Skip to content

Commit 94e02c7

Browse files
committed
add launch.json configs
1 parent accd0fb commit 94e02c7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
526526
}
527527
}
528528

529+
public async getLaunchConfigs(folder: vscode.WorkspaceFolder | undefined): Promise<vscode.WorkspaceConfiguration[] | undefined> {
530+
let configs: vscode.WorkspaceConfiguration[] | undefined = vscode.workspace.getConfiguration('launch', folder).get('configurations');
531+
if (!configs) {
532+
return undefined;
533+
}
534+
configs = configs.filter(config => (config.name && config.type === DebuggerType.cppvsdbg || config.type === DebuggerType.cppdbg) && config.request === "launch");
535+
return configs;
536+
}
537+
529538
public async buildAndRun(textEditor: vscode.TextEditor): Promise<void> {
530539
// Turn off the debug mode.
531540
return this.buildAndDebug(textEditor, false);
@@ -544,6 +553,36 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
544553
if (os.platform() === 'win32') {
545554
configs = configs.concat(await this.provideDebugConfigurationsForType(DebuggerType.cppvsdbg, folder));
546555
}
556+
557+
if (folder) {
558+
// Get existing debug configurations from launch.json.
559+
let existingConfigs: vscode.DebugConfiguration[] | undefined = (await this.getLaunchConfigs(folder))?.map(config =>
560+
({name: config.name,
561+
type: config.type,
562+
request: config.request,
563+
detail: config.detail ? config.detail : localize("pre.Launch.Task", "preLaunchTask: {0}", config.preLaunchTask),
564+
preLaunchTask: config.preLaunchTask,
565+
existing: TaskConfigStatus.configured
566+
}));
567+
568+
// Remove the detected configs that are already configured once in launch.json.
569+
const dedupExistingConfigs: vscode.DebugConfiguration[] = configs.filter(detectedConfig => {
570+
let isAlreadyConfigured: boolean = false;
571+
if (existingConfigs && existingConfigs.length !== 0) {
572+
for (const config of existingConfigs) {
573+
if (config.name === detectedConfig.name &&
574+
(config.preLaunchTask as string) === (detectedConfig.preLaunchTask as string) &&
575+
config.type === detectedConfig.type &&
576+
config.request === detectedConfig.request) {
577+
isAlreadyConfigured = true;
578+
break;
579+
}
580+
}
581+
}
582+
return !isAlreadyConfigured;
583+
});
584+
configs = existingConfigs ? existingConfigs.concat(dedupExistingConfigs) : dedupExistingConfigs;
585+
}
547586

548587
const defaultConfig: vscode.DebugConfiguration[] = configs.filter((config: vscode.DebugConfiguration) => (config.hasOwnProperty("isDefault") && config.isDefault));
549588
interface MenuItem extends vscode.QuickPickItem {

0 commit comments

Comments
 (0)