@@ -70,6 +70,7 @@ let compilerDefaults: configs.CompilerDefaults;
70
70
let diagnosticsCollectionIntelliSense : vscode . DiagnosticCollection ;
71
71
let diagnosticsCollectionRefactor : vscode . DiagnosticCollection ;
72
72
let displayedSelectCompiler : boolean = false ;
73
+ let secondPromptCounter : number = 0 ;
73
74
74
75
let workspaceDisposables : vscode . Disposable [ ] = [ ] ;
75
76
export let workspaceReferences : refs . ReferencesManager ;
@@ -889,7 +890,7 @@ export class DefaultClient implements Client {
889
890
return workspaceFolder ? workspaceFolder . name : "untitled" ;
890
891
}
891
892
892
- public updateClientConfigurations ( ) : void {
893
+ public static updateClientConfigurations ( ) : void {
893
894
clients . forEach ( client => {
894
895
if ( client instanceof DefaultClient ) {
895
896
const defaultClient : DefaultClient = < DefaultClient > client ;
@@ -899,17 +900,19 @@ export class DefaultClient implements Client {
899
900
} ) ;
900
901
}
901
902
902
- public async showSelectCompiler ( paths : string [ ] ) : Promise < number > {
903
+ public async showSelectDefaultCompiler ( paths : string [ ] ) : Promise < number > {
903
904
const options : vscode . QuickPickOptions = { } ;
904
905
options . placeHolder = localize ( "select.compile.commands" , "Select a compiler to configure for IntelliSense" ) ;
905
906
906
907
const items : IndexableQuickPickItem [ ] = [ ] ;
907
908
for ( let i : number = 0 ; i < paths . length ; i ++ ) {
908
909
let option : string | undefined ;
909
910
let isCompiler : boolean = false ;
911
+ let isCl : boolean = false ;
910
912
const slash : string = ( os . platform ( ) === 'win32' ) ? "\\" : "/" ;
911
913
912
914
if ( paths [ i ] . includes ( slash ) ) {
915
+ isCl = util . isCl ( paths [ i ] ) ;
913
916
if ( paths [ i ] . split ( slash ) . pop ( ) !== undefined ) {
914
917
option = paths [ i ] . split ( slash ) . pop ( ) ;
915
918
isCompiler = true ;
@@ -918,7 +921,8 @@ export class DefaultClient implements Client {
918
921
919
922
if ( option !== undefined && isCompiler ) {
920
923
const path : string | undefined = paths [ i ] . replace ( option , "" ) ;
921
- items . push ( { label : option , description : localize ( "found.string" , "Found at {0}" , path ) , index : i } ) ;
924
+ const description : string = isCl ? "" : localize ( "found.string" , "Found at {0}" , path ) ;
925
+ items . push ( { label : option , description : description , index : i } ) ;
922
926
} else {
923
927
items . push ( { label : paths [ i ] , index : i } ) ;
924
928
}
@@ -928,22 +932,55 @@ export class DefaultClient implements Client {
928
932
return ( selection ) ? selection . index : - 1 ;
929
933
}
930
934
931
- public async handleCompilerQuickPick ( ) : Promise < void > {
935
+ public async showPrompt ( buttonMessage : string , showSecondPrompt : boolean ) : Promise < void > {
936
+ if ( secondPromptCounter < 1 ) {
937
+ const value : string | undefined = await vscode . window . showInformationMessage ( localize ( "setCompiler.message" , "You do not have IntelliSense configured. Unless you set your own configurations, IntelliSense may not be functional." ) , buttonMessage ) ;
938
+ secondPromptCounter ++ ;
939
+ if ( value === buttonMessage ) {
940
+ this . handleCompilerQuickPick ( showSecondPrompt ) ;
941
+ }
942
+ }
943
+ }
944
+
945
+ public async handleCompilerQuickPick ( showSecondPrompt : boolean ) : Promise < void > {
932
946
const settings : OtherSettings = new OtherSettings ( ) ;
933
- let paths : string [ ] = [ ] ;
947
+ const selectCompiler : string = localize ( "selectCompiler.string" , "Select Compiler" ) ;
948
+ const paths : string [ ] = [ ] ;
934
949
if ( compilerDefaults . knownCompilers !== undefined ) {
935
- paths = compilerDefaults . knownCompilers . map ( function ( a : configs . KnownCompiler ) : string { return a . path ; } ) ;
950
+ const tempPaths : string [ ] = compilerDefaults . knownCompilers . map ( function ( a : configs . KnownCompiler ) : string { return a . path ; } ) ;
951
+ let clFound : boolean = false ;
952
+ // Remove all but the first cl path.
953
+ for ( const path of tempPaths ) {
954
+ if ( clFound ) {
955
+ if ( ! util . isCl ( path ) ) {
956
+ paths . push ( path ) ;
957
+ }
958
+ } else {
959
+ if ( util . isCl ( path ) ) {
960
+ clFound = true ;
961
+ }
962
+ paths . push ( path ) ;
963
+ }
964
+ }
936
965
}
937
966
paths . push ( localize ( "selectAnotherCompiler.string" , "Select another compiler on my machine" ) ) ;
938
967
paths . push ( localize ( "installCompiler.string" , "Help me install a compiler" ) ) ;
939
968
paths . push ( localize ( "noConfig.string" , "Do not configure a compiler (not recommended)" ) ) ;
940
- const index : number = await this . showSelectCompiler ( paths ) ;
969
+ const index : number = await this . showSelectDefaultCompiler ( paths ) ;
941
970
if ( index === - 1 ) {
971
+ if ( showSecondPrompt ) {
972
+ this . showPrompt ( selectCompiler , true ) ;
973
+ }
942
974
return ;
943
975
}
944
976
if ( index === paths . length - 1 ) {
945
977
settings . defaultCompiler = "" ;
946
- } else if ( index === paths . length - 2 ) {
978
+ if ( showSecondPrompt ) {
979
+ this . showPrompt ( selectCompiler , true ) ;
980
+ }
981
+ return ;
982
+ }
983
+ if ( index === paths . length - 2 ) {
947
984
switch ( os . platform ( ) ) {
948
985
case 'win32' :
949
986
vscode . commands . executeCommand ( 'vscode.open' , "https://go.microsoft.com/fwlink/?linkid=2217614" ) ;
@@ -955,55 +992,45 @@ export class DefaultClient implements Client {
955
992
vscode . commands . executeCommand ( 'vscode.open' , "https://go.microsoft.com/fwlink/?linkid=2217615" ) ;
956
993
return ;
957
994
}
958
- } else if ( index === paths . length - 3 ) {
995
+ }
996
+ if ( index === paths . length - 3 ) {
959
997
const result : vscode . Uri [ ] | undefined = await vscode . window . showOpenDialog ( ) ;
960
- if ( result !== undefined && result . length > 0 ) {
961
- util . addTrustedCompiler ( compilerPaths , result [ 0 ] . fsPath ) ;
962
- settings . defaultCompiler = result [ 0 ] . fsPath ;
963
- compilerDefaults = await this . requestCompiler ( compilerPaths ) ;
964
- this . updateClientConfigurations ( ) ;
998
+ if ( result === undefined || result . length === 0 ) {
965
999
return ;
966
1000
}
1001
+ settings . defaultCompiler = result [ 0 ] . fsPath ;
967
1002
} else {
968
- util . addTrustedCompiler ( compilerPaths , paths [ index ] ) ;
969
- }
970
- // If a compiler is selected, update the default.compilerPath user setting.
971
- if ( index < paths . length - 3 ) {
972
- settings . defaultCompiler = paths [ index ] ;
1003
+ settings . defaultCompiler = util . isCl ( paths [ index ] ) ? "cl.exe" : paths [ index ] ;
973
1004
}
1005
+ util . addTrustedCompiler ( compilerPaths , settings . defaultCompiler ) ;
974
1006
compilerDefaults = await this . requestCompiler ( compilerPaths ) ;
975
- this . updateClientConfigurations ( ) ;
1007
+ DefaultClient . updateClientConfigurations ( ) ;
976
1008
}
977
1009
978
- async promptSelectCompiler ( command : boolean ) : Promise < void > {
1010
+ async promptSelectCompiler ( isCommand : boolean ) : Promise < void > {
1011
+ if ( compilerDefaults === undefined ) {
1012
+ return ;
1013
+ }
979
1014
const selectCompiler : string = localize ( "selectCompiler.string" , "Select Compiler" ) ;
980
1015
const confirmCompiler : string = localize ( "confirmCompiler.string" , "Yes" ) ;
981
1016
const settings : OtherSettings = new OtherSettings ( ) ;
982
- if ( compilerDefaults . compilerPath !== "" ) {
983
- if ( ! command && ( compilerDefaults . compilerPath !== undefined ) ) {
984
- const value : string | undefined = await vscode . window . showInformationMessage ( localize ( "selectCompiler.message" , "The compiler {0} was found on this computer . Do you want to configure it for IntelliSense ?" , compilerDefaults . compilerPath ) , confirmCompiler , selectCompiler ) ;
1017
+ if ( isCommand || compilerDefaults . compilerPath !== "" ) {
1018
+ if ( ! isCommand && ( compilerDefaults . compilerPath !== undefined ) ) {
1019
+ const value : string | undefined = await vscode . window . showInformationMessage ( localize ( "selectCompiler.message" , "The compiler {0} was found. Do you want to configure IntelliSense with this compiler ?" , compilerDefaults . compilerPath ) , confirmCompiler , selectCompiler ) ;
985
1020
if ( value === confirmCompiler ) {
986
1021
compilerPaths = await util . addTrustedCompiler ( compilerPaths , compilerDefaults . compilerPath ) ;
987
1022
settings . defaultCompiler = compilerDefaults . compilerPath ;
988
1023
compilerDefaults = await this . requestCompiler ( compilerPaths ) ;
989
- this . updateClientConfigurations ( ) ;
1024
+ DefaultClient . updateClientConfigurations ( ) ;
990
1025
} else if ( value === selectCompiler ) {
991
- this . handleCompilerQuickPick ( ) ;
1026
+ this . handleCompilerQuickPick ( true ) ;
992
1027
} else {
993
- const setCompiler : string = localize ( "setCompiler.string" , "Set Compiler" ) ;
994
- const value : string | undefined = await vscode . window . showInformationMessage ( localize ( "setCompiler.message" , "You do not have a compiler configured. Unless you set your own configurations, IntelliSense may not be functional." ) , selectCompiler ) ;
995
- if ( value === setCompiler ) {
996
- this . handleCompilerQuickPick ( ) ;
997
- }
998
- }
999
- } else if ( ! command && ( compilerDefaults . compilerPath === undefined ) ) {
1000
- const setCompiler : string = localize ( "setCompiler.string" , "Set Compiler" ) ;
1001
- const value : string | undefined = await vscode . window . showInformationMessage ( localize ( "setCompiler.message" , "You do not have a compiler configured. Unless you set your own configurations, IntelliSense may not be functional." ) , selectCompiler ) ;
1002
- if ( value === setCompiler ) {
1003
- this . handleCompilerQuickPick ( ) ;
1028
+ this . showPrompt ( selectCompiler , true ) ;
1004
1029
}
1030
+ } else if ( ! isCommand && ( compilerDefaults . compilerPath === undefined ) ) {
1031
+ this . showPrompt ( selectCompiler , false ) ;
1005
1032
} else {
1006
- this . handleCompilerQuickPick ( ) ;
1033
+ this . handleCompilerQuickPick ( false ) ;
1007
1034
}
1008
1035
}
1009
1036
}
@@ -1125,16 +1152,9 @@ export class DefaultClient implements Client {
1125
1152
if ( ( vscode . workspace . workspaceFolders === undefined ) || ( initializedClientCount >= vscode . workspace . workspaceFolders . length ) ) {
1126
1153
// The configurations will not be sent to the language server until the default include paths and frameworks have been set.
1127
1154
// The event handlers must be set before this happens.
1128
- const inputCompilerDefaults : configs . CompilerDefaults = await this . requestCompiler ( compilerPaths ) ;
1129
- compilerDefaults = inputCompilerDefaults ;
1130
- clients . forEach ( client => {
1131
- if ( client instanceof DefaultClient ) {
1132
- const defaultClient : DefaultClient = < DefaultClient > client ;
1133
- defaultClient . configuration . CompilerDefaults = compilerDefaults ;
1134
- defaultClient . configuration . handleConfigurationChange ( ) ;
1135
- }
1136
- } ) ;
1137
- if ( ! compilerDefaults . trustedCompilerFound && ! displayedSelectCompiler ) {
1155
+ compilerDefaults = await this . requestCompiler ( compilerPaths ) ;
1156
+ DefaultClient . updateClientConfigurations ( ) ;
1157
+ if ( ! compilerDefaults . trustedCompilerFound && ! displayedSelectCompiler && ( compilerPaths . length !== 1 || compilerPaths [ 0 ] !== "" ) ) {
1138
1158
// if there is no compilerPath in c_cpp_properties.json, prompt user to configure a compiler
1139
1159
this . promptSelectCompiler ( false ) ;
1140
1160
displayedSelectCompiler = true ;
0 commit comments