@@ -141,11 +141,14 @@ export class CppProperties {
141
141
console . assert ( rootPath !== undefined ) ;
142
142
this . currentConfigurationIndex = new PersistentFolderState < number > ( "CppProperties.currentConfigurationIndex" , - 1 , rootPath ) ;
143
143
this . configFolder = path . join ( rootPath , ".vscode" ) ;
144
- this . resetToDefaultSettings ( this . currentConfigurationIndex . Value === - 1 ) ;
145
-
144
+
146
145
let configFilePath : string = path . join ( this . configFolder , "c_cpp_properties.json" ) ;
147
146
if ( fs . existsSync ( configFilePath ) ) {
148
147
this . propertiesFile = vscode . Uri . file ( configFilePath ) ;
148
+ this . parsePropertiesFile ( ) ;
149
+ }
150
+ if ( ! this . configurationJson ) {
151
+ this . resetToDefaultSettings ( this . CurrentConfiguration === - 1 ) ;
149
152
}
150
153
151
154
this . configFileWatcher = vscode . workspace . createFileSystemWatcher ( path . join ( this . configFolder , this . configurationGlobPattern ) ) ;
@@ -452,13 +455,27 @@ export class CppProperties {
452
455
// the system includes were available.
453
456
this . configurationIncomplete = false ;
454
457
458
+ // Update intelliSenseMode, compilerPath, cStandard, and cppStandard with the defaults if they're missing.
455
459
let dirty : boolean = false ;
456
460
for ( let i : number = 0 ; i < this . configurationJson . configurations . length ; i ++ ) {
457
461
let config : Configuration = this . configurationJson . configurations [ i ] ;
458
462
if ( config . intelliSenseMode === undefined ) {
459
463
dirty = true ;
460
464
config . intelliSenseMode = this . getIntelliSenseModeForPlatform ( config . name ) ;
461
465
}
466
+ // Don't set the default if compileCommands exist, until it is fixed to have the correct value.
467
+ if ( config . compilerPath === undefined && this . defaultCompilerPath && ! config . compileCommands ) {
468
+ config . compilerPath = this . defaultCompilerPath ;
469
+ dirty = true ;
470
+ }
471
+ if ( ! config . cStandard && this . defaultCStandard ) {
472
+ config . cStandard = this . defaultCStandard ;
473
+ dirty = true ;
474
+ }
475
+ if ( ! config . cppStandard && this . defaultCppStandard ) {
476
+ config . cppStandard = this . defaultCppStandard ;
477
+ dirty = true ;
478
+ }
462
479
}
463
480
464
481
if ( this . configurationJson . version !== configVersion ) {
@@ -475,24 +492,13 @@ export class CppProperties {
475
492
}
476
493
}
477
494
478
- // Update the compilerPath, cStandard, and cppStandard with the default if they're missing.
479
- let config : Configuration = this . configurationJson . configurations [ this . CurrentConfiguration ] ;
480
- // Don't set the default if compileCommands exist, until it is fixed to have the correct value.
481
- if ( config . compilerPath === undefined && this . defaultCompilerPath && ! config . compileCommands ) {
482
- config . compilerPath = this . defaultCompilerPath ;
483
- dirty = true ;
484
- }
485
- if ( ! config . cStandard && this . defaultCStandard ) {
486
- config . cStandard = this . defaultCStandard ;
487
- dirty = true ;
488
- }
489
- if ( ! config . cppStandard && this . defaultCppStandard ) {
490
- config . cppStandard = this . defaultCppStandard ;
491
- dirty = true ;
492
- }
493
-
494
495
if ( dirty ) {
495
- fs . writeFileSync ( this . propertiesFile . fsPath , JSON . stringify ( this . configurationJson , null , 4 ) ) ;
496
+ try {
497
+ fs . writeFileSync ( this . propertiesFile . fsPath , JSON . stringify ( this . configurationJson , null , 4 ) ) ;
498
+ } catch {
499
+ // Ignore write errors, the file may be under source control. Updated settings will only be modified in memory.
500
+ vscode . window . showWarningMessage ( 'Attempt to update "' + this . propertiesFile . fsPath + '" failed (do you have write access?)' ) ;
501
+ }
496
502
}
497
503
} catch ( err ) {
498
504
vscode . window . showErrorMessage ( 'Failed to parse "' + this . propertiesFile . fsPath + '": ' + err . message ) ;
0 commit comments