Skip to content

Commit 7a767d0

Browse files
committed
Unherit server extra env for runnables extra env
1 parent 71ea00f commit 7a767d0

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

src/tools/rust-analyzer/editors/code/src/config.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,12 @@ export class Config {
261261
}
262262

263263
runnablesExtraEnv(label: string): Env {
264-
let extraEnv = this.get<RunnableEnvCfgItem[] | { [key: string]: { toString(): string } | null } | null>("runnables.extraEnv") ?? {};
265-
if (!extraEnv) return {};
264+
const serverEnv = this.serverExtraEnv;
265+
let extraEnv =
266+
this.get<
267+
RunnableEnvCfgItem[] | { [key: string]: { toString(): string } | null } | null
268+
>("runnables.extraEnv") ?? {};
269+
if (!extraEnv) return serverEnv;
266270

267271
const platform = process.platform;
268272
const checkPlatform = (it: RunnableEnvCfgItem) => {
@@ -283,14 +287,15 @@ export class Config {
283287
}
284288
extraEnv = env;
285289
}
286-
return substituteVariablesInEnv(
290+
const runnableExtraEnv = substituteVariablesInEnv(
287291
Object.fromEntries(
288292
Object.entries(extraEnv).map(([k, v]) => [
289293
k,
290294
typeof v === "string" ? v : v?.toString(),
291295
]),
292296
),
293297
);
298+
return { ...runnableExtraEnv, ...serverEnv };
294299
}
295300

296301
get restartServerOnConfigChange() {
@@ -485,11 +490,11 @@ function computeVscodeVar(varName: string): string | null {
485490
folder === undefined
486491
? "" // no workspace opened
487492
: // could use currently opened document to detect the correct
488-
// workspace. However, that would be determined by the document
489-
// user has opened on Editor startup. Could lead to
490-
// unpredictable workspace selection in practice.
491-
// It's better to pick the first one
492-
normalizeDriveLetter(folder.uri.fsPath);
493+
// workspace. However, that would be determined by the document
494+
// user has opened on Editor startup. Could lead to
495+
// unpredictable workspace selection in practice.
496+
// It's better to pick the first one
497+
normalizeDriveLetter(folder.uri.fsPath);
493498
return fsPath;
494499
};
495500
// https://code.visualstudio.com/docs/editor/variables-reference

src/tools/rust-analyzer/editors/code/src/debug.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import type * as ra from "./lsp_ext";
66
import { Cargo } from "./toolchain";
77
import type { Ctx } from "./ctx";
88
import { createTaskFromRunnable, prepareEnv } from "./run";
9-
import { execute, isCargoRunnableArgs, unwrapUndefinable, log, normalizeDriveLetter, Env } from "./util";
9+
import {
10+
execute,
11+
isCargoRunnableArgs,
12+
unwrapUndefinable,
13+
log,
14+
normalizeDriveLetter,
15+
Env,
16+
} from "./util";
1017
import type { Config } from "./config";
1118

1219
// Here we want to keep track on everything that's currently running
@@ -108,9 +115,9 @@ async function getDebugConfiguration(
108115

109116
await vscode.window.showErrorMessage(
110117
`Install [CodeLLDB](command:${commandCodeLLDB} "Open CodeLLDB")` +
111-
`, [lldb-dap](command:${commandLLDBDap} "Open lldb-dap")` +
112-
`, [C/C++](command:${commandCCpp} "Open C/C++") ` +
113-
`or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
118+
`, [lldb-dap](command:${commandLLDBDap} "Open lldb-dap")` +
119+
`, [C/C++](command:${commandCCpp} "Open C/C++") ` +
120+
`or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
114121
);
115122
return;
116123
}
@@ -124,7 +131,7 @@ async function getDebugConfiguration(
124131
!isMultiFolderWorkspace || !runnableArgs.workspaceRoot
125132
? firstWorkspace
126133
: workspaceFolders.find((w) => runnableArgs.workspaceRoot?.includes(w.uri.fsPath)) ||
127-
firstWorkspace;
134+
firstWorkspace;
128135

129136
const workspace = unwrapUndefinable(maybeWorkspace);
130137
const wsFolder = normalizeDriveLetter(path.normalize(workspace.uri.fsPath));
@@ -206,10 +213,7 @@ type SourceFileMap = {
206213
destination: string;
207214
};
208215

209-
async function discoverSourceFileMap(
210-
env: Env,
211-
cwd: string,
212-
): Promise<SourceFileMap | undefined> {
216+
async function discoverSourceFileMap(env: Env, cwd: string): Promise<SourceFileMap | undefined> {
213217
const sysroot = env["RUSTC_TOOLCHAIN"];
214218
if (sysroot) {
215219
// let's try to use the default toolchain
@@ -304,10 +308,7 @@ const knownEngines: {
304308
},
305309
};
306310

307-
async function getDebugExecutable(
308-
runnableArgs: ra.CargoRunnableArgs,
309-
env: Env,
310-
): Promise<string> {
311+
async function getDebugExecutable(runnableArgs: ra.CargoRunnableArgs, env: Env): Promise<string> {
311312
const cargo = new Cargo(runnableArgs.workspaceRoot || ".", env);
312313
const executable = await cargo.executableFromArgs(runnableArgs);
313314

src/tools/rust-analyzer/editors/code/src/run.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ export class RunnableQuickPick implements vscode.QuickPickItem {
122122
}
123123
}
124124

125-
export function prepareBaseEnv(
126-
inheritEnv: boolean,
127-
base?: Env,
128-
): Env {
125+
export function prepareBaseEnv(inheritEnv: boolean, base?: Env): Env {
129126
const env: Env = { RUST_BACKTRACE: "short" };
130127
if (inheritEnv) {
131128
Object.assign(env, process.env);
@@ -136,11 +133,7 @@ export function prepareBaseEnv(
136133
return env;
137134
}
138135

139-
export function prepareEnv(
140-
inheritEnv: boolean,
141-
runnableEnv?: Env,
142-
runnableEnvCfg?: Env,
143-
): Env {
136+
export function prepareEnv(inheritEnv: boolean, runnableEnv?: Env, runnableEnvCfg?: Env): Env {
144137
const env = prepareBaseEnv(inheritEnv, runnableEnv);
145138

146139
if (runnableEnvCfg) {

src/tools/rust-analyzer/editors/code/src/tasks.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ export async function targetToExecution(
134134
}
135135
return new vscode.ProcessExecution(command, args, {
136136
cwd: options?.cwd,
137-
env:
138-
Object.fromEntries(
139-
Object.entries(options?.env ?? {}).map(([key, value]) => [key, value ?? ""])
140-
)
141-
,
137+
env: Object.fromEntries(
138+
Object.entries(options?.env ?? {}).map(([key, value]) => [key, value ?? ""]),
139+
),
142140
});
143141
}
144142

src/tools/rust-analyzer/editors/code/src/toolchain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Cargo {
3838
constructor(
3939
readonly rootFolder: string,
4040
readonly env: Env,
41-
) { }
41+
) {}
4242

4343
// Made public for testing purposes
4444
static artifactSpec(cargoArgs: string[], executableArgs?: string[]): ArtifactSpec {

0 commit comments

Comments
 (0)