Skip to content

Commit 9e5237f

Browse files
authored
Fix debug with IntelliSense engine disabled when there's no existing launch.json. (#9771)
1 parent 7d7ff29 commit 9e5237f

File tree

1 file changed

+89
-88
lines changed

1 file changed

+89
-88
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 89 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -383,106 +383,107 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
383383
(!configuredBuildTasks.some(taskJson => (taskJson.definition.label === taskDetected.definition.label))));
384384
buildTasks = buildTasks.concat(configuredBuildTasks, dedupDetectedBuildTasks);
385385

386-
if (buildTasks.length === 0) {
387-
return [];
388-
}
389-
390386
// Filter out build tasks that don't match the currently selected debug configuration type.
391-
buildTasks = buildTasks.filter((task: CppBuildTask) => {
392-
const command: string = task.definition.command as string;
393-
if (!command) {
394-
return false;
395-
}
396-
if (defaultTemplateConfig.name.startsWith("(Windows) ")) {
397-
if (command.startsWith("cl.exe")) {
398-
return true;
387+
if (buildTasks.length !== 0) {
388+
buildTasks = buildTasks.filter((task: CppBuildTask) => {
389+
const command: string = task.definition.command as string;
390+
if (!command) {
391+
return false;
399392
}
400-
} else {
401-
if (!command.startsWith("cl.exe")) {
402-
return true;
393+
if (defaultTemplateConfig.name.startsWith("(Windows) ")) {
394+
if (command.startsWith("cl.exe")) {
395+
return true;
396+
}
397+
} else {
398+
if (!command.startsWith("cl.exe")) {
399+
return true;
400+
}
403401
}
404-
}
405-
return false;
406-
});
402+
return false;
403+
});
404+
}
407405

408406
// Generate new configurations for each build task.
409407
// Generating a task is async, therefore we must *await* *all* map(task => config) Promises to resolve.
410-
let configs: CppDebugConfiguration[] = await Promise.all(buildTasks.map<Promise<CppDebugConfiguration>>(async task => {
411-
const definition: CppBuildTaskDefinition = task.definition as CppBuildTaskDefinition;
412-
const compilerPath: string = definition.command;
413-
const compilerName: string = path.basename(compilerPath);
414-
const newConfig: CppDebugConfiguration = { ...defaultTemplateConfig }; // Copy enumerables and properties
415-
newConfig.existing = false;
416-
417-
newConfig.name = configPrefix + compilerName + " " + this.buildAndDebugActiveFileStr();
418-
newConfig.preLaunchTask = task.name;
419-
if (newConfig.type === DebuggerType.cppdbg) {
420-
newConfig.externalConsole = false;
421-
} else {
422-
newConfig.console = "externalTerminal";
423-
}
424-
const isWindows: boolean = platformInfo.platform === 'win32';
425-
// Extract the .exe path from the defined task.
426-
const definedExePath: string | undefined = util.findExePathInArgs(task.definition.args);
427-
newConfig.program = definedExePath ? definedExePath : util.defaultExePath();
428-
// Add the "detail" property to show the compiler path in QuickPickItem.
429-
// This property will be removed before writing the DebugConfiguration in launch.json.
430-
newConfig.detail = localize("pre.Launch.Task", "preLaunchTask: {0}", task.name);
431-
newConfig.taskDetail = task.detail;
432-
newConfig.taskStatus = task.existing ?
433-
((task.name === DebugConfigurationProvider.recentBuildTaskLabelStr) ? TaskStatus.recentlyUsed : TaskStatus.configured) :
434-
TaskStatus.detected;
435-
if (task.isDefault) {
436-
newConfig.isDefault = true;
437-
}
438-
const isCl: boolean = compilerName === "cl.exe";
439-
newConfig.cwd = isWindows && !isCl && !process.env.PATH?.includes(path.dirname(compilerPath)) ? path.dirname(compilerPath) : "${fileDirname}";
440-
441-
return new Promise<CppDebugConfiguration>(resolve => {
442-
if (platformInfo.platform === "darwin") {
443-
return resolve(newConfig);
408+
let configs: CppDebugConfiguration[] = [];
409+
if (buildTasks.length !== 0) {
410+
configs = await Promise.all(buildTasks.map<Promise<CppDebugConfiguration>>(async task => {
411+
const definition: CppBuildTaskDefinition = task.definition as CppBuildTaskDefinition;
412+
const compilerPath: string = definition.command;
413+
const compilerName: string = path.basename(compilerPath);
414+
const newConfig: CppDebugConfiguration = { ...defaultTemplateConfig }; // Copy enumerables and properties
415+
newConfig.existing = false;
416+
417+
newConfig.name = configPrefix + compilerName + " " + this.buildAndDebugActiveFileStr();
418+
newConfig.preLaunchTask = task.name;
419+
if (newConfig.type === DebuggerType.cppdbg) {
420+
newConfig.externalConsole = false;
444421
} else {
445-
let debuggerName: string;
446-
if (compilerName.startsWith("clang")) {
447-
newConfig.MIMode = "lldb";
448-
debuggerName = "lldb-mi";
449-
// Search for clang-8, clang-10, etc.
450-
if ((compilerName !== "clang-cl.exe") && (compilerName !== "clang-cpp.exe")) {
451-
const suffixIndex: number = compilerName.indexOf("-");
452-
if (suffixIndex !== -1) {
453-
const suffix: string = compilerName.substring(suffixIndex);
454-
debuggerName += suffix;
455-
}
456-
}
457-
newConfig.type = DebuggerType.cppdbg;
458-
} else if (compilerName === "cl.exe") {
459-
newConfig.miDebuggerPath = undefined;
460-
newConfig.type = DebuggerType.cppvsdbg;
461-
return resolve(newConfig);
462-
} else {
463-
debuggerName = "gdb";
464-
}
465-
if (isWindows) {
466-
debuggerName = debuggerName.endsWith(".exe") ? debuggerName : (debuggerName + ".exe");
467-
}
468-
const compilerDirname: string = path.dirname(compilerPath);
469-
const debuggerPath: string = path.join(compilerDirname, debuggerName);
470-
if (isWindows) {
471-
newConfig.miDebuggerPath = debuggerPath;
422+
newConfig.console = "externalTerminal";
423+
}
424+
const isWindows: boolean = platformInfo.platform === 'win32';
425+
// Extract the .exe path from the defined task.
426+
const definedExePath: string | undefined = util.findExePathInArgs(task.definition.args);
427+
newConfig.program = definedExePath ? definedExePath : util.defaultExePath();
428+
// Add the "detail" property to show the compiler path in QuickPickItem.
429+
// This property will be removed before writing the DebugConfiguration in launch.json.
430+
newConfig.detail = localize("pre.Launch.Task", "preLaunchTask: {0}", task.name);
431+
newConfig.taskDetail = task.detail;
432+
newConfig.taskStatus = task.existing ?
433+
((task.name === DebugConfigurationProvider.recentBuildTaskLabelStr) ? TaskStatus.recentlyUsed : TaskStatus.configured) :
434+
TaskStatus.detected;
435+
if (task.isDefault) {
436+
newConfig.isDefault = true;
437+
}
438+
const isCl: boolean = compilerName === "cl.exe";
439+
newConfig.cwd = isWindows && !isCl && !process.env.PATH?.includes(path.dirname(compilerPath)) ? path.dirname(compilerPath) : "${fileDirname}";
440+
441+
return new Promise<CppDebugConfiguration>(resolve => {
442+
if (platformInfo.platform === "darwin") {
472443
return resolve(newConfig);
473444
} else {
474-
fs.stat(debuggerPath, (err, stats: fs.Stats) => {
475-
if (!err && stats && stats.isFile()) {
476-
newConfig.miDebuggerPath = debuggerPath;
477-
} else {
478-
newConfig.miDebuggerPath = path.join("/usr", "bin", debuggerName);
445+
let debuggerName: string;
446+
if (compilerName.startsWith("clang")) {
447+
newConfig.MIMode = "lldb";
448+
debuggerName = "lldb-mi";
449+
// Search for clang-8, clang-10, etc.
450+
if ((compilerName !== "clang-cl.exe") && (compilerName !== "clang-cpp.exe")) {
451+
const suffixIndex: number = compilerName.indexOf("-");
452+
if (suffixIndex !== -1) {
453+
const suffix: string = compilerName.substring(suffixIndex);
454+
debuggerName += suffix;
455+
}
479456
}
457+
newConfig.type = DebuggerType.cppdbg;
458+
} else if (compilerName === "cl.exe") {
459+
newConfig.miDebuggerPath = undefined;
460+
newConfig.type = DebuggerType.cppvsdbg;
480461
return resolve(newConfig);
481-
});
462+
} else {
463+
debuggerName = "gdb";
464+
}
465+
if (isWindows) {
466+
debuggerName = debuggerName.endsWith(".exe") ? debuggerName : (debuggerName + ".exe");
467+
}
468+
const compilerDirname: string = path.dirname(compilerPath);
469+
const debuggerPath: string = path.join(compilerDirname, debuggerName);
470+
if (isWindows) {
471+
newConfig.miDebuggerPath = debuggerPath;
472+
return resolve(newConfig);
473+
} else {
474+
fs.stat(debuggerPath, (err, stats: fs.Stats) => {
475+
if (!err && stats && stats.isFile()) {
476+
newConfig.miDebuggerPath = debuggerPath;
477+
} else {
478+
newConfig.miDebuggerPath = path.join("/usr", "bin", debuggerName);
479+
}
480+
return resolve(newConfig);
481+
});
482+
}
482483
}
483-
}
484-
});
485-
}));
484+
});
485+
}));
486+
}
486487
configs.push(defaultTemplateConfig);
487488
const existingConfigs: CppDebugConfiguration[] | undefined = this.getLaunchConfigs(folder, type)?.map(config => {
488489
if (!config.detail && config.preLaunchTask) {

0 commit comments

Comments
 (0)