@@ -53,6 +53,7 @@ import {
5353} from './codeAnalysis' ;
5454import { DebugProtocolParams , getDiagnosticsChannel , getOutputChannelLogger , logDebugProtocol , Logger , logLocalized , showWarning , ShowWarningParams } from '../logger' ;
5555import _ = require( 'lodash' ) ;
56+ import { DebugConfigurationProvider } from '../Debugger/configurationProvider' ;
5657
5758const deepCopy = ( obj : any ) => _ . cloneDeep ( obj ) ;
5859nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
@@ -69,14 +70,6 @@ export function hasTrustedCompilerPaths(): boolean {
6970 return trustedCompilerPaths . length !== 0 ;
7071}
7172
72- export function addTrustedCompiler ( path : string ) : void {
73- // Detect duplicate paths or invalid paths.
74- if ( trustedCompilerPaths . includes ( path ) || path === null || path === undefined ) {
75- return ;
76- }
77- trustedCompilerPaths . push ( path ) ;
78- }
79-
8073// Data shared by all clients.
8174let languageClient : LanguageClient ;
8275let firstClientStarted : Promise < void > ;
@@ -213,7 +206,7 @@ interface ReportStatusNotificationBody extends WorkspaceFolderParams {
213206}
214207
215208interface QueryDefaultCompilerParams {
216- trustedCompilerPaths : string [ ] ;
209+ newTrustedCompilerPath : string ;
217210}
218211
219212interface CppPropertiesParams extends WorkspaceFolderParams {
@@ -826,6 +819,7 @@ export interface Client {
826819 isInitialized ( ) : boolean ;
827820 getShowConfigureIntelliSenseButton ( ) : boolean ;
828821 setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
822+ addTrustedCompiler ( path : string ) : Promise < void > ;
829823}
830824
831825export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -1129,8 +1123,7 @@ export class DefaultClient implements Client {
11291123 }
11301124
11311125 ui . ShowConfigureIntelliSenseButton ( false , this ) ;
1132- addTrustedCompiler ( settings . defaultCompilerPath ) ;
1133- compilerDefaults = await this . requestCompiler ( trustedCompilerPaths ) ;
1126+ await this . addTrustedCompiler ( settings . defaultCompilerPath ) ;
11341127 DefaultClient . updateClientConfigurations ( ) ;
11351128 } finally {
11361129 if ( compilersOnly ) {
@@ -1161,7 +1154,7 @@ export class DefaultClient implements Client {
11611154 }
11621155
11631156 public async rescanCompilers ( sender ?: any ) : Promise < void > {
1164- compilerDefaults = await this . requestCompiler ( trustedCompilerPaths ) ;
1157+ compilerDefaults = await this . requestCompiler ( ) ;
11651158 DefaultClient . updateClientConfigurations ( ) ;
11661159 if ( compilerDefaults . knownCompilers !== undefined && compilerDefaults . knownCompilers . length > 0 ) {
11671160 await this . promptSelectCompiler ( true , sender ) ;
@@ -1181,9 +1174,8 @@ export class DefaultClient implements Client {
11811174 if ( ! isCommand && ( compilerDefaults . compilerPath !== undefined ) ) {
11821175 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 ) ;
11831176 if ( value === confirmCompiler ) {
1184- addTrustedCompiler ( compilerDefaults . compilerPath ) ;
11851177 settings . defaultCompilerPath = compilerDefaults . compilerPath ;
1186- compilerDefaults = await this . requestCompiler ( trustedCompilerPaths ) ;
1178+ await this . addTrustedCompiler ( settings . defaultCompilerPath ) ;
11871179 DefaultClient . updateClientConfigurations ( ) ;
11881180 action = "confirm compiler" ;
11891181 ui . ShowConfigureIntelliSenseButton ( false , this ) ;
@@ -1216,9 +1208,8 @@ export class DefaultClient implements Client {
12161208 if ( ! isCommand && ( compilerDefaults . compilerPath !== undefined ) ) {
12171209 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 ) ;
12181210 if ( value === confirmCompiler ) {
1219- addTrustedCompiler ( compilerDefaults . compilerPath ) ;
12201211 settings . defaultCompilerPath = compilerDefaults . compilerPath ;
1221- compilerDefaults = await this . requestCompiler ( trustedCompilerPaths ) ;
1212+ await this . addTrustedCompiler ( settings . defaultCompilerPath ) ;
12221213 DefaultClient . updateClientConfigurations ( ) ;
12231214 action = "confirm compiler" ;
12241215 ui . ShowConfigureIntelliSenseButton ( false , this ) ;
@@ -1386,7 +1377,7 @@ export class DefaultClient implements Client {
13861377 } ) ;
13871378 // The configurations will not be sent to the language server until the default include paths and frameworks have been set.
13881379 // The event handlers must be set before this happens.
1389- compilerDefaults = await this . requestCompiler ( trustedCompilerPaths ) ;
1380+ compilerDefaults = await this . requestCompiler ( ) ;
13901381 DefaultClient . updateClientConfigurations ( ) ;
13911382 clients . forEach ( client => {
13921383 if ( client instanceof DefaultClient ) {
@@ -2306,7 +2297,7 @@ export class DefaultClient implements Client {
23062297 console . assert ( this . languageClient !== undefined , "This method must not be called until this.languageClient is set in \"onReady\"" ) ;
23072298
23082299 this . languageClient . onNotification ( ReloadWindowNotification , ( ) => void util . promptForReloadWindowDueToSettingsChange ( ) ) ;
2309- this . languageClient . onNotification ( UpdateTrustedCompilersNotification , ( e ) => addTrustedCompiler ( e . compilerPath ) ) ;
2300+ this . languageClient . onNotification ( UpdateTrustedCompilersNotification , ( e ) => { this . addTrustedCompiler ( e . compilerPath ) ; return ; } ) ;
23102301 this . languageClient . onNotification ( LogTelemetryNotification , logTelemetry ) ;
23112302 this . languageClient . onNotification ( ReportStatusNotification , ( e ) => void this . updateStatus ( e ) ) ;
23122303 this . languageClient . onNotification ( ReportTagParseStatusNotification , ( e ) => this . updateTagParseStatus ( e ) ) ;
@@ -2816,9 +2807,9 @@ export class DefaultClient implements Client {
28162807 return this . requestWhenReady ( ( ) => this . languageClient . sendRequest ( SwitchHeaderSourceRequest , params ) ) ;
28172808 }
28182809
2819- public async requestCompiler ( compilerPath : string [ ] ) : Promise < configs . CompilerDefaults > {
2810+ public async requestCompiler ( newCompilerPath ? : string ) : Promise < configs . CompilerDefaults > {
28202811 const params : QueryDefaultCompilerParams = {
2821- trustedCompilerPaths : compilerPath
2812+ newTrustedCompilerPath : newCompilerPath ?? ""
28222813 } ;
28232814 const results : configs . CompilerDefaults = await this . languageClient . sendRequest ( QueryCompilerDefaultsRequest , params ) ;
28242815 vscode . commands . executeCommand ( 'setContext' , 'cpptools.scanForCompilersDone' , true ) ;
@@ -3096,7 +3087,7 @@ export class DefaultClient implements Client {
30963087 util . isArrayOfString ( itemConfig . compilerArgs ) ? itemConfig . compilerArgs : undefined ) ;
30973088 itemConfig . compilerPath = compilerPathAndArgs . compilerPath ;
30983089 if ( itemConfig . compilerPath !== undefined ) {
3099- addTrustedCompiler ( itemConfig . compilerPath ) ;
3090+ this . addTrustedCompiler ( itemConfig . compilerPath ) ;
31003091 }
31013092 if ( providerVersion < Version . v6 ) {
31023093 itemConfig . compilerArgsLegacy = compilerPathAndArgs . allCompilerArgs ;
@@ -3199,7 +3190,7 @@ export class DefaultClient implements Client {
31993190 util . isArrayOfString ( sanitized . compilerArgs ) ? sanitized . compilerArgs : undefined ) ;
32003191 sanitized . compilerPath = compilerPathAndArgs . compilerPath ;
32013192 if ( sanitized . compilerPath !== undefined ) {
3202- addTrustedCompiler ( sanitized . compilerPath ) ;
3193+ this . addTrustedCompiler ( sanitized . compilerPath ) ;
32033194 }
32043195 if ( providerVersion < Version . v6 ) {
32053196 sanitized . compilerArgsLegacy = compilerPathAndArgs . allCompilerArgs ;
@@ -3747,6 +3738,19 @@ export class DefaultClient implements Client {
37473738 public setReferencesCommandMode ( mode : refs . ReferencesCommandMode ) : void {
37483739 this . model . referencesCommandMode . Value = mode ;
37493740 }
3741+
3742+ public async addTrustedCompiler ( path : string ) : Promise < void > {
3743+ if ( path === null || path === undefined ) {
3744+ return ;
3745+ }
3746+ if ( trustedCompilerPaths . includes ( path ) ) {
3747+ DebugConfigurationProvider . ClearDetectedBuildTasks ( ) ;
3748+ return ;
3749+ }
3750+ trustedCompilerPaths . push ( path ) ;
3751+ compilerDefaults = await this . requestCompiler ( path ) ;
3752+ DebugConfigurationProvider . ClearDetectedBuildTasks ( ) ;
3753+ }
37503754}
37513755
37523756function getLanguageServerFileName ( ) : string {
@@ -3855,4 +3859,5 @@ class NullClient implements Client {
38553859 isInitialized ( ) : boolean { return true ; }
38563860 getShowConfigureIntelliSenseButton ( ) : boolean { return false ; }
38573861 setShowConfigureIntelliSenseButton ( show : boolean ) : void { }
3862+ addTrustedCompiler ( path : string ) : Promise < void > { return Promise . resolve ( ) ; }
38583863}
0 commit comments