mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Respect $CARGO_HOME when looking up toolchains.
This commit is contained in:
parent
289208bc9f
commit
e4b184a776
2 changed files with 35 additions and 16 deletions
|
@ -156,19 +156,10 @@ export const getPathForExecutable = memoizeAsync(
|
|||
|
||||
if (await lookupInPath(executableName)) return executableName;
|
||||
|
||||
try {
|
||||
// hmm, `os.homedir()` seems to be infallible
|
||||
// it is not mentioned in docs and cannot be inferred by the type signature...
|
||||
const standardPath = vscode.Uri.joinPath(
|
||||
vscode.Uri.file(os.homedir()),
|
||||
".cargo",
|
||||
"bin",
|
||||
executableName
|
||||
);
|
||||
|
||||
const cargoHome = getCargoHome();
|
||||
if (cargoHome) {
|
||||
const standardPath = vscode.Uri.joinPath(cargoHome, "bin", executableName);
|
||||
if (await isFileAtUri(standardPath)) return standardPath.fsPath;
|
||||
} catch (err) {
|
||||
log.error("Failed to read the fs info", err);
|
||||
}
|
||||
return executableName;
|
||||
}
|
||||
|
@ -190,6 +181,21 @@ async function lookupInPath(exec: string): Promise<boolean> {
|
|||
return false;
|
||||
}
|
||||
|
||||
function getCargoHome(): vscode.Uri | null {
|
||||
const envVar = process.env["CARGO_HOME"];
|
||||
if (envVar) return vscode.Uri.file(envVar);
|
||||
|
||||
try {
|
||||
// hmm, `os.homedir()` seems to be infallible
|
||||
// it is not mentioned in docs and cannot be inferred by the type signature...
|
||||
return vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo");
|
||||
} catch (err) {
|
||||
log.error("Failed to read the fs info", err);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function isFileAtPath(path: string): Promise<boolean> {
|
||||
return isFileAtUri(vscode.Uri.file(path));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue