Skip to content

Commit

Permalink
Address config issues: #1599, #1790 (#1807)
Browse files Browse the repository at this point in the history
* addresses #1599, #1790

* Update all configs when c_cpp_properties.json is parsed
  • Loading branch information
bobbrow authored Apr 10, 2018
1 parent 7cff0f1 commit e2b5bf9
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ export class CppProperties {
console.assert(rootPath !== undefined);
this.currentConfigurationIndex = new PersistentFolderState<number>("CppProperties.currentConfigurationIndex", -1, rootPath);
this.configFolder = path.join(rootPath, ".vscode");
this.resetToDefaultSettings(this.currentConfigurationIndex.Value === -1);


let configFilePath: string = path.join(this.configFolder, "c_cpp_properties.json");
if (fs.existsSync(configFilePath)) {
this.propertiesFile = vscode.Uri.file(configFilePath);
this.parsePropertiesFile();
}
if (!this.configurationJson) {
this.resetToDefaultSettings(this.CurrentConfiguration === -1);
}

this.configFileWatcher = vscode.workspace.createFileSystemWatcher(path.join(this.configFolder, this.configurationGlobPattern));
Expand Down Expand Up @@ -452,13 +455,27 @@ export class CppProperties {
// the system includes were available.
this.configurationIncomplete = false;

// Update intelliSenseMode, compilerPath, cStandard, and cppStandard with the defaults if they're missing.
let dirty: boolean = false;
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
let config: Configuration = this.configurationJson.configurations[i];
if (config.intelliSenseMode === undefined) {
dirty = true;
config.intelliSenseMode = this.getIntelliSenseModeForPlatform(config.name);
}
// Don't set the default if compileCommands exist, until it is fixed to have the correct value.
if (config.compilerPath === undefined && this.defaultCompilerPath && !config.compileCommands) {
config.compilerPath = this.defaultCompilerPath;
dirty = true;
}
if (!config.cStandard && this.defaultCStandard) {
config.cStandard = this.defaultCStandard;
dirty = true;
}
if (!config.cppStandard && this.defaultCppStandard) {
config.cppStandard = this.defaultCppStandard;
dirty = true;
}
}

if (this.configurationJson.version !== configVersion) {
Expand All @@ -475,24 +492,13 @@ export class CppProperties {
}
}

// Update the compilerPath, cStandard, and cppStandard with the default if they're missing.
let config: Configuration = this.configurationJson.configurations[this.CurrentConfiguration];
// Don't set the default if compileCommands exist, until it is fixed to have the correct value.
if (config.compilerPath === undefined && this.defaultCompilerPath && !config.compileCommands) {
config.compilerPath = this.defaultCompilerPath;
dirty = true;
}
if (!config.cStandard && this.defaultCStandard) {
config.cStandard = this.defaultCStandard;
dirty = true;
}
if (!config.cppStandard && this.defaultCppStandard) {
config.cppStandard = this.defaultCppStandard;
dirty = true;
}

if (dirty) {
fs.writeFileSync(this.propertiesFile.fsPath, JSON.stringify(this.configurationJson, null, 4));
try {
fs.writeFileSync(this.propertiesFile.fsPath, JSON.stringify(this.configurationJson, null, 4));
} catch {
// Ignore write errors, the file may be under source control. Updated settings will only be modified in memory.
vscode.window.showWarningMessage('Attempt to update "' + this.propertiesFile.fsPath + '" failed (do you have write access?)');
}
}
} catch (err) {
vscode.window.showErrorMessage('Failed to parse "' + this.propertiesFile.fsPath + '": ' + err.message);
Expand Down

0 comments on commit e2b5bf9

Please sign in to comment.