vscode-json-languageservice 5.7.0 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,6 +10,7 @@ import { SchemaDraft, ErrorCode } from '../jsonLanguageTypes';
|
|
|
10
10
|
import * as l10n from '@vscode/l10n';
|
|
11
11
|
import { createRegex } from '../utils/glob';
|
|
12
12
|
import { isObject, isString } from '../utils/objects';
|
|
13
|
+
import { Range } from 'vscode-languageserver-types';
|
|
13
14
|
const BANG = '!';
|
|
14
15
|
const PATH_SEP = '/';
|
|
15
16
|
class FilePatternAssociation {
|
|
@@ -102,8 +103,12 @@ export class UnresolvedSchema {
|
|
|
102
103
|
this.errors = errors;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
function toDiagnostic(message, code) {
|
|
106
|
-
|
|
106
|
+
function toDiagnostic(message, code, relatedURL) {
|
|
107
|
+
const relatedInformation = relatedURL ? [{
|
|
108
|
+
location: { uri: relatedURL, range: Range.create(0, 0, 0, 0) },
|
|
109
|
+
message
|
|
110
|
+
}] : undefined;
|
|
111
|
+
return { message, code, relatedInformation };
|
|
107
112
|
}
|
|
108
113
|
export class ResolvedSchema {
|
|
109
114
|
constructor(schema, errors = [], warnings = [], schemaDraft) {
|
|
@@ -265,23 +270,23 @@ export class JSONSchemaService {
|
|
|
265
270
|
loadSchema(url) {
|
|
266
271
|
if (!this.requestService) {
|
|
267
272
|
const errorMessage = l10n.t('Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
|
|
268
|
-
return this.promise.resolve(new UnresolvedSchema({}, [toDiagnostic(errorMessage, ErrorCode.SchemaResolveError)]));
|
|
273
|
+
return this.promise.resolve(new UnresolvedSchema({}, [toDiagnostic(errorMessage, ErrorCode.SchemaResolveError, url)]));
|
|
269
274
|
}
|
|
270
275
|
return this.requestService(url).then(content => {
|
|
271
276
|
if (!content) {
|
|
272
277
|
const errorMessage = l10n.t('Unable to load schema from \'{0}\': No content.', toDisplayString(url));
|
|
273
|
-
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, ErrorCode.SchemaResolveError)]);
|
|
278
|
+
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, ErrorCode.SchemaResolveError, url)]);
|
|
274
279
|
}
|
|
275
280
|
const errors = [];
|
|
276
281
|
if (content.charCodeAt(0) === 65279) {
|
|
277
|
-
errors.push(toDiagnostic(l10n.t('Problem reading content from \'{0}\': UTF-8 with BOM detected, only UTF 8 is allowed.', toDisplayString(url)), ErrorCode.SchemaResolveError));
|
|
282
|
+
errors.push(toDiagnostic(l10n.t('Problem reading content from \'{0}\': UTF-8 with BOM detected, only UTF 8 is allowed.', toDisplayString(url)), ErrorCode.SchemaResolveError, url));
|
|
278
283
|
content = content.trimStart();
|
|
279
284
|
}
|
|
280
285
|
let schemaContent = {};
|
|
281
286
|
const jsonErrors = [];
|
|
282
287
|
schemaContent = Json.parse(content, jsonErrors);
|
|
283
288
|
if (jsonErrors.length) {
|
|
284
|
-
errors.push(toDiagnostic(l10n.t('Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset), ErrorCode.SchemaResolveError));
|
|
289
|
+
errors.push(toDiagnostic(l10n.t('Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset), ErrorCode.SchemaResolveError, url));
|
|
285
290
|
}
|
|
286
291
|
return new UnresolvedSchema(schemaContent, errors);
|
|
287
292
|
}, (error) => {
|
|
@@ -303,7 +308,7 @@ export class JSONSchemaService {
|
|
|
303
308
|
errorCode += code;
|
|
304
309
|
}
|
|
305
310
|
const errorMessage = l10n.t('Unable to load schema from \'{0}\': {1}.', toDisplayString(url), message);
|
|
306
|
-
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, errorCode)]);
|
|
311
|
+
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, errorCode, url)]);
|
|
307
312
|
});
|
|
308
313
|
}
|
|
309
314
|
resolveSchemaContent(schemaToResolve, handle) {
|
|
@@ -371,9 +376,10 @@ export class JSONSchemaService {
|
|
|
371
376
|
return referencedHandle.getUnresolvedSchema().then(unresolvedSchema => {
|
|
372
377
|
parentHandle.dependencies.add(uri);
|
|
373
378
|
if (unresolvedSchema.errors.length) {
|
|
379
|
+
const error = unresolvedSchema.errors[0];
|
|
374
380
|
const loc = refSegment ? uri + '#' + refSegment : uri;
|
|
375
|
-
const errorMessage = l10n.t('Problems loading reference \'{0}\': {1}',
|
|
376
|
-
resolveErrors.push(toDiagnostic(errorMessage,
|
|
381
|
+
const errorMessage = refSegment ? l10n.t('Problems loading reference \'{0}\': {1}', refSegment, error.message) : error.message;
|
|
382
|
+
resolveErrors.push(toDiagnostic(errorMessage, error.code, uri));
|
|
377
383
|
}
|
|
378
384
|
mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
|
|
379
385
|
return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
|
|
@@ -37,27 +37,28 @@ export class JSONValidation {
|
|
|
37
37
|
let schemaValidation = documentSettings?.schemaValidation ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
|
|
38
38
|
let schemaRequest = documentSettings?.schemaRequest ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
|
|
39
39
|
if (schema) {
|
|
40
|
-
const addSchemaProblem = (errorMessage, errorCode) => {
|
|
40
|
+
const addSchemaProblem = (errorMessage, errorCode, relatedInformation) => {
|
|
41
41
|
if (jsonDocument.root && schemaRequest) {
|
|
42
42
|
const astRoot = jsonDocument.root;
|
|
43
43
|
const property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
44
44
|
if (property && property.keyNode.value === '$schema') {
|
|
45
45
|
const node = property.valueNode || property;
|
|
46
46
|
const range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
47
|
-
addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
|
|
47
|
+
addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode, 'json', relatedInformation));
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
const range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
51
|
-
addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
|
|
51
|
+
addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode, 'json', relatedInformation));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
if (schema.errors.length) {
|
|
56
|
-
|
|
56
|
+
const error = schema.errors[0];
|
|
57
|
+
addSchemaProblem(error.message, error.code, error.relatedInformation);
|
|
57
58
|
}
|
|
58
59
|
else if (schemaValidation) {
|
|
59
60
|
for (const warning of schema.warnings) {
|
|
60
|
-
addSchemaProblem(warning.message, warning.code);
|
|
61
|
+
addSchemaProblem(warning.message, warning.code, warning.relatedInformation);
|
|
61
62
|
}
|
|
62
63
|
const semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation, documentSettings?.schemaDraft);
|
|
63
64
|
if (semanticErrors) {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
if (v !== undefined) module.exports = v;
|
|
9
9
|
}
|
|
10
10
|
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "jsonc-parser", "vscode-uri", "../utils/strings", "../parser/jsonParser", "../jsonLanguageTypes", "@vscode/l10n", "../utils/glob", "../utils/objects"], factory);
|
|
11
|
+
define(["require", "exports", "jsonc-parser", "vscode-uri", "../utils/strings", "../parser/jsonParser", "../jsonLanguageTypes", "@vscode/l10n", "../utils/glob", "../utils/objects", "vscode-languageserver-types"], factory);
|
|
12
12
|
}
|
|
13
13
|
})(function (require, exports) {
|
|
14
14
|
"use strict";
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
const l10n = require("@vscode/l10n");
|
|
23
23
|
const glob_1 = require("../utils/glob");
|
|
24
24
|
const objects_1 = require("../utils/objects");
|
|
25
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
25
26
|
const BANG = '!';
|
|
26
27
|
const PATH_SEP = '/';
|
|
27
28
|
class FilePatternAssociation {
|
|
@@ -115,8 +116,12 @@
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
exports.UnresolvedSchema = UnresolvedSchema;
|
|
118
|
-
function toDiagnostic(message, code) {
|
|
119
|
-
|
|
119
|
+
function toDiagnostic(message, code, relatedURL) {
|
|
120
|
+
const relatedInformation = relatedURL ? [{
|
|
121
|
+
location: { uri: relatedURL, range: vscode_languageserver_types_1.Range.create(0, 0, 0, 0) },
|
|
122
|
+
message
|
|
123
|
+
}] : undefined;
|
|
124
|
+
return { message, code, relatedInformation };
|
|
120
125
|
}
|
|
121
126
|
class ResolvedSchema {
|
|
122
127
|
constructor(schema, errors = [], warnings = [], schemaDraft) {
|
|
@@ -279,23 +284,23 @@
|
|
|
279
284
|
loadSchema(url) {
|
|
280
285
|
if (!this.requestService) {
|
|
281
286
|
const errorMessage = l10n.t('Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
|
|
282
|
-
return this.promise.resolve(new UnresolvedSchema({}, [toDiagnostic(errorMessage, jsonLanguageTypes_1.ErrorCode.SchemaResolveError)]));
|
|
287
|
+
return this.promise.resolve(new UnresolvedSchema({}, [toDiagnostic(errorMessage, jsonLanguageTypes_1.ErrorCode.SchemaResolveError, url)]));
|
|
283
288
|
}
|
|
284
289
|
return this.requestService(url).then(content => {
|
|
285
290
|
if (!content) {
|
|
286
291
|
const errorMessage = l10n.t('Unable to load schema from \'{0}\': No content.', toDisplayString(url));
|
|
287
|
-
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, jsonLanguageTypes_1.ErrorCode.SchemaResolveError)]);
|
|
292
|
+
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, jsonLanguageTypes_1.ErrorCode.SchemaResolveError, url)]);
|
|
288
293
|
}
|
|
289
294
|
const errors = [];
|
|
290
295
|
if (content.charCodeAt(0) === 65279) {
|
|
291
|
-
errors.push(toDiagnostic(l10n.t('Problem reading content from \'{0}\': UTF-8 with BOM detected, only UTF 8 is allowed.', toDisplayString(url)), jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
|
|
296
|
+
errors.push(toDiagnostic(l10n.t('Problem reading content from \'{0}\': UTF-8 with BOM detected, only UTF 8 is allowed.', toDisplayString(url)), jsonLanguageTypes_1.ErrorCode.SchemaResolveError, url));
|
|
292
297
|
content = content.trimStart();
|
|
293
298
|
}
|
|
294
299
|
let schemaContent = {};
|
|
295
300
|
const jsonErrors = [];
|
|
296
301
|
schemaContent = Json.parse(content, jsonErrors);
|
|
297
302
|
if (jsonErrors.length) {
|
|
298
|
-
errors.push(toDiagnostic(l10n.t('Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset), jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
|
|
303
|
+
errors.push(toDiagnostic(l10n.t('Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset), jsonLanguageTypes_1.ErrorCode.SchemaResolveError, url));
|
|
299
304
|
}
|
|
300
305
|
return new UnresolvedSchema(schemaContent, errors);
|
|
301
306
|
}, (error) => {
|
|
@@ -317,7 +322,7 @@
|
|
|
317
322
|
errorCode += code;
|
|
318
323
|
}
|
|
319
324
|
const errorMessage = l10n.t('Unable to load schema from \'{0}\': {1}.', toDisplayString(url), message);
|
|
320
|
-
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, errorCode)]);
|
|
325
|
+
return new UnresolvedSchema({}, [toDiagnostic(errorMessage, errorCode, url)]);
|
|
321
326
|
});
|
|
322
327
|
}
|
|
323
328
|
resolveSchemaContent(schemaToResolve, handle) {
|
|
@@ -385,9 +390,10 @@
|
|
|
385
390
|
return referencedHandle.getUnresolvedSchema().then(unresolvedSchema => {
|
|
386
391
|
parentHandle.dependencies.add(uri);
|
|
387
392
|
if (unresolvedSchema.errors.length) {
|
|
393
|
+
const error = unresolvedSchema.errors[0];
|
|
388
394
|
const loc = refSegment ? uri + '#' + refSegment : uri;
|
|
389
|
-
const errorMessage = l10n.t('Problems loading reference \'{0}\': {1}',
|
|
390
|
-
resolveErrors.push(toDiagnostic(errorMessage,
|
|
395
|
+
const errorMessage = refSegment ? l10n.t('Problems loading reference \'{0}\': {1}', refSegment, error.message) : error.message;
|
|
396
|
+
resolveErrors.push(toDiagnostic(errorMessage, error.code, uri));
|
|
391
397
|
}
|
|
392
398
|
mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
|
|
393
399
|
return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
|
|
@@ -49,27 +49,28 @@
|
|
|
49
49
|
let schemaValidation = documentSettings?.schemaValidation ? toDiagnosticSeverity(documentSettings.schemaValidation) : jsonLanguageTypes_1.DiagnosticSeverity.Warning;
|
|
50
50
|
let schemaRequest = documentSettings?.schemaRequest ? toDiagnosticSeverity(documentSettings.schemaRequest) : jsonLanguageTypes_1.DiagnosticSeverity.Warning;
|
|
51
51
|
if (schema) {
|
|
52
|
-
const addSchemaProblem = (errorMessage, errorCode) => {
|
|
52
|
+
const addSchemaProblem = (errorMessage, errorCode, relatedInformation) => {
|
|
53
53
|
if (jsonDocument.root && schemaRequest) {
|
|
54
54
|
const astRoot = jsonDocument.root;
|
|
55
55
|
const property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
56
56
|
if (property && property.keyNode.value === '$schema') {
|
|
57
57
|
const node = property.valueNode || property;
|
|
58
58
|
const range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
59
|
-
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
|
|
59
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, errorMessage, schemaRequest, errorCode, 'json', relatedInformation));
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
const range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
63
|
-
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
|
|
63
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, errorMessage, schemaRequest, errorCode, 'json', relatedInformation));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
if (schema.errors.length) {
|
|
68
|
-
|
|
68
|
+
const error = schema.errors[0];
|
|
69
|
+
addSchemaProblem(error.message, error.code, error.relatedInformation);
|
|
69
70
|
}
|
|
70
71
|
else if (schemaValidation) {
|
|
71
72
|
for (const warning of schema.warnings) {
|
|
72
|
-
addSchemaProblem(warning.message, warning.code);
|
|
73
|
+
addSchemaProblem(warning.message, warning.code, warning.relatedInformation);
|
|
73
74
|
}
|
|
74
75
|
const semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation, documentSettings?.schemaDraft);
|
|
75
76
|
if (semanticErrors) {
|