@@ -363,8 +363,8 @@ export class CppProperties {
363363 public onDidChangeSettings ( ) : void {
364364 // Default settings may have changed in a way that affects the configuration.
365365 // Just send another message since the language server will sort out whether anything important changed or not.
366- if ( ! this . propertiesFile ) {
367- this . resetToDefaultSettings ( true ) ;
366+ const settings : CppSettings = new CppSettings ( this . rootUri ) ;
367+ if ( ! this . propertiesFile || ( settings . configurations && settings . configurations . length > 0 ) ) {
368368 this . handleConfigurationChange ( ) ;
369369 } else if ( ! this . configurationIncomplete ) {
370370 this . handleConfigurationChange ( ) ;
@@ -1370,7 +1370,8 @@ export class CppProperties {
13701370 }
13711371
13721372 public handleConfigurationChange ( ) : void {
1373- if ( this . propertiesFile === undefined ) {
1373+ const settings : CppSettings = new CppSettings ( this . rootUri ) ;
1374+ if ( this . propertiesFile === undefined && ( ! settings . configurations || settings . configurations . length === 0 ) ) {
13741375 return ; // Occurs when propertiesFile hasn't been checked yet.
13751376 }
13761377 this . configFileWatcherFallbackTime = new Date ( ) ;
@@ -1452,24 +1453,46 @@ export class CppProperties {
14521453 }
14531454
14541455 private parsePropertiesFile ( ) : boolean {
1455- if ( ! this . propertiesFile ) {
1456- this . configurationJson = undefined ;
1457- return false ;
1458- }
1456+ const settings : CppSettings = new CppSettings ( this . rootUri ) ;
1457+ const settingsConfigs : any [ ] | undefined = settings . configurations ;
1458+
14591459 let success : boolean = true ;
14601460 const firstParse = this . configurationJson === undefined ;
1461- try {
1462- const readResults : string = fs . readFileSync ( this . propertiesFile . fsPath , 'utf8' ) ;
1463- if ( readResults === "" ) {
1464- return false ; // Repros randomly when the file is initially created. The parse will get called again after the file is written.
1461+
1462+ let newJson : ConfigurationJson | undefined ;
1463+ if ( settingsConfigs && settingsConfigs . length > 0 ) {
1464+ newJson = {
1465+ configurations : settingsConfigs as Configuration [ ] ,
1466+ version : configVersion
1467+ } ;
1468+ } else {
1469+ if ( ! this . propertiesFile ) {
1470+ this . configurationJson = undefined ;
1471+ return false ;
14651472 }
1473+ try {
1474+ const readResults : string = fs . readFileSync ( this . propertiesFile . fsPath , 'utf8' ) ;
1475+ if ( readResults === "" ) {
1476+ return false ; // Repros randomly when the file is initially created. The parse will get called again after the file is written.
1477+ }
14661478
1467- // Try to use the same configuration as before the change.
1468- // TODO?: Handle when jsonc.parse() throws an exception due to invalid JSON contents.
1469- const newJson : ConfigurationJson = jsonc . parse ( readResults , undefined , true ) as any ;
1470- if ( ! newJson || ! newJson . configurations || newJson . configurations . length === 0 ) {
1479+ // Try to use the same configuration as before the change.
1480+ // TODO?: Handle when jsonc.parse() throws an exception due to invalid JSON contents.
1481+ newJson = jsonc . parse ( readResults , undefined , true ) as any ;
1482+ } catch ( err ) {
1483+ this . configurationJson = undefined ;
1484+ success = false ;
1485+ }
1486+ }
1487+
1488+ if ( ! newJson || ! newJson . configurations || newJson . configurations . length === 0 ) {
1489+ if ( settingsConfigs && settingsConfigs . length > 0 ) {
1490+ // If we tried to parse from settings and it was invalid, we should probably log an error.
1491+ } else if ( this . propertiesFile ) {
14711492 throw { message : localize ( "invalid.configuration.file" , "Invalid configuration file. There must be at least one configuration present in the array." ) } ;
14721493 }
1494+ return false ;
1495+ }
14731496 if ( ! this . configurationIncomplete && this . configurationJson && this . configurationJson . configurations &&
14741497 this . CurrentConfigurationIndex >= 0 && this . CurrentConfigurationIndex < this . configurationJson . configurations . length ) {
14751498 for ( let i : number = 0 ; i < newJson . configurations . length ; i ++ ) {
0 commit comments