Skip to content

Commit 2cbe7d6

Browse files
add launch config (#8949)
1 parent ffb1b83 commit 2cbe7d6

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,8 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
257257
let buildTasks: CppBuildTask[] = [];
258258
await this.loadDetectedTasks();
259259
// Remove the tasks that are already configured once in tasks.json.
260-
const dedupDetectedBuildTasks: CppBuildTask[] = DebugConfigurationProvider.detectedBuildTasks.filter(taskDetected => {
261-
let isAlreadyConfigured: boolean = false;
262-
for (const taskJson of configuredBuildTasks) {
263-
if ((taskDetected.definition.label as string) === (taskJson.definition.label as string)) {
264-
isAlreadyConfigured = true;
265-
break;
266-
}
267-
}
268-
return !isAlreadyConfigured;
269-
});
260+
const dedupDetectedBuildTasks: CppBuildTask[] = DebugConfigurationProvider.detectedBuildTasks.filter(taskDetected =>
261+
(!configuredBuildTasks.some(taskJson => (taskJson.definition.label === taskDetected.definition.label))));
270262
buildTasks = buildTasks.concat(configuredBuildTasks, dedupDetectedBuildTasks);
271263

272264
if (buildTasks.length === 0) {
@@ -526,6 +518,15 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
526518
}
527519
}
528520

521+
public async getLaunchConfigs(folder: vscode.WorkspaceFolder | undefined): Promise<vscode.WorkspaceConfiguration[] | undefined> {
522+
let configs: vscode.WorkspaceConfiguration[] | undefined = vscode.workspace.getConfiguration('launch', folder).get('configurations');
523+
if (!configs) {
524+
return undefined;
525+
}
526+
configs = configs.filter(config => (config.name && config.request === "launch" && (config.type === DebuggerType.cppvsdbg || config.type === DebuggerType.cppdbg)));
527+
return configs;
528+
}
529+
529530
public async buildAndRun(textEditor: vscode.TextEditor): Promise<void> {
530531
// Turn off the debug mode.
531532
return this.buildAndDebug(textEditor, false);
@@ -545,6 +546,26 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
545546
configs = configs.concat(await this.provideDebugConfigurationsForType(DebuggerType.cppvsdbg, folder));
546547
}
547548

549+
if (folder) {
550+
// Get existing debug configurations from launch.json.
551+
const existingConfigs: vscode.DebugConfiguration[] | undefined = (await this.getLaunchConfigs(folder))?.map(config => ({
552+
name: config.name,
553+
type: config.type,
554+
request: config.request,
555+
detail: config.detail ? config.detail : localize("pre.Launch.Task", "preLaunchTask: {0}", config.preLaunchTask),
556+
preLaunchTask: config.preLaunchTask,
557+
existing: TaskConfigStatus.configured
558+
}));
559+
if (existingConfigs) {
560+
const areEqual = (config1: vscode.DebugConfiguration, config2: vscode.DebugConfiguration): boolean =>
561+
(config1.name === config2.name && config1.preLaunchTask === config2.preLaunchTask
562+
&& config1.type === config2.type && config1.request === config2.request);
563+
// Remove the detected configs that are already configured once in launch.json.
564+
const dedupExistingConfigs: vscode.DebugConfiguration[] = configs.filter(detectedConfig => !existingConfigs.some(config => areEqual(config, detectedConfig)));
565+
configs = existingConfigs.concat(dedupExistingConfigs);
566+
}
567+
}
568+
548569
const defaultConfig: vscode.DebugConfiguration[] = configs.filter((config: vscode.DebugConfiguration) => (config.hasOwnProperty("isDefault") && config.isDefault));
549570
interface MenuItem extends vscode.QuickPickItem {
550571
configuration: vscode.DebugConfiguration;

0 commit comments

Comments
 (0)