@@ -15,6 +15,8 @@ import { ABTestSettings, getABTestSettings } from '../abTesting';
1515import { getCustomConfigProviders } from './customProviders' ;
1616const configVersion :number = 4 ;
1717
18+ type Environment = { [ key :string ] :string | string [ ] } ;
19+
1820// No properties are set in the config since we want to apply vscode settings first (if applicable).
1921// That code won't trigger if another value is already set.
2022// The property defaults are moved down to applyDefaultIncludePathsAndFrameworks.
@@ -202,7 +204,6 @@ export class CppProperties {
202204
203205private resetToDefaultSettings ( resetIndex :boolean ) :void {
204206this . configurationJson = getDefaultCppProperties ( ) ;
205- this . extendConfigurationEnvironment ( ) ;
206207if ( resetIndex || this . CurrentConfigurationIndex < 0 ||
207208this . CurrentConfigurationIndex >= this . configurationJson . configurations . length ) {
208209this . currentConfigurationIndex . Value = this . getConfigIndexForPlatform ( this . configurationJson ) ;
@@ -253,12 +254,14 @@ export class CppProperties {
253254}
254255}
255256
256- private extendConfigurationEnvironment ( ) :void {
257- if ( ! this . configurationJson . env ) {
258- this . configurationJson . env = { } ;
257+ private get ExtendedEnvironment ( ) :Environment {
258+ let result :Environment = { } ;
259+ if ( this . configurationJson . env ) {
260+ Object . assign ( result , this . configurationJson . env ) ;
259261}
260262
261- this . configurationJson . env [ "workspaceFolderBasename" ] = path . basename ( this . rootUri . fsPath ) ;
263+ result [ "workspaceFolderBasename" ] = path . basename ( this . rootUri . fsPath ) ;
264+ return result ;
262265}
263266
264267private async buildVcpkgIncludePath ( ) :Promise < void > {
@@ -402,62 +405,63 @@ export class CppProperties {
402405return result ;
403406}
404407
405- private resolveAndSplit ( paths :string [ ] | undefined , defaultValue :string [ ] ) :string [ ] {
408+ private resolveAndSplit ( paths :string [ ] | undefined , defaultValue :string [ ] , env : Environment ) :string [ ] {
406409let result :string [ ] = [ ] ;
407410if ( paths ) {
408411paths . forEach ( entry => {
409- let entries :string [ ] = util . resolveVariables ( entry , this . configurationJson . env ) . split ( ";" ) . filter ( e => e ) ;
412+ let entries :string [ ] = util . resolveVariables ( entry , env ) . split ( ";" ) . filter ( e => e ) ;
410413entries = this . resolveDefaults ( entries , defaultValue ) ;
411414result = result . concat ( entries ) ;
412415} ) ;
413416}
414417return result ;
415418}
416419
417- private resolveVariables ( input :string | boolean , defaultValue :string | boolean ) :string | boolean {
420+ private resolveVariables ( input :string | boolean , defaultValue :string | boolean , env : Environment ) :string | boolean {
418421if ( input === undefined || input === "${default}" ) {
419422input = defaultValue ;
420423}
421424if ( typeof input === "boolean" ) {
422425return input ;
423426}
424- return util . resolveVariables ( input , this . configurationJson . env ) ;
427+ return util . resolveVariables ( input , env ) ;
425428}
426429
427- private updateConfiguration ( property :string [ ] , defaultValue :string [ ] ) :string [ ] ;
428- private updateConfiguration ( property :string , defaultValue :string ) :string ;
429- private updateConfiguration ( property :string | boolean , defaultValue :boolean ) :boolean ;
430- private updateConfiguration ( property , defaultValue ) :any {
430+ private updateConfiguration ( property :string [ ] , defaultValue :string [ ] , env : Environment ) :string [ ] ;
431+ private updateConfiguration ( property :string , defaultValue :string , env : Environment ) :string ;
432+ private updateConfiguration ( property :string | boolean , defaultValue :boolean , env : Environment ) :boolean ;
433+ private updateConfiguration ( property , defaultValue , env ) :any {
431434if ( typeof property === "string" || typeof defaultValue === "string" ) {
432- return this . resolveVariables ( property , defaultValue ) ;
435+ return this . resolveVariables ( property , defaultValue , env ) ;
433436} else if ( typeof property === "boolean" || typeof defaultValue === "boolean" ) {
434- return this . resolveVariables ( property , defaultValue ) ;
437+ return this . resolveVariables ( property , defaultValue , env ) ;
435438} else if ( property instanceof Array || defaultValue instanceof Array ) {
436439if ( property ) {
437- return this . resolveAndSplit ( property , defaultValue ) ;
440+ return this . resolveAndSplit ( property , defaultValue , env ) ;
438441} else if ( property === undefined && defaultValue ) {
439- return this . resolveAndSplit ( defaultValue , [ ] ) ;
442+ return this . resolveAndSplit ( defaultValue , [ ] , env ) ;
440443}
441444}
442445return property ;
443446}
444447
445448private updateServerOnFolderSettingsChange ( ) :void {
446449let settings :CppSettings = new CppSettings ( this . rootUri ) ;
450+ let env :Environment = this . ExtendedEnvironment ;
447451for ( let i :number = 0 ; i < this . configurationJson . configurations . length ; i ++ ) {
448452let configuration :Configuration = this . configurationJson . configurations [ i ] ;
449453
450- configuration . includePath = this . updateConfiguration ( configuration . includePath , settings . defaultIncludePath ) ;
451- configuration . defines = this . updateConfiguration ( configuration . defines , settings . defaultDefines ) ;
452- configuration . macFrameworkPath = this . updateConfiguration ( configuration . macFrameworkPath , settings . defaultMacFrameworkPath ) ;
453- configuration . windowsSdkVersion = this . updateConfiguration ( configuration . windowsSdkVersion , settings . defaultWindowsSdkVersion ) ;
454- configuration . forcedInclude = this . updateConfiguration ( configuration . forcedInclude , settings . defaultForcedInclude ) ;
455- configuration . compileCommands = this . updateConfiguration ( configuration . compileCommands , settings . defaultCompileCommands ) ;
456- configuration . compilerPath = this . updateConfiguration ( configuration . compilerPath , settings . defaultCompilerPath ) ;
457- configuration . cStandard = this . updateConfiguration ( configuration . cStandard , settings . defaultCStandard ) ;
458- configuration . cppStandard = this . updateConfiguration ( configuration . cppStandard , settings . defaultCppStandard ) ;
459- configuration . intelliSenseMode = this . updateConfiguration ( configuration . intelliSenseMode , settings . defaultIntelliSenseMode ) ;
460- configuration . configurationProvider = this . updateConfiguration ( configuration . configurationProvider , settings . defaultConfigurationProvider ) ;
454+ configuration . includePath = this . updateConfiguration ( configuration . includePath , settings . defaultIncludePath , env ) ;
455+ configuration . defines = this . updateConfiguration ( configuration . defines , settings . defaultDefines , env ) ;
456+ configuration . macFrameworkPath = this . updateConfiguration ( configuration . macFrameworkPath , settings . defaultMacFrameworkPath , env ) ;
457+ configuration . windowsSdkVersion = this . updateConfiguration ( configuration . windowsSdkVersion , settings . defaultWindowsSdkVersion , env ) ;
458+ configuration . forcedInclude = this . updateConfiguration ( configuration . forcedInclude , settings . defaultForcedInclude , env ) ;
459+ configuration . compileCommands = this . updateConfiguration ( configuration . compileCommands , settings . defaultCompileCommands , env ) ;
460+ configuration . compilerPath = this . updateConfiguration ( configuration . compilerPath , settings . defaultCompilerPath , env ) ;
461+ configuration . cStandard = this . updateConfiguration ( configuration . cStandard , settings . defaultCStandard , env ) ;
462+ configuration . cppStandard = this . updateConfiguration ( configuration . cppStandard , settings . defaultCppStandard , env ) ;
463+ configuration . intelliSenseMode = this . updateConfiguration ( configuration . intelliSenseMode , settings . defaultIntelliSenseMode , env ) ;
464+ configuration . configurationProvider = this . updateConfiguration ( configuration . configurationProvider , settings . defaultConfigurationProvider , env ) ;
461465
462466if ( ! configuration . browse ) {
463467configuration . browse = { } ;
@@ -476,11 +480,11 @@ export class CppProperties {
476480}
477481}
478482} else {
479- configuration . browse . path = this . updateConfiguration ( configuration . browse . path , settings . defaultBrowsePath ) ;
483+ configuration . browse . path = this . updateConfiguration ( configuration . browse . path , settings . defaultBrowsePath , env ) ;
480484}
481485
482- configuration . browse . limitSymbolsToIncludedHeaders = this . updateConfiguration ( configuration . browse . limitSymbolsToIncludedHeaders , settings . defaultLimitSymbolsToIncludedHeaders ) ;
483- configuration . browse . databaseFilename = this . updateConfiguration ( configuration . browse . databaseFilename , settings . defaultDatabaseFilename ) ;
486+ configuration . browse . limitSymbolsToIncludedHeaders = this . updateConfiguration ( configuration . browse . limitSymbolsToIncludedHeaders , settings . defaultLimitSymbolsToIncludedHeaders , env ) ;
487+ configuration . browse . databaseFilename = this . updateConfiguration ( configuration . browse . databaseFilename , settings . defaultDatabaseFilename , env ) ;
484488}
485489
486490this . updateCompileCommandsFileWatchers ( ) ;
@@ -619,11 +623,10 @@ export class CppProperties {
619623if ( this . configurationJson . env ) {
620624delete this . configurationJson . env [ 'workspaceRoot' ] ;
621625delete this . configurationJson . env [ 'workspaceFolder' ] ;
626+ delete this . configurationJson . env [ 'workspaceFolderBasename' ] ;
622627delete this . configurationJson . env [ 'default' ] ;
623628}
624629
625- this . extendConfigurationEnvironment ( ) ;
626-
627630// Warning: There is a chance that this is incorrect in the event that the c_cpp_properties.json file was created before
628631// the system includes were available.
629632this . configurationIncomplete = false ;