@@ -758,54 +758,22 @@ export class CTestDriver implements vscode.Disposable {
758
758
759
759
private async debugCTestImpl ( workspaceFolder : vscode . WorkspaceFolder , testName : string , cancellation : vscode . CancellationToken ) : Promise < void > {
760
760
const magicValue = sessionNum ++ ;
761
- const launchConfig = vscode . workspace . getConfiguration (
762
- 'launch' ,
763
- workspaceFolder . uri
764
- ) ;
765
- const workspaceLaunchConfig = vscode . workspace . workspaceFile ? vscode . workspace . getConfiguration (
766
- 'launch' ,
767
- vscode . workspace . workspaceFile
768
- ) : undefined ;
769
- const configs = launchConfig . get < vscode . DebugConfiguration [ ] > ( 'configurations' ) ?? [ ] ;
770
- const workspaceConfigs = workspaceLaunchConfig ?. get < vscode . DebugConfiguration [ ] > ( 'configurations' ) ?? [ ] ;
771
- if ( configs . length === 0 && workspaceConfigs . length === 0 ) {
761
+
762
+ const testProgram = this . testProgram ( testName ) ;
763
+ const basename = path . parse ( testProgram ) . name ;
764
+ const debugConfig = await this . projectController ?. getActiveCMakeProject ( ) ?. getDebugConfiguration ( basename ) ;
765
+
766
+ if ( debugConfig === null || debugConfig === undefined ) {
772
767
log . error ( localize ( 'no.launch.config' , 'No launch configurations found.' ) ) ;
773
768
return ;
774
769
}
775
770
776
- interface ConfigItem extends vscode . QuickPickItem {
777
- label : string ;
778
- config : vscode . DebugConfiguration ;
779
- detail : string ;
780
- // Undefined for workspace launch config
781
- folder ?: vscode . WorkspaceFolder ;
782
- }
783
- let allConfigItems : ConfigItem [ ] = configs . map ( config => ( { label : config . name , config, folder : workspaceFolder , detail : workspaceFolder . uri . fsPath } ) ) ;
784
- allConfigItems = allConfigItems . concat ( workspaceConfigs . map ( config => ( { label : config . name , config, detail : vscode . workspace . workspaceFile ! . fsPath } ) ) ) ;
785
- let chosenConfig : ConfigItem | undefined ;
786
- if ( allConfigItems . length === 1 ) {
787
- chosenConfig = allConfigItems [ 0 ] ;
788
- } else {
789
- // TODO: we can remember the last choice once the CMake side panel work is done
790
- const chosen = await vscode . window . showQuickPick ( allConfigItems , { placeHolder : localize ( 'choose.launch.config' , 'Choose a launch configuration to debug the test with.' ) } ) ;
791
- if ( chosen ) {
792
- chosenConfig = chosen ;
793
- } else {
794
- return ;
795
- }
796
- }
797
-
798
- // Commands can't be used to replace array (i.e., args); and both test program and test args requires folder and
799
- // test name as parameters, which means one lauch config for each test. So replacing them here is a better way.
800
- chosenConfig . config = this . replaceAllInObject < vscode . DebugConfiguration > ( chosenConfig . config , '${cmake.testProgram}' , this . testProgram ( testName ) ) ;
801
- chosenConfig . config = this . replaceAllInObject < vscode . DebugConfiguration > ( chosenConfig . config , '${cmake.testWorkingDirectory}' , this . testWorkingDirectory ( testName ) ) ;
802
-
803
- // Replace cmake.testArgs wrapped in quotes, like `"${command:cmake.testArgs}"`, without any spaces in between,
804
- // since we need to repalce the quotes as well.
805
- chosenConfig . config = this . replaceArrayItems ( chosenConfig . config , '${cmake.testArgs}' , this . testArgs ( testName ) ) as vscode . DebugConfiguration ;
771
+ debugConfig . cwd = this . testWorkingDirectory ( testName ) ! ;
772
+ debugConfig . args = this . testArgs ( testName ) ! ;
806
773
807
774
// Identify the session we started
808
- chosenConfig . config [ magicKey ] = magicValue ;
775
+ debugConfig [ magicKey ] = magicValue ;
776
+
809
777
let onDidStartDebugSession : vscode . Disposable | undefined ;
810
778
let onDidTerminateDebugSession : vscode . Disposable | undefined ;
811
779
let sessionId : string | undefined ;
@@ -828,7 +796,7 @@ export class CTestDriver implements vscode.Disposable {
828
796
log . info ( 'debugSessionTerminated' ) ;
829
797
} ) ;
830
798
831
- const debugStarted = await vscode . debug . startDebugging ( chosenConfig . folder , chosenConfig . config ! ) ;
799
+ const debugStarted = await vscode . debug . startDebugging ( workspaceFolder , debugConfig ! ) ;
832
800
if ( debugStarted ) {
833
801
const session = await started ;
834
802
if ( session ) {
@@ -879,57 +847,6 @@ export class CTestDriver implements vscode.Disposable {
879
847
return [ ] ;
880
848
}
881
849
882
- private replaceAllInObject < T > ( obj : any , str : string , replace : string ) : T {
883
- const regex = new RegExp ( util . escapeStringForRegex ( str ) , 'g' ) ;
884
- if ( util . isString ( obj ) ) {
885
- obj = obj . replace ( regex , replace ) ;
886
- } else if ( util . isArray ( obj ) ) {
887
- for ( let i = 0 ; i < obj . length ; i ++ ) {
888
- obj [ i ] = this . replaceAllInObject ( obj [ i ] , str , replace ) ;
889
- }
890
- } else if ( typeof obj === 'object' ) {
891
- for ( const key of Object . keys ( obj ) ) {
892
- obj [ key ] = this . replaceAllInObject ( obj [ key ] , str , replace ) ;
893
- }
894
- }
895
- return obj ;
896
- }
897
-
898
- private replaceArrayItems ( obj : any , str : string , replace : string [ ] ) {
899
- if ( util . isArray ( obj ) && obj . length !== 0 ) {
900
- const result : any [ ] = [ ] ;
901
- for ( let i = 0 ; i < obj . length ; i ++ ) {
902
- if ( util . isArray ( obj [ i ] ) || typeof obj [ i ] === 'object' ) {
903
- result . push ( this . replaceArrayItems ( obj [ i ] , str , replace ) ) ;
904
- } else if ( util . isString ( obj [ i ] ) ) {
905
- const replacedItem = this . replaceArrayItemsHelper ( obj [ i ] as string , str , replace ) ;
906
- if ( util . isArray ( replacedItem ) ) {
907
- result . push ( ...replacedItem ) ;
908
- } else {
909
- result . push ( replacedItem ) ;
910
- }
911
- } else {
912
- result . push ( obj [ i ] ) ;
913
- }
914
- }
915
- return result ;
916
- }
917
- if ( typeof obj === 'object' ) {
918
- for ( const key of Object . keys ( obj ) ) {
919
- obj [ key ] = this . replaceArrayItems ( obj [ key ] , str , replace ) ;
920
- }
921
- return obj ;
922
- }
923
- return obj ;
924
- }
925
-
926
- private replaceArrayItemsHelper ( orig : string , str : string , replace : string [ ] ) : string | string [ ] {
927
- if ( orig === str ) {
928
- return replace ;
929
- }
930
- return orig ;
931
- }
932
-
933
850
private async debugTestHandler ( request : vscode . TestRunRequest , cancellation : vscode . CancellationToken ) {
934
851
if ( ! testExplorer ) {
935
852
return ;
0 commit comments