Skip to content

Commit aa4c5df

Browse files
committed
Fix cwd. (#6619)
Fixes #6618
1 parent a3de2f9 commit aa4c5df

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,13 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
178178
newConfig.preLaunchTask = task.name;
179179
newConfig.externalConsole = false;
180180
const exeName: string = path.join("${fileDirname}", "${fileBasenameNoExtension}");
181-
newConfig.program = platform === "win32" ? exeName + ".exe" : exeName;
181+
const isWindows: boolean = platform === 'win32';
182+
newConfig.program = isWindows ? exeName + ".exe" : exeName;
182183
// Add the "detail" property to show the compiler path in QuickPickItem.
183184
// This property will be removed before writing the DebugConfiguration in launch.json.
184185
newConfig.detail = task.detail ? task.detail : definition.command;
186+
const isCl: boolean = compilerName === "cl.exe";
187+
newConfig.cwd = isWindows && !isCl && !process.env.PATH?.includes(compilerPath) ? path.dirname(compilerPath) : "${workspaceFolder}";
185188

186189
return new Promise<vscode.DebugConfiguration>(resolve => {
187190
if (platform === "darwin") {
@@ -201,7 +204,7 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
201204
debuggerName = "gdb";
202205
}
203206

204-
if (platform === "win32") {
207+
if (isWindows) {
205208
debuggerName += ".exe";
206209
}
207210

Extension/src/LanguageServer/cppBuildTaskProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class CppBuildTaskProvider implements TaskProvider {
167167
if (compilerArgs && compilerArgs.length > 0) {
168168
args = args.concat(compilerArgs);
169169
}
170-
const cwd: string = isCl ? "${workspaceFolder}" : path.dirname(compilerPath);
170+
const cwd: string = isWindows && !isCl && !process.env.PATH?.includes(compilerPath) ? path.dirname(compilerPath) : "${workspaceFolder}";
171171
const options: cp.ExecOptions | undefined = { cwd: cwd };
172172
definition = {
173173
type: CppBuildTaskProvider.CppBuildScriptType,

0 commit comments

Comments
 (0)