提交 48e81641 编写于 作者: M Martin Aeschlimann

Update json.ts to latest jsonc-parser

上级 3c748fa1
此差异已折叠。
......@@ -5,7 +5,7 @@
'use strict';
import * as assert from 'assert';
import { SyntaxKind, createScanner, parse } from 'vs/base/common/json';
import { SyntaxKind, createScanner, parse, ParseError, getParseErrorMessage } from 'vs/base/common/json';
function assertKinds(text:string, ...kinds:SyntaxKind[]):void {
var _json = createScanner(text);
......@@ -18,17 +18,17 @@ function assertKinds(text:string, ...kinds:SyntaxKind[]):void {
function assertValidParse(input:string, expected:any) : void {
var errors : string[] = [];
var errors : ParseError[] = [];
var actual = parse(input, errors);
if (errors.length !== 0) {
assert(false, errors[0]);
assert(false, getParseErrorMessage(errors[0].error));
}
assert.deepEqual(actual, expected);
}
function assertInvalidParse(input:string, expected:any) : void {
var errors : string[] = [];
var errors : ParseError[] = [];
var actual = parse(input, errors);
assert(errors.length > 0);
......
......@@ -5,7 +5,7 @@
'use strict';
import * as nls from 'vs/nls';
import {parse} from 'vs/base/common/json';
import {parse, ParseError} from 'vs/base/common/json';
import * as paths from 'vs/base/common/paths';
import {TPromise} from 'vs/base/common/winjs.base';
import {readFile} from 'vs/base/node/pfs';
......@@ -23,7 +23,7 @@ export interface ITMSnippetsExtensionPoint {
export function snippetUpdated(modeId: string, filePath: string): TPromise<void> {
return readFile(filePath).then((fileContents) => {
var errors: string[] = [];
var errors: ParseError[] = [];
var snippetsObj = parse(fileContents.toString(), errors);
var adaptedSnippets = TMSnippetsAdaptor.adapt(snippetsObj);
SnippetsRegistry.registerSnippets(modeId, filePath, adaptedSnippets);
......@@ -98,7 +98,7 @@ export class MainProcessTextMateSnippet {
public registerDefinition(modeId: string, filePath: string): void {
readFile(filePath).then((fileContents) => {
var errors: string[] = [];
var errors: ParseError[] = [];
var snippetsObj = parse(fileContents.toString(), errors);
var adaptedSnippets = TMSnippetsAdaptor.adapt(snippetsObj);
SnippetsRegistry.registerDefaultSnippets(modeId, adaptedSnippets);
......
......@@ -342,9 +342,9 @@ export class JSONSchemaService implements IJSONSchemaService {
}
var schemaContent: IJSONSchema = {};
var jsonErrors = [];
schemaContent = Json.parse(content, errors);
var errors = jsonErrors.length ? [ nls.localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), jsonErrors[0])] : [];
var jsonErrors: Json.ParseError[] = [];
schemaContent = Json.parse(content, jsonErrors);
var errors = jsonErrors.length ? [ nls.localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), Json.getParseErrorMessage(jsonErrors[0].error))] : [];
return new UnresolvedSchema(schemaContent, errors);
},
(error : http.IXHRResponse) => {
......
......@@ -898,7 +898,7 @@ export class JSONParser {
if (_scanner.getToken() === Json.SyntaxKind.Unknown) {
// give a more helpful error message
var value = _scanner.getTokenValue();
if (value.length > 0 && (value.charAt(0) === '\'' || Json.isLetter(value.charAt(0).charCodeAt(0)))) {
if (value.match(/^['\w]/)) {
_error(nls.localize('DoubleQuotesExpected', 'Property keys must be doublequoted'));
}
}
......
......@@ -83,11 +83,11 @@ abstract class ExtensionManifestHandler {
class ExtensionManifestParser extends ExtensionManifestHandler {
public parse(): TPromise<IExtensionDescription> {
return pfs.readFile(this._absoluteManifestPath).then((manifestContents) => {
let errors: string[] = [];
let errors: json.ParseError[] = [];
let extensionDescription: IExtensionDescription = json.parse(manifestContents.toString(), errors);
if (errors.length > 0) {
errors.forEach((error) => {
this._collector.error(this._absoluteFolderPath, nls.localize('jsonParseFail', "Failed to parse {0}: {1}.", this._absoluteManifestPath, error));
this._collector.error(this._absoluteFolderPath, nls.localize('jsonParseFail', "Failed to parse {0}: {1}.", this._absoluteManifestPath, json.getParseErrorMessage(error.error)));
});
return null;
}
......@@ -114,11 +114,11 @@ class ExtensionManifestNLSReplacer extends ExtensionManifestHandler {
return extensionDescription;
}
return pfs.readFile(messageBundle).then(messageBundleContent => {
let errors: string[] = [];
let errors: json.ParseError[] = [];
let messages: { [key: string]: string; } = json.parse(messageBundleContent.toString(), errors);
if (errors.length > 0) {
errors.forEach((error) => {
this._collector.error(this._absoluteFolderPath, nls.localize('jsonParseFail', "Failed to parse {0}: {1}.", messageBundle, error));
this._collector.error(this._absoluteFolderPath, nls.localize('jsonParseFail', "Failed to parse {0}: {1}.", messageBundle, json.getParseErrorMessage(error.error)));
});
return extensionDescription;
}
......
......@@ -262,10 +262,10 @@ function applyTheme(theme: IThemeData, onApply: (themeId:string) => void): TProm
function _loadThemeDocument(themePath: string) : TPromise<ThemeDocument> {
return pfs.readFile(themePath).then(content => {
if (Paths.extname(themePath) === '.json') {
let errors: string[] = [];
let errors: Json.ParseError[] = [];
let contentValue = <ThemeDocument> Json.parse(content.toString(), errors);
if (errors.length > 0) {
return TPromise.wrapError(new Error(nls.localize('error.cannotparsejson', "Problems parsing JSON theme file: {0}", errors.join(', '))));
return TPromise.wrapError(new Error(nls.localize('error.cannotparsejson', "Problems parsing JSON theme file: {0}", errors.map(e => Json.getParseErrorMessage(e.error)).join(', '))));
}
if (contentValue.include) {
return _loadThemeDocument(Paths.join(Paths.dirname(themePath), contentValue.include)).then(includedValue => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册