@@ -89,6 +89,9 @@ export interface Browse {
8989
9090export interface Configuration {
9191 name : string ;
92+ compilerPath ?: string ;
93+ cStandard ?: string ;
94+ cppStandard ?: string ;
9295 includePath ?: string [ ] ;
9396 macFrameworkPath ?: string [ ] ;
9497 defines ?: string [ ] ;
@@ -98,7 +101,10 @@ export interface Configuration {
98101 browse ?: Browse ;
99102}
100103
101- export interface DefaultPaths {
104+ export interface CompilerDefaults {
105+ compilerPath : string ;
106+ cStandard : string ;
107+ cppStandard : string ;
102108 includes : string [ ] ;
103109 frameworks : string [ ] ;
104110}
@@ -116,6 +122,9 @@ export class CppProperties {
116122 private configFileWatcher : vscode . FileSystemWatcher = null ;
117123 private configFileWatcherFallbackTime : Date = new Date ( ) ; // Used when file watching fails.
118124 private compileCommandFileWatchers : fs . FSWatcher [ ] = [ ] ;
125+ private defaultCompilerPath : string = null ;
126+ private defaultCStandard : string = null ;
127+ private defaultCppStandard : string = null ;
119128 private defaultIncludes : string [ ] = null ;
120129 private defaultFrameworks : string [ ] = null ;
121130 private readonly configurationGlobPattern : string = "**/c_cpp_properties.json" ; // TODO: probably should be a single file, not all files...
@@ -171,9 +180,31 @@ export class CppProperties {
171180 return result ;
172181 }
173182
174- public set DefaultPaths ( paths : DefaultPaths ) {
175- this . defaultIncludes = paths . includes ;
176- this . defaultFrameworks = paths . frameworks ;
183+ public set CompilerDefaults ( compilerDefaults : CompilerDefaults ) {
184+ this . defaultCompilerPath = compilerDefaults . compilerPath ;
185+ this . defaultCStandard = compilerDefaults . cStandard ;
186+ this . defaultCppStandard = compilerDefaults . cppStandard ;
187+ this . defaultIncludes = compilerDefaults . includes ;
188+ this . defaultFrameworks = compilerDefaults . frameworks ;
189+
190+ // Update the compilerPath, cStandard, and cppStandard with the default being used.
191+ let doUpdate : boolean = false ;
192+ let config : Configuration = this . configurationJson . configurations [ this . CurrentConfiguration ] ;
193+ if ( this . defaultCompilerPath && this . defaultCompilerPath . length > 0 && ( ! config . compilerPath || config . compilerPath . length === 0 ) ) {
194+ config . compilerPath = this . defaultCompilerPath ;
195+ doUpdate = true ;
196+ }
197+ if ( this . defaultCStandard && this . defaultCStandard . length > 0 && ( ! config . cStandard || config . cStandard . length === 0 ) ) {
198+ config . cStandard = this . defaultCStandard ;
199+ doUpdate = true ;
200+ }
201+ if ( this . defaultCppStandard && this . defaultCppStandard . length > 0 && ( ! config . cppStandard || config . cppStandard . length === 0 ) ) {
202+ config . cppStandard = this . defaultCppStandard ;
203+ doUpdate = true ;
204+ }
205+ if ( doUpdate ) {
206+ fs . writeFileSync ( this . propertiesFile . fsPath , JSON . stringify ( this . configurationJson , null , 4 ) ) ;
207+ }
177208
178209 // defaultPaths is only used when there isn't a c_cpp_properties.json, but we don't send the configuration changed event
179210 // to the language server until the default include paths and frameworks have been sent.
@@ -202,12 +233,21 @@ export class CppProperties {
202233 }
203234
204235 private applyDefaultIncludePathsAndFrameworks ( ) : void {
205- if ( this . configurationIncomplete && this . defaultIncludes !== undefined && this . defaultFrameworks !== undefined ) {
236+ if ( this . configurationIncomplete && this . defaultIncludes && this . defaultFrameworks ) {
206237 this . configurationJson . configurations [ this . CurrentConfiguration ] . includePath = this . defaultIncludes ;
207238 this . configurationJson . configurations [ this . CurrentConfiguration ] . browse . path = this . defaultIncludes ;
208239 if ( process . platform === 'darwin' ) {
209240 this . configurationJson . configurations [ this . CurrentConfiguration ] . macFrameworkPath = this . defaultFrameworks ;
210241 }
242+ if ( this . defaultCompilerPath ) {
243+ this . configurationJson . configurations [ this . CurrentConfiguration ] . compilerPath = this . defaultCompilerPath ;
244+ }
245+ if ( this . defaultCStandard ) {
246+ this . configurationJson . configurations [ this . CurrentConfiguration ] . cStandard = this . defaultCStandard ;
247+ }
248+ if ( this . defaultCppStandard ) {
249+ this . configurationJson . configurations [ this . CurrentConfiguration ] . cppStandard = this . defaultCppStandard ;
250+ }
211251 this . configurationIncomplete = false ;
212252 }
213253 }
@@ -293,7 +333,7 @@ export class CppProperties {
293333 if ( configuration . includePath ) {
294334 configuration . includePath = this . resolveAndSplit ( configuration . includePath ) ;
295335 }
296- if ( configuration . browse ) {
336+ if ( configuration . browse && configuration . browse . path ) {
297337 configuration . browse . path = this . resolveAndSplit ( configuration . browse . path ) ;
298338 }
299339 if ( configuration . macFrameworkPath ) {
@@ -305,6 +345,9 @@ export class CppProperties {
305345 if ( configuration . compileCommands ) {
306346 configuration . compileCommands = util . resolveVariables ( configuration . compileCommands ) ;
307347 }
348+ if ( configuration . compilerPath ) {
349+ configuration . compilerPath = util . resolveVariables ( configuration . compilerPath ) ;
350+ }
308351 }
309352
310353 this . updateCompileCommandsFileWatchers ( ) ;
0 commit comments