Skip to content

Commit

Permalink
Debugger "environment" only in ms-vscode.cpptools
Browse files Browse the repository at this point in the history
Only set the debugger "environment" key if debugType is 'cppdbg'
(running under ms-vscode.cpptools), otherwise "env" key
  • Loading branch information
cskeogh committed Jun 19, 2024
1 parent 664a05b commit eba1b9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { ExecResult, exec, extensionConfiguration } from "./utils";
import { Tests } from "./types";
import { Tests, DebugEnvironmentConfiguration } from "./types";
import { getMesonTests, getMesonTargets } from "./introspection";
import { workspaceState } from "./extension";

Expand Down Expand Up @@ -128,24 +128,39 @@ export async function testDebugHandler(
let args = [...test.cmd];
args.shift();

const debugEnv = [];
/* convert from dict of key = value to array of {name: key, value: value} */
if (test.env instanceof Object) {
for (const [key, val] of Object.entries(test.env)) {
debugEnv.push({ name: key, value: val });
let debugEnvironmentConfiguration: DebugEnvironmentConfiguration;
/* cppdbg uses 'environment' key, all others use 'env' key */
if (debugType == "cppdbg") {
const debugEnv = [];
if (test.env instanceof Object) {
/* convert from dict of key = value to array of {name: key, value: value} */
for (const [key, val] of Object.entries(test.env)) {
debugEnv.push({ name: key, value: val });
}
}
debugEnvironmentConfiguration = {
environment: debugEnv,
};
} else {
debugEnvironmentConfiguration = {
env: test.env,
};
}

let debugConfiguration = {
name: `meson-debug-${test.name}`,
type: debugType,
request: "launch",
cwd: test.workdir || sourceDir,
environment: debugEnv,
program: test.cmd[0],
args: args,
};
await vscode.debug.startDebugging(undefined, { ...debugConfiguration, ...configDebugOptions });
const configuration = {
...debugConfiguration,
...debugEnvironmentConfiguration,
...configDebugOptions,
};
await vscode.debug.startDebugging(undefined, configuration);
}

run.end();
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ export interface Test {
depends: string[];
}

interface StdDebugEnvironmentConfiguration {
env: { [key: string]: string };
}
interface CppDebugEnvironmentConfiguration {
environment: { name: string; value: string }[];
}
export type DebugEnvironmentConfiguration = StdDebugEnvironmentConfiguration | CppDebugEnvironmentConfiguration;

export type Targets = Target[];
export type BuildOptions = BuildOption<any>[];
export type Dependencies = Dependency[];
Expand Down

0 comments on commit eba1b9c

Please sign in to comment.