about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorTomoki Nakagawa <tomokinat@google.com>2023-02-24 15:26:25 +0900
committerTomoki Nakagawa <tomokinat@google.com>2023-02-26 15:37:04 +0900
commite4b184a776ef20e33ff2922f583349928061a18b (patch)
tree50d42cf24cc6656a667022a19045089d7d3b9d25 /editors/code/src
parent289208bc9fb08704db37c6ce0fb700bbfb3b7099 (diff)
downloadrust-e4b184a776ef20e33ff2922f583349928061a18b.tar.gz
rust-e4b184a776ef20e33ff2922f583349928061a18b.zip
Respect $CARGO_HOME when looking up toolchains.
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/toolchain.ts30
1 files changed, 18 insertions, 12 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index e1ca4954280..eb70b88871e 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));
 }