Skip to content

Commit e109aa9

Browse files
committed
Resolve relative program paths using cargoCwd
1 parent 73b892d commit e109aa9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

extension/cargo.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ export class Cargo {
135135
// and sends LaunchEnvironment info including the debuggee path, arguments, etc.
136136
let launchEnv = result as LaunchEnvironment;
137137
// Use args passed in by Cargo, appending any user-provided args
138-
debugConfig.program = launchEnv.cmd[0];
138+
debugConfig.program = path.resolve(this.getCargoCwd(cargoConfig.cwd), launchEnv.cmd[0]);
139139
debugConfig.args = launchEnv.cmd.slice(1).concat(debugConfig.args ?? []);
140140
debugConfig.cwd = launchEnv.cwd;
141141
// Use Cargo environment, with overrides from launchConfig
142142
debugConfig.env = Object.assign({}, debugConfig.env, launchEnv.env);
143143
debugConfig = expandCargo(debugConfig, { program: launchEnv.cmd[0] });
144144
} else {
145145
// Case 2: `cargo build ...` is used; the `result` is the path of the debuggee executable.
146+
result = path.resolve(this.getCargoCwd(cargoConfig.cwd), result);
146147
debugConfig = expandCargo(debugConfig, { program: result }); // Expand ${cargo:program}.
147148
if (debugConfig.program == undefined) {
148149
debugConfig.program = result;
@@ -279,7 +280,7 @@ export class Cargo {
279280
): cp.ChildProcess & { exit: Promise<number> } {
280281
let config = getExtensionConfig(this.workspaceFolder);
281282
let cargoCmd = config.get<string>('cargo', 'cargo');
282-
let cargoCwd = cwd ?? (this.workspaceFolder?.uri?.fsPath);
283+
let cargoCwd = this.getCargoCwd(cwd);
283284
let cargoEnv = Object.assign({}, process.env, extraEnv)
284285

285286
output.appendLine(`Running: ${cargoCmd} ${args.join(' ')}`);
@@ -308,6 +309,10 @@ export class Cargo {
308309
});
309310
return cargo;
310311
}
312+
313+
getCargoCwd(cwd: string | undefined) : string {
314+
return cwd ?? (this.workspaceFolder?.uri?.fsPath!);
315+
}
311316
}
312317

313318
async function runTask<T, R>(

0 commit comments

Comments
 (0)