vscode-json-languageservice 5.7.0 → 5.7.2

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.
@@ -482,7 +482,7 @@ const descriptions = {
482
482
  maxProperties: l10n.t("The maximum number of properties an object can have. Inclusive."),
483
483
  minProperties: l10n.t("The minimum number of properties an object can have. Inclusive."),
484
484
  required: l10n.t("An array of strings that lists the names of all properties required on this object."),
485
- additionalProperties: l10n.t("Either a schema or a boolean. If a schema, used to validate all properties not matched by 'properties', 'propertyNames', or 'patternProperties'. If false, any properties not defined by the adajacent keywords will cause this schema to fail."),
485
+ additionalProperties: l10n.t("Either a schema or a boolean. If a schema, used to validate all properties not matched by 'properties', 'propertyNames', or 'patternProperties'. If false, any properties not defined by the adjacent keywords will cause this schema to fail."),
486
486
  definitions: l10n.t("Not used for validation. Place subschemas here that you wish to reference inline with $ref."),
487
487
  properties: l10n.t("A map of property names to schemas for each property."),
488
488
  patternProperties: l10n.t("A map of regular expressions on property names to schemas for matching properties."),
@@ -95,7 +95,9 @@ function toMarkdown(plain) {
95
95
  return plain
96
96
  .trim()
97
97
  .replace(/[\\`*_{}[\]()<>#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
98
- .replace(/([ \t]+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape spaces tabs
98
+ .replace(/(^ +)/mg, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape leading spaces on each line
99
+ .replace(/( {2,})/g, (_match, g1) => ' ' + '&nbsp;'.repeat(g1.length - 1)) // escape consecutive spaces
100
+ .replace(/(\t+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length * 4)) // escape tabs
99
101
  .replace(/\n/g, '\\\n'); // escape new lines
100
102
  }
101
103
  return undefined;
@@ -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
- return { message, code };
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}', loc, unresolvedSchema.errors[0].message);
376
- resolveErrors.push(toDiagnostic(errorMessage, unresolvedSchema.errors[0].code));
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
- addSchemaProblem(schema.errors[0].message, schema.errors[0].code);
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) {
@@ -494,7 +494,7 @@
494
494
  maxProperties: l10n.t("The maximum number of properties an object can have. Inclusive."),
495
495
  minProperties: l10n.t("The minimum number of properties an object can have. Inclusive."),
496
496
  required: l10n.t("An array of strings that lists the names of all properties required on this object."),
497
- additionalProperties: l10n.t("Either a schema or a boolean. If a schema, used to validate all properties not matched by 'properties', 'propertyNames', or 'patternProperties'. If false, any properties not defined by the adajacent keywords will cause this schema to fail."),
497
+ additionalProperties: l10n.t("Either a schema or a boolean. If a schema, used to validate all properties not matched by 'properties', 'propertyNames', or 'patternProperties'. If false, any properties not defined by the adjacent keywords will cause this schema to fail."),
498
498
  definitions: l10n.t("Not used for validation. Place subschemas here that you wish to reference inline with $ref."),
499
499
  properties: l10n.t("A map of property names to schemas for each property."),
500
500
  patternProperties: l10n.t("A map of regular expressions on property names to schemas for matching properties."),
@@ -108,7 +108,9 @@
108
108
  return plain
109
109
  .trim()
110
110
  .replace(/[\\`*_{}[\]()<>#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
111
- .replace(/([ \t]+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape spaces tabs
111
+ .replace(/(^ +)/mg, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape leading spaces on each line
112
+ .replace(/( {2,})/g, (_match, g1) => ' ' + '&nbsp;'.repeat(g1.length - 1)) // escape consecutive spaces
113
+ .replace(/(\t+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length * 4)) // escape tabs
112
114
  .replace(/\n/g, '\\\n'); // escape new lines
113
115
  }
114
116
  return undefined;
@@ -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
- return { message, code };
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}', loc, unresolvedSchema.errors[0].message);
390
- resolveErrors.push(toDiagnostic(errorMessage, unresolvedSchema.errors[0].code));
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
- addSchemaProblem(schema.errors[0].message, schema.errors[0].code);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "5.7.0",
3
+ "version": "5.7.2",
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.53.0",
21
- "@typescript-eslint/parser": "^8.53.0",
22
- "eslint": "^9.39.2",
20
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
21
+ "@typescript-eslint/parser": "^8.56.0",
22
+ "eslint": "^9.39.3",
23
23
  "json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite.git#69acf52990b004240839ae19b4bec8fb01d50876",
24
24
  "mocha": "^11.7.5",
25
- "rimraf": "^6.1.2",
25
+ "rimraf": "^6.1.3",
26
26
  "typescript": "^5.9.3"
27
27
  },
28
28
  "dependencies": {