@@ -526,6 +526,15 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
526
526
}
527
527
}
528
528
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
+
529
538
public async buildAndRun ( textEditor : vscode . TextEditor ) : Promise < void > {
530
539
// Turn off the debug mode.
531
540
return this . buildAndDebug ( textEditor , false ) ;
@@ -544,6 +553,36 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
544
553
if ( os . platform ( ) === 'win32' ) {
545
554
configs = configs . concat ( await this . provideDebugConfigurationsForType ( DebuggerType . cppvsdbg , folder ) ) ;
546
555
}
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
+ }
547
586
548
587
const defaultConfig : vscode . DebugConfiguration [ ] = configs . filter ( ( config : vscode . DebugConfiguration ) => ( config . hasOwnProperty ( "isDefault" ) && config . isDefault ) ) ;
549
588
interface MenuItem extends vscode . QuickPickItem {
0 commit comments