in Extension/src/LanguageServer/configurations.ts [1198:1324]
private parsePropertiesFile(): boolean {
if (!this.propertiesFile) {
return false;
}
let success: boolean = true;
try {
const readResults: string = fs.readFileSync(this.propertiesFile.fsPath, 'utf8');
if (readResults === "") {
return false; // Repros randomly when the file is initially created. The parse will get called again after the file is written.
}
// Try to use the same configuration as before the change.
const newJson: ConfigurationJson = jsonc.parse(readResults);
if (!newJson || !newJson.configurations || newJson.configurations.length === 0) {
throw { message: localize("invalid.configuration.file", "Invalid configuration file. There must be at least one configuration present in the array.") };
}
if (!this.configurationIncomplete && this.configurationJson && this.configurationJson.configurations &&
this.CurrentConfigurationIndex >= 0 && this.CurrentConfigurationIndex < this.configurationJson.configurations.length) {
for (let i: number = 0; i < newJson.configurations.length; i++) {
if (newJson.configurations[i].name === this.configurationJson.configurations[this.CurrentConfigurationIndex].name) {
if (this.currentConfigurationIndex !== undefined) {
this.currentConfigurationIndex.Value = i;
}
break;
}
}
}
this.configurationJson = newJson;
if (this.CurrentConfigurationIndex < 0 || this.CurrentConfigurationIndex >= newJson.configurations.length) {
const index: number | undefined = this.getConfigIndexForPlatform(newJson);
if (this.currentConfigurationIndex !== undefined) {
if (index === undefined) {
this.currentConfigurationIndex.setDefault();
} else {
this.currentConfigurationIndex.Value = index;
}
}
}
let dirty: boolean = false;
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
const newId: string | undefined = getCustomConfigProviders().checkId(this.configurationJson.configurations[i].configurationProvider);
if (newId !== this.configurationJson.configurations[i].configurationProvider) {
dirty = true;
this.configurationJson.configurations[i].configurationProvider = newId;
}
}
// Remove disallowed variable overrides
if (this.configurationJson.env) {
delete this.configurationJson.env['workspaceRoot'];
delete this.configurationJson.env['workspaceFolder'];
delete this.configurationJson.env['workspaceFolderBasename'];
delete this.configurationJson.env['execPath'];
delete this.configurationJson.env['pathSeparator'];
delete this.configurationJson.env['default'];
}
// Warning: There is a chance that this is incorrect in the event that the c_cpp_properties.json file was created before
// the system includes were available.
this.configurationIncomplete = false;
if (this.configurationJson.version !== configVersion) {
dirty = true;
if (this.configurationJson.version === undefined) {
this.updateToVersion2();
}
if (this.configurationJson.version === 2) {
this.updateToVersion3();
}
if (this.configurationJson.version === 3) {
this.updateToVersion4();
} else {
this.configurationJson.version = configVersion;
vscode.window.showErrorMessage(localize("unknown.properties.version", 'Unknown version number found in c_cpp_properties.json. Some features may not work as expected.'));
}
}
this.configurationJson.configurations.forEach(e => {
if ((<any>e).knownCompilers !== undefined) {
delete (<any>e).knownCompilers;
dirty = true;
}
});
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
if ((this.configurationJson.configurations[i].compilerPathIsExplicit !== undefined)
|| (this.configurationJson.configurations[i].cStandardIsExplicit !== undefined)
|| (this.configurationJson.configurations[i].cppStandardIsExplicit !== undefined)
|| (this.configurationJson.configurations[i].intelliSenseModeIsExplicit !== undefined)) {
dirty = true;
break;
}
}
if (dirty) {
try {
this.writeToJson();
} catch (err) {
// Ignore write errors, the file may be under source control. Updated settings will only be modified in memory.
vscode.window.showWarningMessage(localize('update.properties.failed', 'Attempt to update "{0}" failed (do you have write access?)', this.propertiesFile.fsPath));
success = false;
}
}
this.configurationJson.configurations.forEach(e => {
e.compilerPathIsExplicit = e.compilerPath !== undefined;
e.cStandardIsExplicit = e.cStandard !== undefined;
e.cppStandardIsExplicit = e.cppStandard !== undefined;
e.intelliSenseModeIsExplicit = e.intelliSenseMode !== undefined;
});
} catch (errJS) {
const err: Error = errJS as Error;
const failedToParse: string = localize("failed.to.parse.properties", 'Failed to parse "{0}"', this.propertiesFile.fsPath);
vscode.window.showErrorMessage(`${failedToParse}: ${err.message}`);
success = false;
}
if (success) {
this.handleSquiggles();
}
return success;
}