@@ -21,7 +21,7 @@ import { setTimeout } from 'timers';
21
21
import * as which from 'which' ;
22
22
import { Version , WorkspaceBrowseConfiguration } from 'vscode-cpptools' ;
23
23
import { getOutputChannelLogger } from '../logger' ;
24
-
24
+ import { compilerPaths } from './client' ;
25
25
nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
26
26
const localize : nls . LocalizeFunc = nls . loadMessageBundle ( ) ;
27
27
@@ -103,6 +103,8 @@ export interface Browse {
103
103
export interface KnownCompiler {
104
104
path : string ;
105
105
isC : boolean ;
106
+ isTrusted : boolean ; // May be used in the future for build tasks.
107
+ isCL : boolean ;
106
108
}
107
109
108
110
export interface CompilerDefaults {
@@ -115,6 +117,7 @@ export interface CompilerDefaults {
115
117
frameworks : string [ ] ;
116
118
windowsSdkVersion : string ;
117
119
intelliSenseMode : string ;
120
+ trustedCompilerFound : boolean ;
118
121
}
119
122
120
123
export class CppProperties {
@@ -157,6 +160,7 @@ export class CppProperties {
157
160
// Any time the default settings are parsed and assigned to `this.configurationJson`,
158
161
// we want to track when the default includes have been added to it.
159
162
private configurationIncomplete : boolean = true ;
163
+ trustedCompilerFound : boolean = false ;
160
164
161
165
constructor ( rootUri ?: vscode . Uri , workspaceFolder ?: vscode . WorkspaceFolder ) {
162
166
this . rootUri = rootUri ;
@@ -206,18 +210,11 @@ export class CppProperties {
206
210
return result ;
207
211
}
208
212
209
- public set CompilerDefaults ( compilerDefaults : CompilerDefaults ) {
210
- this . defaultCompilerPath = compilerDefaults . compilerPath ;
211
- this . knownCompilers = compilerDefaults . knownCompilers ;
212
- this . defaultCStandard = compilerDefaults . cStandard ;
213
- this . defaultCppStandard = compilerDefaults . cppStandard ;
214
- this . defaultIncludes = compilerDefaults . includes ;
215
- this . defaultFrameworks = compilerDefaults . frameworks ;
216
- this . defaultWindowsSdkVersion = compilerDefaults . windowsSdkVersion ;
217
- this . defaultIntelliSenseMode = compilerDefaults . intelliSenseMode ;
213
+ public setupConfigurations ( ) : void {
218
214
219
215
// defaultPaths is only used when there isn't a c_cpp_properties.json, but we don't send the configuration changed event
220
216
// to the language server until the default include paths and frameworks have been sent.
217
+
221
218
const configFilePath : string = path . join ( this . configFolder , "c_cpp_properties.json" ) ;
222
219
if ( this . rootUri !== null && fs . existsSync ( configFilePath ) ) {
223
220
this . propertiesFile = vscode . Uri . file ( configFilePath ) ;
@@ -273,7 +270,7 @@ export class CppProperties {
273
270
const savedDocWorkspaceFolder : vscode . WorkspaceFolder | undefined = vscode . workspace . getWorkspaceFolder ( doc . uri ) ;
274
271
const notifyingWorkspaceFolder : vscode . WorkspaceFolder | undefined = vscode . workspace . getWorkspaceFolder ( vscode . Uri . file ( settingsPath ) ) ;
275
272
if ( ( ! savedDocWorkspaceFolder && vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 && notifyingWorkspaceFolder === vscode . workspace . workspaceFolders [ 0 ] )
276
- || savedDocWorkspaceFolder === notifyingWorkspaceFolder ) {
273
+ || savedDocWorkspaceFolder === notifyingWorkspaceFolder ) {
277
274
let fileType : string | undefined ;
278
275
const documentPath : string = doc . uri . fsPath . toLowerCase ( ) ;
279
276
if ( documentPath . endsWith ( "cmakelists.txt" ) ) {
@@ -298,6 +295,17 @@ export class CppProperties {
298
295
299
296
this . handleConfigurationChange ( ) ;
300
297
}
298
+ public set CompilerDefaults ( compilerDefaults : CompilerDefaults ) {
299
+ this . defaultCompilerPath = compilerDefaults . compilerPath ;
300
+ this . knownCompilers = compilerDefaults . knownCompilers ;
301
+ this . defaultCStandard = compilerDefaults . cStandard ;
302
+ this . defaultCppStandard = compilerDefaults . cppStandard ;
303
+ this . defaultIncludes = compilerDefaults . includes ;
304
+ this . defaultFrameworks = compilerDefaults . frameworks ;
305
+ this . defaultWindowsSdkVersion = compilerDefaults . windowsSdkVersion ;
306
+ this . defaultIntelliSenseMode = compilerDefaults . intelliSenseMode ;
307
+ this . trustedCompilerFound = compilerDefaults . trustedCompilerFound ;
308
+ }
301
309
302
310
public get VcpkgInstalled ( ) : boolean {
303
311
return this . vcpkgIncludes . length > 0 ;
@@ -857,7 +865,7 @@ export class CppProperties {
857
865
configuration . compilerPath = this . updateConfigurationString ( configuration . compilerPath , settings . defaultCompilerPath , env , true ) ;
858
866
configuration . compilerPathIsExplicit = configuration . compilerPathIsExplicit || settings . defaultCompilerPath !== undefined ;
859
867
if ( configuration . compilerPath === undefined ) {
860
- if ( ! ! this . defaultCompilerPath ) {
868
+ if ( ! ! this . defaultCompilerPath && this . trustedCompilerFound ) {
861
869
// If no config value yet set for these, pick up values from the defaults, but don't consider them explicit.
862
870
configuration . compilerPath = this . defaultCompilerPath ;
863
871
if ( ! configuration . cStandard && ! ! this . defaultCStandard ) {
@@ -883,6 +891,9 @@ export class CppProperties {
883
891
configuration . macFrameworkPath = this . defaultFrameworks ;
884
892
}
885
893
}
894
+ } else {
895
+ // add compiler to list of trusted compilers
896
+ util . addTrustedCompiler ( compilerPaths , configuration . compilerPath ) ;
886
897
}
887
898
} else {
888
899
// However, if compileCommands are used and compilerPath is explicitly set, it's still necessary to resolve variables in it.
0 commit comments