adopt json.ParseOptions.allowEmptyContent and getNodeType

This commit is contained in:
Martin Aeschlimann
2019-10-25 08:58:51 +02:00
parent db5a09cdcb
commit ce9f8e1c94
14 changed files with 61 additions and 33 deletions
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { ParseError, parse } from 'vs/base/common/json';
import { ParseError, parse, getNodeType } from 'vs/base/common/json';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import * as types from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
@@ -91,10 +91,14 @@ export class LanguageConfigurationFileHandler {
private _handleConfigFile(languageIdentifier: LanguageIdentifier, configFileLocation: URI): void {
this._fileService.readFile(configFileLocation).then((contents) => {
const errors: ParseError[] = [];
const configuration = <ILanguageConfiguration>parse(contents.value.toString(), errors);
let configuration = <ILanguageConfiguration>parse(contents.value.toString(), errors);
if (errors.length) {
console.error(nls.localize('parseErrors', "Errors parsing {0}: {1}", configFileLocation.toString(), errors.map(e => (`[${e.offset}, ${e.length}] ${getParseErrorMessage(e.error)}`)).join('\n')));
}
if (getNodeType(configuration) !== 'object') {
console.error(nls.localize('formatError', "{0}: Invalid format, JSON object expected.", configFileLocation.toString()));
configuration = {};
}
this._handleConfig(languageIdentifier, configuration);
}, (err) => {
console.error(err);