@@ -257,16 +257,8 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
257
257
let buildTasks : CppBuildTask [ ] = [ ] ;
258
258
await this . loadDetectedTasks ( ) ;
259
259
// 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 ) ) ) ) ;
270
262
buildTasks = buildTasks . concat ( configuredBuildTasks , dedupDetectedBuildTasks ) ;
271
263
272
264
if ( buildTasks . length === 0 ) {
@@ -526,6 +518,15 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
526
518
}
527
519
}
528
520
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
+
529
530
public async buildAndRun ( textEditor : vscode . TextEditor ) : Promise < void > {
530
531
// Turn off the debug mode.
531
532
return this . buildAndDebug ( textEditor , false ) ;
@@ -545,6 +546,26 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
545
546
configs = configs . concat ( await this . provideDebugConfigurationsForType ( DebuggerType . cppvsdbg , folder ) ) ;
546
547
}
547
548
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
+
548
569
const defaultConfig : vscode . DebugConfiguration [ ] = configs . filter ( ( config : vscode . DebugConfiguration ) => ( config . hasOwnProperty ( "isDefault" ) && config . isDefault ) ) ;
549
570
interface MenuItem extends vscode . QuickPickItem {
550
571
configuration : vscode . DebugConfiguration ;
0 commit comments