Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/toolchain.ts')
| -rw-r--r-- | editors/code/src/toolchain.ts | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index e1ca495428..eb70b88871 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts @@ -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)); } |