about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <me@lukaswirth.dev>2025-07-27 14:09:21 +0200
committerLukas Wirth <me@lukaswirth.dev>2025-07-27 14:09:21 +0200
commit7a767d01cf7ed75c6924a96cc90d9191b447e76b (patch)
treef45b790278b3eecbc543c5de72bc1eae21d94116 /src/tools/rust-analyzer
parent71ea00f7a3911990e9e5328446312bc0d792cf5f (diff)
downloadrust-7a767d01cf7ed75c6924a96cc90d9191b447e76b.tar.gz
rust-7a767d01cf7ed75c6924a96cc90d9191b447e76b.zip
Unherit server extra env for runnables extra env
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/editors/code/src/config.ts21
-rw-r--r--src/tools/rust-analyzer/editors/code/src/debug.ts27
-rw-r--r--src/tools/rust-analyzer/editors/code/src/run.ts11
-rw-r--r--src/tools/rust-analyzer/editors/code/src/tasks.ts8
-rw-r--r--src/tools/rust-analyzer/editors/code/src/toolchain.ts2
5 files changed, 33 insertions, 36 deletions
diff --git a/src/tools/rust-analyzer/editors/code/src/config.ts b/src/tools/rust-analyzer/editors/code/src/config.ts
index cadab37f517..3b1b0768d3c 100644
--- a/src/tools/rust-analyzer/editors/code/src/config.ts
+++ b/src/tools/rust-analyzer/editors/code/src/config.ts
@@ -261,8 +261,12 @@ export class Config {
     }
 
     runnablesExtraEnv(label: string): Env {
-        let extraEnv = this.get<RunnableEnvCfgItem[] | { [key: string]: { toString(): string } | null } | null>("runnables.extraEnv") ?? {};
-        if (!extraEnv) return {};
+        const serverEnv = this.serverExtraEnv;
+        let extraEnv =
+            this.get<
+                RunnableEnvCfgItem[] | { [key: string]: { toString(): string } | null } | null
+            >("runnables.extraEnv") ?? {};
+        if (!extraEnv) return serverEnv;
 
         const platform = process.platform;
         const checkPlatform = (it: RunnableEnvCfgItem) => {
@@ -283,7 +287,7 @@ export class Config {
             }
             extraEnv = env;
         }
-        return substituteVariablesInEnv(
+        const runnableExtraEnv = substituteVariablesInEnv(
             Object.fromEntries(
                 Object.entries(extraEnv).map(([k, v]) => [
                     k,
@@ -291,6 +295,7 @@ export class Config {
                 ]),
             ),
         );
+        return { ...runnableExtraEnv, ...serverEnv };
     }
 
     get restartServerOnConfigChange() {
@@ -485,11 +490,11 @@ function computeVscodeVar(varName: string): string | null {
             folder === undefined
                 ? "" // no workspace opened
                 : // could use currently opened document to detect the correct
-                // workspace. However, that would be determined by the document
-                // user has opened on Editor startup. Could lead to
-                // unpredictable workspace selection in practice.
-                // It's better to pick the first one
-                normalizeDriveLetter(folder.uri.fsPath);
+                  // workspace. However, that would be determined by the document
+                  // user has opened on Editor startup. Could lead to
+                  // unpredictable workspace selection in practice.
+                  // It's better to pick the first one
+                  normalizeDriveLetter(folder.uri.fsPath);
         return fsPath;
     };
     // https://code.visualstudio.com/docs/editor/variables-reference
diff --git a/src/tools/rust-analyzer/editors/code/src/debug.ts b/src/tools/rust-analyzer/editors/code/src/debug.ts
index 9559fe16f51..24f8d908730 100644
--- a/src/tools/rust-analyzer/editors/code/src/debug.ts
+++ b/src/tools/rust-analyzer/editors/code/src/debug.ts
@@ -6,7 +6,14 @@ import type * as ra from "./lsp_ext";
 import { Cargo } from "./toolchain";
 import type { Ctx } from "./ctx";
 import { createTaskFromRunnable, prepareEnv } from "./run";
-import { execute, isCargoRunnableArgs, unwrapUndefinable, log, normalizeDriveLetter, Env } from "./util";
+import {
+    execute,
+    isCargoRunnableArgs,
+    unwrapUndefinable,
+    log,
+    normalizeDriveLetter,
+    Env,
+} from "./util";
 import type { Config } from "./config";
 
 // Here we want to keep track on everything that's currently running
@@ -108,9 +115,9 @@ async function getDebugConfiguration(
 
         await vscode.window.showErrorMessage(
             `Install [CodeLLDB](command:${commandCodeLLDB} "Open CodeLLDB")` +
-            `, [lldb-dap](command:${commandLLDBDap} "Open lldb-dap")` +
-            `, [C/C++](command:${commandCCpp} "Open C/C++") ` +
-            `or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
+                `, [lldb-dap](command:${commandLLDBDap} "Open lldb-dap")` +
+                `, [C/C++](command:${commandCCpp} "Open C/C++") ` +
+                `or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
         );
         return;
     }
@@ -124,7 +131,7 @@ async function getDebugConfiguration(
         !isMultiFolderWorkspace || !runnableArgs.workspaceRoot
             ? firstWorkspace
             : workspaceFolders.find((w) => runnableArgs.workspaceRoot?.includes(w.uri.fsPath)) ||
-            firstWorkspace;
+              firstWorkspace;
 
     const workspace = unwrapUndefinable(maybeWorkspace);
     const wsFolder = normalizeDriveLetter(path.normalize(workspace.uri.fsPath));
@@ -206,10 +213,7 @@ type SourceFileMap = {
     destination: string;
 };
 
-async function discoverSourceFileMap(
-    env: Env,
-    cwd: string,
-): Promise<SourceFileMap | undefined> {
+async function discoverSourceFileMap(env: Env, cwd: string): Promise<SourceFileMap | undefined> {
     const sysroot = env["RUSTC_TOOLCHAIN"];
     if (sysroot) {
         // let's try to use the default toolchain
@@ -304,10 +308,7 @@ const knownEngines: {
     },
 };
 
-async function getDebugExecutable(
-    runnableArgs: ra.CargoRunnableArgs,
-    env: Env,
-): Promise<string> {
+async function getDebugExecutable(runnableArgs: ra.CargoRunnableArgs, env: Env): Promise<string> {
     const cargo = new Cargo(runnableArgs.workspaceRoot || ".", env);
     const executable = await cargo.executableFromArgs(runnableArgs);
 
diff --git a/src/tools/rust-analyzer/editors/code/src/run.ts b/src/tools/rust-analyzer/editors/code/src/run.ts
index bed874705d8..87c1d529f7e 100644
--- a/src/tools/rust-analyzer/editors/code/src/run.ts
+++ b/src/tools/rust-analyzer/editors/code/src/run.ts
@@ -122,10 +122,7 @@ export class RunnableQuickPick implements vscode.QuickPickItem {
     }
 }
 
-export function prepareBaseEnv(
-    inheritEnv: boolean,
-    base?: Env,
-): Env {
+export function prepareBaseEnv(inheritEnv: boolean, base?: Env): Env {
     const env: Env = { RUST_BACKTRACE: "short" };
     if (inheritEnv) {
         Object.assign(env, process.env);
@@ -136,11 +133,7 @@ export function prepareBaseEnv(
     return env;
 }
 
-export function prepareEnv(
-    inheritEnv: boolean,
-    runnableEnv?: Env,
-    runnableEnvCfg?: Env,
-): Env {
+export function prepareEnv(inheritEnv: boolean, runnableEnv?: Env, runnableEnvCfg?: Env): Env {
     const env = prepareBaseEnv(inheritEnv, runnableEnv);
 
     if (runnableEnvCfg) {
diff --git a/src/tools/rust-analyzer/editors/code/src/tasks.ts b/src/tools/rust-analyzer/editors/code/src/tasks.ts
index 417c28f0ee8..eb0748a704b 100644
--- a/src/tools/rust-analyzer/editors/code/src/tasks.ts
+++ b/src/tools/rust-analyzer/editors/code/src/tasks.ts
@@ -134,11 +134,9 @@ export async function targetToExecution(
     }
     return new vscode.ProcessExecution(command, args, {
         cwd: options?.cwd,
-        env:
-            Object.fromEntries(
-                Object.entries(options?.env ?? {}).map(([key, value]) => [key, value ?? ""])
-            )
-        ,
+        env: Object.fromEntries(
+            Object.entries(options?.env ?? {}).map(([key, value]) => [key, value ?? ""]),
+        ),
     });
 }
 
diff --git a/src/tools/rust-analyzer/editors/code/src/toolchain.ts b/src/tools/rust-analyzer/editors/code/src/toolchain.ts
index f64dec2ccfb..06f75a8f8d6 100644
--- a/src/tools/rust-analyzer/editors/code/src/toolchain.ts
+++ b/src/tools/rust-analyzer/editors/code/src/toolchain.ts
@@ -38,7 +38,7 @@ export class Cargo {
     constructor(
         readonly rootFolder: string,
         readonly env: Env,
-    ) { }
+    ) {}
 
     // Made public for testing purposes
     static artifactSpec(cargoArgs: string[], executableArgs?: string[]): ArtifactSpec {