Skip to content

fix: Fix debug configuration querying not inheriting environment #18586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions editors/code/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,38 @@ export class Config {
return this.get<boolean | undefined>("testExplorer");
}

get runnablesExtraEnv() {
runnablesExtraEnv(label: string): Record<string, string> | undefined {
const item = this.get<any>("runnables.extraEnv") ?? this.get<any>("runnableEnv");
if (!item) return item;
if (!item) return undefined;
const fixRecord = (r: Record<string, any>) => {
for (const key in r) {
if (typeof r[key] !== "string") {
r[key] = String(r[key]);
}
}
};

const platform = process.platform;
const checkPlatform = (it: RunnableEnvCfgItem) => {
if (it.platform) {
const platforms = Array.isArray(it.platform) ? it.platform : [it.platform];
return platforms.indexOf(platform) >= 0;
}
return true;
};

if (item instanceof Array) {
item.forEach((x) => fixRecord(x.env));
} else {
fixRecord(item);
const env = {};
for (const it of item) {
const masked = !it.mask || new RegExp(it.mask).test(label);
if (masked && checkPlatform(it)) {
Object.assign(env, it.env);
}
}
fixRecord(env);
return env;
}
fixRecord(item);
return item;
}

Expand Down
12 changes: 10 additions & 2 deletions editors/code/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,16 @@ async function getDebugConfiguration(
return path.normalize(p).replace(wsFolder, `\${workspaceFolder${workspaceQualifier}}`);
}

const env = prepareEnv(inheritEnv, runnable.label, runnableArgs, config.runnablesExtraEnv);
const executable = await getDebugExecutable(runnableArgs, env);
const executable = await getDebugExecutable(
runnableArgs,
prepareEnv(true, {}, config.runnablesExtraEnv(runnable.label)),
);

const env = prepareEnv(
inheritEnv,
runnableArgs.environment,
config.runnablesExtraEnv(runnable.label),
);
let sourceFileMap = debugOptions.sourceFileMap;

if (sourceFileMap === "auto") {
Expand Down
35 changes: 10 additions & 25 deletions editors/code/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as tasks from "./tasks";

import type { CtxInit } from "./ctx";
import { makeDebugConfig } from "./debug";
import type { Config, RunnableEnvCfg, RunnableEnvCfgItem } from "./config";
import type { Config } from "./config";
import type { LanguageClient } from "vscode-languageclient/node";
import { unwrapUndefinable, type RustEditor } from "./util";

Expand Down Expand Up @@ -81,32 +81,13 @@ export function prepareBaseEnv(

export function prepareEnv(
inheritEnv: boolean,
label: string,
runnableArgs: ra.CargoRunnableArgs,
runnableEnvCfg?: RunnableEnvCfg,
runnableEnv?: Record<string, string>,
runnableEnvCfg?: Record<string, string>,
): Record<string, string> {
const env = prepareBaseEnv(inheritEnv, runnableArgs.environment);
const platform = process.platform;

const checkPlatform = (it: RunnableEnvCfgItem) => {
if (it.platform) {
const platforms = Array.isArray(it.platform) ? it.platform : [it.platform];
return platforms.indexOf(platform) >= 0;
}
return true;
};
const env = prepareBaseEnv(inheritEnv, runnableEnv);

if (runnableEnvCfg) {
if (Array.isArray(runnableEnvCfg)) {
for (const it of runnableEnvCfg) {
const masked = !it.mask || new RegExp(it.mask).test(label);
if (masked && checkPlatform(it)) {
Object.assign(env, it.env);
}
}
} else {
Object.assign(env, runnableEnvCfg);
}
Object.assign(env, runnableEnvCfg);
}

return env;
Expand Down Expand Up @@ -140,7 +121,11 @@ export async function createTaskFromRunnable(
};
options = {
cwd: runnableArgs.workspaceRoot || ".",
env: prepareEnv(true, runnable.label, runnableArgs, config.runnablesExtraEnv),
env: prepareEnv(
true,
runnableArgs.environment,
config.runnablesExtraEnv(runnable.label),
),
};
} else {
const runnableArgs = runnable.args;
Expand Down
122 changes: 0 additions & 122 deletions editors/code/tests/unit/runnable_env.test.ts

This file was deleted.