vscode-json-languageservice 5.6.4 → 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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 5.7.0 / 2026-01-12
2
+ ================
3
+ * the error code for `SchemaResolveError` is now 0x10000 plus the error code returned by the request service.
4
+
1
5
  5.6.0 / 2025-05-28
2
6
  ================
3
7
  * added `Schema.enumSortTexts` and `Schema.enumDetails` to control the sort order and presentation of suggestions for enums
@@ -26,9 +26,10 @@ export declare enum ErrorCode {
26
26
  DuplicateKey = 520,
27
27
  CommentNotPermitted = 521,
28
28
  PropertyKeysMustBeDoublequoted = 528,
29
- SchemaResolveError = 768,
30
- SchemaUnsupportedFeature = 769
29
+ SchemaUnsupportedFeature = 769,
30
+ SchemaResolveError = 65536
31
31
  }
32
+ export declare function isSchemaResolveError(code: number): boolean;
32
33
  export type ASTNode = ObjectASTNode | PropertyASTNode | ArrayASTNode | StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode;
33
34
  export interface BaseASTNode {
34
35
  readonly type: 'object' | 'array' | 'property' | 'string' | 'number' | 'boolean' | 'null';
@@ -153,7 +154,8 @@ export interface WorkspaceContextService {
153
154
  }
154
155
  /**
155
156
  * The schema request service is used to fetch schemas. If successful, returns a resolved promise with the content of the schema.
156
- * In case of an error, returns a rejected promise with a displayable error string.
157
+ * In case of an error, returns a rejected promise with an Error object. If the type is of form { message: string, code: number }, the
158
+ * error code will be used for diagnostics.
157
159
  */
158
160
  export interface SchemaRequestService {
159
161
  (uri: string): PromiseLike<string>;
@@ -29,9 +29,12 @@ export var ErrorCode;
29
29
  ErrorCode[ErrorCode["DuplicateKey"] = 520] = "DuplicateKey";
30
30
  ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
31
31
  ErrorCode[ErrorCode["PropertyKeysMustBeDoublequoted"] = 528] = "PropertyKeysMustBeDoublequoted";
32
- ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
33
32
  ErrorCode[ErrorCode["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
33
+ ErrorCode[ErrorCode["SchemaResolveError"] = 65536] = "SchemaResolveError";
34
34
  })(ErrorCode || (ErrorCode = {}));
35
+ export function isSchemaResolveError(code) {
36
+ return code >= ErrorCode.SchemaResolveError;
37
+ }
35
38
  export var SchemaDraft;
36
39
  (function (SchemaDraft) {
37
40
  SchemaDraft[SchemaDraft["v3"] = 3] = "v3";
@@ -6,10 +6,11 @@ import * as Json from 'jsonc-parser';
6
6
  import { URI } from 'vscode-uri';
7
7
  import * as Strings from '../utils/strings';
8
8
  import { asSchema, getSchemaDraftFromId, normalizeId } from '../parser/jsonParser';
9
- import { SchemaDraft } from '../jsonLanguageTypes';
9
+ 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,6 +103,13 @@ export class UnresolvedSchema {
102
103
  this.errors = errors;
103
104
  }
104
105
  }
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 };
112
+ }
105
113
  export class ResolvedSchema {
106
114
  constructor(schema, errors = [], warnings = [], schemaDraft) {
107
115
  this.schema = schema;
@@ -262,36 +270,45 @@ export class JSONSchemaService {
262
270
  loadSchema(url) {
263
271
  if (!this.requestService) {
264
272
  const errorMessage = l10n.t('Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
265
- return this.promise.resolve(new UnresolvedSchema({}, [errorMessage]));
273
+ return this.promise.resolve(new UnresolvedSchema({}, [toDiagnostic(errorMessage, ErrorCode.SchemaResolveError, url)]));
266
274
  }
267
275
  return this.requestService(url).then(content => {
268
276
  if (!content) {
269
277
  const errorMessage = l10n.t('Unable to load schema from \'{0}\': No content.', toDisplayString(url));
270
- return new UnresolvedSchema({}, [errorMessage]);
278
+ return new UnresolvedSchema({}, [toDiagnostic(errorMessage, ErrorCode.SchemaResolveError, url)]);
271
279
  }
272
280
  const errors = [];
273
281
  if (content.charCodeAt(0) === 65279) {
274
- errors.push(l10n.t('Problem reading content from \'{0}\': UTF-8 with BOM detected, only UTF 8 is allowed.', toDisplayString(url)));
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));
275
283
  content = content.trimStart();
276
284
  }
277
285
  let schemaContent = {};
278
286
  const jsonErrors = [];
279
287
  schemaContent = Json.parse(content, jsonErrors);
280
288
  if (jsonErrors.length) {
281
- errors.push(l10n.t('Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset));
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));
282
290
  }
283
291
  return new UnresolvedSchema(schemaContent, errors);
284
292
  }, (error) => {
285
- let errorMessage = error.toString();
286
- const errorSplit = error.toString().split('Error: ');
287
- if (errorSplit.length > 1) {
288
- // more concise error message, URL and context are attached by caller anyways
289
- errorMessage = errorSplit[1];
293
+ let { message, code } = error;
294
+ if (typeof message !== 'string') {
295
+ let errorMessage = error.toString();
296
+ const errorSplit = error.toString().split('Error: ');
297
+ if (errorSplit.length > 1) {
298
+ // more concise error message, URL and context are attached by caller anyways
299
+ errorMessage = errorSplit[1];
300
+ }
301
+ if (Strings.endsWith(errorMessage, '.')) {
302
+ errorMessage = errorMessage.substr(0, errorMessage.length - 1);
303
+ }
304
+ message = errorMessage;
290
305
  }
291
- if (Strings.endsWith(errorMessage, '.')) {
292
- errorMessage = errorMessage.substr(0, errorMessage.length - 1);
306
+ let errorCode = ErrorCode.SchemaResolveError;
307
+ if (typeof code === 'number' && code < 0x10000) {
308
+ errorCode += code;
293
309
  }
294
- return new UnresolvedSchema({}, [l10n.t('Unable to load schema from \'{0}\': {1}.', toDisplayString(url), errorMessage)]);
310
+ const errorMessage = l10n.t('Unable to load schema from \'{0}\': {1}.', toDisplayString(url), message);
311
+ return new UnresolvedSchema({}, [toDiagnostic(errorMessage, errorCode, url)]);
295
312
  });
296
313
  }
297
314
  resolveSchemaContent(schemaToResolve, handle) {
@@ -299,7 +316,7 @@ export class JSONSchemaService {
299
316
  const schema = schemaToResolve.schema;
300
317
  const schemaDraft = schema.$schema ? getSchemaDraftFromId(schema.$schema) : undefined;
301
318
  if (schemaDraft === SchemaDraft.v3) {
302
- return this.promise.resolve(new ResolvedSchema({}, [l10n.t("Draft-03 schemas are not supported.")], [], schemaDraft));
319
+ return this.promise.resolve(new ResolvedSchema({}, [toDiagnostic(l10n.t("Draft-03 schemas are not supported."), ErrorCode.SchemaUnsupportedFeature)], [], schemaDraft));
303
320
  }
304
321
  let usesUnsupportedFeatures = new Set();
305
322
  const contextService = this.contextService;
@@ -346,7 +363,8 @@ export class JSONSchemaService {
346
363
  merge(target, section);
347
364
  }
348
365
  else {
349
- resolveErrors.push(l10n.t('$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment || '', sourceHandle.uri));
366
+ const message = l10n.t('$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment || '', sourceHandle.uri);
367
+ resolveErrors.push(toDiagnostic(message, ErrorCode.SchemaResolveError));
350
368
  }
351
369
  };
352
370
  const resolveExternalLink = (node, uri, refSegment, parentHandle) => {
@@ -358,8 +376,10 @@ export class JSONSchemaService {
358
376
  return referencedHandle.getUnresolvedSchema().then(unresolvedSchema => {
359
377
  parentHandle.dependencies.add(uri);
360
378
  if (unresolvedSchema.errors.length) {
379
+ const error = unresolvedSchema.errors[0];
361
380
  const loc = refSegment ? uri + '#' + refSegment : uri;
362
- resolveErrors.push(l10n.t('Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
381
+ const errorMessage = refSegment ? l10n.t('Problems loading reference \'{0}\': {1}', refSegment, error.message) : error.message;
382
+ resolveErrors.push(toDiagnostic(errorMessage, error.code, uri));
363
383
  }
364
384
  mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
365
385
  return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
@@ -403,7 +423,7 @@ export class JSONSchemaService {
403
423
  const anchor = isString(id) && id.charAt(0) === '#' ? id.substring(1) : next.$anchor;
404
424
  if (anchor) {
405
425
  if (result.has(anchor)) {
406
- resolveErrors.push(l10n.t('Duplicate anchor declaration: \'{0}\'', anchor));
426
+ resolveErrors.push(toDiagnostic(l10n.t('Duplicate anchor declaration: \'{0}\'', anchor), ErrorCode.SchemaResolveError));
407
427
  }
408
428
  else {
409
429
  result.set(anchor, next);
@@ -421,7 +441,7 @@ export class JSONSchemaService {
421
441
  return resolveRefs(schema, schema, handle).then(_ => {
422
442
  let resolveWarnings = [];
423
443
  if (usesUnsupportedFeatures.size) {
424
- resolveWarnings.push(l10n.t('The schema uses meta-schema features ({0}) that are not yet supported by the validator.', Array.from(usesUnsupportedFeatures.keys()).join(', ')));
444
+ resolveWarnings.push(toDiagnostic(l10n.t('The schema uses meta-schema features ({0}) that are not yet supported by the validator.', Array.from(usesUnsupportedFeatures.keys()).join(', ')), ErrorCode.SchemaUnsupportedFeature));
425
445
  }
426
446
  return new ResolvedSchema(schema, resolveErrors, resolveWarnings, schemaDraft);
427
447
  });
@@ -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
- addSchemaProblem(schema.errors[0], ErrorCode.SchemaResolveError);
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, ErrorCode.SchemaUnsupportedFeature);
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) {
@@ -26,9 +26,10 @@ export declare enum ErrorCode {
26
26
  DuplicateKey = 520,
27
27
  CommentNotPermitted = 521,
28
28
  PropertyKeysMustBeDoublequoted = 528,
29
- SchemaResolveError = 768,
30
- SchemaUnsupportedFeature = 769
29
+ SchemaUnsupportedFeature = 769,
30
+ SchemaResolveError = 65536
31
31
  }
32
+ export declare function isSchemaResolveError(code: number): boolean;
32
33
  export type ASTNode = ObjectASTNode | PropertyASTNode | ArrayASTNode | StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode;
33
34
  export interface BaseASTNode {
34
35
  readonly type: 'object' | 'array' | 'property' | 'string' | 'number' | 'boolean' | 'null';
@@ -153,7 +154,8 @@ export interface WorkspaceContextService {
153
154
  }
154
155
  /**
155
156
  * The schema request service is used to fetch schemas. If successful, returns a resolved promise with the content of the schema.
156
- * In case of an error, returns a rejected promise with a displayable error string.
157
+ * In case of an error, returns a rejected promise with an Error object. If the type is of form { message: string, code: number }, the
158
+ * error code will be used for diagnostics.
157
159
  */
158
160
  export interface SchemaRequestService {
159
161
  (uri: string): PromiseLike<string>;
@@ -14,6 +14,7 @@
14
14
  "use strict";
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ClientCapabilities = exports.SchemaDraft = exports.ErrorCode = exports.DocumentHighlightKind = exports.VersionedTextDocumentIdentifier = exports.TextDocumentEdit = exports.CodeActionKind = exports.TextEdit = exports.WorkspaceEdit = exports.DocumentLink = exports.DocumentHighlight = exports.CodeAction = exports.Command = exports.CodeActionContext = exports.MarkedString = exports.Hover = exports.Location = exports.DocumentSymbol = exports.SymbolKind = exports.SymbolInformation = exports.InsertTextFormat = exports.CompletionItemTag = exports.CompletionList = exports.CompletionItemKind = exports.CompletionItem = exports.DiagnosticSeverity = exports.Diagnostic = exports.SelectionRange = exports.FoldingRangeKind = exports.FoldingRange = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.MarkupKind = exports.MarkupContent = exports.DocumentUri = exports.Position = exports.Range = exports.TextDocument = void 0;
17
+ exports.isSchemaResolveError = isSchemaResolveError;
17
18
  const vscode_languageserver_types_1 = require("vscode-languageserver-types");
18
19
  Object.defineProperty(exports, "Range", { enumerable: true, get: function () { return vscode_languageserver_types_1.Range; } });
19
20
  Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return vscode_languageserver_types_1.Position; } });
@@ -76,9 +77,12 @@
76
77
  ErrorCode[ErrorCode["DuplicateKey"] = 520] = "DuplicateKey";
77
78
  ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
78
79
  ErrorCode[ErrorCode["PropertyKeysMustBeDoublequoted"] = 528] = "PropertyKeysMustBeDoublequoted";
79
- ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
80
80
  ErrorCode[ErrorCode["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
81
+ ErrorCode[ErrorCode["SchemaResolveError"] = 65536] = "SchemaResolveError";
81
82
  })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
83
+ function isSchemaResolveError(code) {
84
+ return code >= ErrorCode.SchemaResolveError;
85
+ }
82
86
  var SchemaDraft;
83
87
  (function (SchemaDraft) {
84
88
  SchemaDraft[SchemaDraft["v3"] = 3] = "v3";
@@ -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,6 +116,13 @@
115
116
  }
116
117
  }
117
118
  exports.UnresolvedSchema = UnresolvedSchema;
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 };
125
+ }
118
126
  class ResolvedSchema {
119
127
  constructor(schema, errors = [], warnings = [], schemaDraft) {
120
128
  this.schema = schema;
@@ -276,36 +284,45 @@
276
284
  loadSchema(url) {
277
285
  if (!this.requestService) {
278
286
  const errorMessage = l10n.t('Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
279
- return this.promise.resolve(new UnresolvedSchema({}, [errorMessage]));
287
+ return this.promise.resolve(new UnresolvedSchema({}, [toDiagnostic(errorMessage, jsonLanguageTypes_1.ErrorCode.SchemaResolveError, url)]));
280
288
  }
281
289
  return this.requestService(url).then(content => {
282
290
  if (!content) {
283
291
  const errorMessage = l10n.t('Unable to load schema from \'{0}\': No content.', toDisplayString(url));
284
- return new UnresolvedSchema({}, [errorMessage]);
292
+ return new UnresolvedSchema({}, [toDiagnostic(errorMessage, jsonLanguageTypes_1.ErrorCode.SchemaResolveError, url)]);
285
293
  }
286
294
  const errors = [];
287
295
  if (content.charCodeAt(0) === 65279) {
288
- errors.push(l10n.t('Problem reading content from \'{0}\': UTF-8 with BOM detected, only UTF 8 is allowed.', toDisplayString(url)));
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));
289
297
  content = content.trimStart();
290
298
  }
291
299
  let schemaContent = {};
292
300
  const jsonErrors = [];
293
301
  schemaContent = Json.parse(content, jsonErrors);
294
302
  if (jsonErrors.length) {
295
- errors.push(l10n.t('Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset));
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));
296
304
  }
297
305
  return new UnresolvedSchema(schemaContent, errors);
298
306
  }, (error) => {
299
- let errorMessage = error.toString();
300
- const errorSplit = error.toString().split('Error: ');
301
- if (errorSplit.length > 1) {
302
- // more concise error message, URL and context are attached by caller anyways
303
- errorMessage = errorSplit[1];
307
+ let { message, code } = error;
308
+ if (typeof message !== 'string') {
309
+ let errorMessage = error.toString();
310
+ const errorSplit = error.toString().split('Error: ');
311
+ if (errorSplit.length > 1) {
312
+ // more concise error message, URL and context are attached by caller anyways
313
+ errorMessage = errorSplit[1];
314
+ }
315
+ if (Strings.endsWith(errorMessage, '.')) {
316
+ errorMessage = errorMessage.substr(0, errorMessage.length - 1);
317
+ }
318
+ message = errorMessage;
304
319
  }
305
- if (Strings.endsWith(errorMessage, '.')) {
306
- errorMessage = errorMessage.substr(0, errorMessage.length - 1);
320
+ let errorCode = jsonLanguageTypes_1.ErrorCode.SchemaResolveError;
321
+ if (typeof code === 'number' && code < 0x10000) {
322
+ errorCode += code;
307
323
  }
308
- return new UnresolvedSchema({}, [l10n.t('Unable to load schema from \'{0}\': {1}.', toDisplayString(url), errorMessage)]);
324
+ const errorMessage = l10n.t('Unable to load schema from \'{0}\': {1}.', toDisplayString(url), message);
325
+ return new UnresolvedSchema({}, [toDiagnostic(errorMessage, errorCode, url)]);
309
326
  });
310
327
  }
311
328
  resolveSchemaContent(schemaToResolve, handle) {
@@ -313,7 +330,7 @@
313
330
  const schema = schemaToResolve.schema;
314
331
  const schemaDraft = schema.$schema ? (0, jsonParser_1.getSchemaDraftFromId)(schema.$schema) : undefined;
315
332
  if (schemaDraft === jsonLanguageTypes_1.SchemaDraft.v3) {
316
- return this.promise.resolve(new ResolvedSchema({}, [l10n.t("Draft-03 schemas are not supported.")], [], schemaDraft));
333
+ return this.promise.resolve(new ResolvedSchema({}, [toDiagnostic(l10n.t("Draft-03 schemas are not supported."), jsonLanguageTypes_1.ErrorCode.SchemaUnsupportedFeature)], [], schemaDraft));
317
334
  }
318
335
  let usesUnsupportedFeatures = new Set();
319
336
  const contextService = this.contextService;
@@ -360,7 +377,8 @@
360
377
  merge(target, section);
361
378
  }
362
379
  else {
363
- resolveErrors.push(l10n.t('$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment || '', sourceHandle.uri));
380
+ const message = l10n.t('$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment || '', sourceHandle.uri);
381
+ resolveErrors.push(toDiagnostic(message, jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
364
382
  }
365
383
  };
366
384
  const resolveExternalLink = (node, uri, refSegment, parentHandle) => {
@@ -372,8 +390,10 @@
372
390
  return referencedHandle.getUnresolvedSchema().then(unresolvedSchema => {
373
391
  parentHandle.dependencies.add(uri);
374
392
  if (unresolvedSchema.errors.length) {
393
+ const error = unresolvedSchema.errors[0];
375
394
  const loc = refSegment ? uri + '#' + refSegment : uri;
376
- resolveErrors.push(l10n.t('Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
395
+ const errorMessage = refSegment ? l10n.t('Problems loading reference \'{0}\': {1}', refSegment, error.message) : error.message;
396
+ resolveErrors.push(toDiagnostic(errorMessage, error.code, uri));
377
397
  }
378
398
  mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
379
399
  return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
@@ -417,7 +437,7 @@
417
437
  const anchor = (0, objects_1.isString)(id) && id.charAt(0) === '#' ? id.substring(1) : next.$anchor;
418
438
  if (anchor) {
419
439
  if (result.has(anchor)) {
420
- resolveErrors.push(l10n.t('Duplicate anchor declaration: \'{0}\'', anchor));
440
+ resolveErrors.push(toDiagnostic(l10n.t('Duplicate anchor declaration: \'{0}\'', anchor), jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
421
441
  }
422
442
  else {
423
443
  result.set(anchor, next);
@@ -435,7 +455,7 @@
435
455
  return resolveRefs(schema, schema, handle).then(_ => {
436
456
  let resolveWarnings = [];
437
457
  if (usesUnsupportedFeatures.size) {
438
- resolveWarnings.push(l10n.t('The schema uses meta-schema features ({0}) that are not yet supported by the validator.', Array.from(usesUnsupportedFeatures.keys()).join(', ')));
458
+ resolveWarnings.push(toDiagnostic(l10n.t('The schema uses meta-schema features ({0}) that are not yet supported by the validator.', Array.from(usesUnsupportedFeatures.keys()).join(', ')), jsonLanguageTypes_1.ErrorCode.SchemaUnsupportedFeature));
439
459
  }
440
460
  return new ResolvedSchema(schema, resolveErrors, resolveWarnings, schemaDraft);
441
461
  });
@@ -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
- addSchemaProblem(schema.errors[0], jsonLanguageTypes_1.ErrorCode.SchemaResolveError);
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, jsonLanguageTypes_1.ErrorCode.SchemaUnsupportedFeature);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "5.6.4",
3
+ "version": "5.7.1",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",
@@ -17,12 +17,12 @@
17
17
  "devDependencies": {
18
18
  "@types/mocha": "^10.0.10",
19
19
  "@types/node": "22.x",
20
- "@typescript-eslint/eslint-plugin": "^8.48.0",
21
- "@typescript-eslint/parser": "^8.48.0",
22
- "eslint": "^9.39.1",
20
+ "@typescript-eslint/eslint-plugin": "^8.53.0",
21
+ "@typescript-eslint/parser": "^8.53.0",
22
+ "eslint": "^9.39.2",
23
23
  "json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite.git#69acf52990b004240839ae19b4bec8fb01d50876",
24
- "mocha": "^11.7.4",
25
- "rimraf": "^6.1.0",
24
+ "mocha": "^11.7.5",
25
+ "rimraf": "^6.1.2",
26
26
  "typescript": "^5.9.3"
27
27
  },
28
28
  "dependencies": {