Skip to content

Commit

Permalink
Allow comments in c_cpp_properties.json (use JSONC) (#5888)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms authored Aug 4, 2020
1 parent 5dce553 commit 3017c5e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getCustomConfigProviders } from './customProviders';
import { SettingsPanel } from './settingsPanel';
import * as os from 'os';
import escapeStringRegExp = require('escape-string-regexp');
import * as jsonc from 'jsonc-parser';
import * as nls from 'vscode-nls';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
Expand Down Expand Up @@ -959,7 +960,7 @@ export class CppProperties {
}

// Try to use the same configuration as before the change.
const newJson: ConfigurationJson = JSON.parse(readResults);
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.") };
}
Expand Down Expand Up @@ -1276,7 +1277,7 @@ export class CppProperties {
// Replace all \<escape character> with \\<character>, except for \"
// Otherwise, the JSON.parse result will have the \<escape character> missing.
const configurationsText: string = util.escapeForSquiggles(curText);
const configurations: ConfigurationJson = JSON.parse(configurationsText);
const configurations: ConfigurationJson = jsonc.parse(configurationsText);
const currentConfiguration: Configuration = configurations.configurations[this.CurrentConfigurationIndex];

let curTextStartOffset: number = 0;
Expand Down

0 comments on commit 3017c5e

Please sign in to comment.