From fb9a1dd87ed3c44bb261958fbe2111f19e9185c9 Mon Sep 17 00:00:00 2001 From: Rungsikorn Rungsikavarnich Date: Thu, 30 Mar 2023 15:22:20 +0900 Subject: [PATCH] Missing runnable env on debug target Fix bug in Rust Analyzer where runnable debugging did not pass environment variable from configuration to child process of Cargo on binary build stage --- editors/code/src/debug.ts | 9 ++++++--- editors/code/src/toolchain.ts | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 268b70b4fbbc..cffee1de6af7 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -118,8 +118,8 @@ async function getDebugConfiguration( return path.normalize(p).replace(wsFolder, "${workspaceFolder" + workspaceQualifier + "}"); } - const executable = await getDebugExecutable(runnable); const env = prepareEnv(runnable, ctx.config.runnableEnv); + const executable = await getDebugExecutable(runnable, env); let sourceFileMap = debugOptions.sourceFileMap; if (sourceFileMap === "auto") { // let's try to use the default toolchain @@ -156,8 +156,11 @@ async function getDebugConfiguration( return debugConfig; } -async function getDebugExecutable(runnable: ra.Runnable): Promise { - const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput); +async function getDebugExecutable( + runnable: ra.Runnable, + env: Record +): Promise { + const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput, env); const executable = await cargo.executableFromArgs(runnable.args.cargoArgs); // if we are here, there were no compilation errors. diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index eb70b88871e3..917a1d6b0997 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts @@ -18,7 +18,11 @@ export interface ArtifactSpec { } export class Cargo { - constructor(readonly rootFolder: string, readonly output: vscode.OutputChannel) {} + constructor( + readonly rootFolder: string, + readonly output: vscode.OutputChannel, + readonly env: Record + ) {} // Made public for testing purposes static artifactSpec(args: readonly string[]): ArtifactSpec { @@ -102,6 +106,7 @@ export class Cargo { const cargo = cp.spawn(path, cargoArgs, { stdio: ["ignore", "pipe", "pipe"], cwd: this.rootFolder, + env: this.env, }); cargo.on("error", (err) => reject(new Error(`could not launch cargo: ${err}`)));