vscode-json-languageservice 5.4.1 → 5.4.3

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.
@@ -83,6 +83,7 @@ export interface JSONSchema {
83
83
  suggestSortText?: string;
84
84
  allowComments?: boolean;
85
85
  allowTrailingCommas?: boolean;
86
+ completionDetail?: string;
86
87
  }
87
88
  export interface JSONSchemaMap {
88
89
  [name: string]: JSONSchemaRef;
@@ -164,6 +164,10 @@ export class ValidationResult {
164
164
  mergeEnumValues(validationResult) {
165
165
  if (!this.enumValueMatch && !validationResult.enumValueMatch && this.enumValues && validationResult.enumValues) {
166
166
  this.enumValues = this.enumValues.concat(validationResult.enumValues);
167
+ }
168
+ }
169
+ updateEnumMismatchProblemMessages() {
170
+ if (!this.enumValueMatch && this.enumValues) {
167
171
  for (const error of this.problems) {
168
172
  if (error.code === ErrorCode.EnumValueMismatch) {
169
173
  error.message = l10n.t('Value is not accepted. Valid values: {0}.', this.enumValues.map(v => JSON.stringify(v)).join(', '));
@@ -382,6 +386,7 @@ function validate(n, schema, validationResult, matchingSchemas, context) {
382
386
  });
383
387
  }
384
388
  if (bestMatch) {
389
+ bestMatch.validationResult.updateEnumMismatchProblemMessages();
385
390
  validationResult.merge(bestMatch.validationResult);
386
391
  matchingSchemas.merge(bestMatch.matchingSchemas);
387
392
  }
@@ -460,8 +460,8 @@ export const schemaContributions = {
460
460
  const descriptions = {
461
461
  id: l10n.t("A unique identifier for the schema."),
462
462
  $schema: l10n.t("The schema to verify this document against."),
463
- title: l10n.t("A descriptive title of the element."),
464
- description: l10n.t("A long description of the element. Used in hover menus and suggestions."),
463
+ title: l10n.t("A descriptive title of the schema."),
464
+ description: l10n.t("A long description of the schema. Used in hover menus and suggestions."),
465
465
  default: l10n.t("A default value. Used by suggestions."),
466
466
  multipleOf: l10n.t("A number that should cleanly divide the current value (i.e. have no remainder)."),
467
467
  maximum: l10n.t("The maximum numerical value, inclusive by default."),
@@ -471,7 +471,7 @@ const descriptions = {
471
471
  maxLength: l10n.t("The maximum length of a string."),
472
472
  minLength: l10n.t("The minimum length of a string."),
473
473
  pattern: l10n.t("A regular expression to match the string against. It is not implicitly anchored."),
474
- additionalItems: l10n.t("For arrays, only when items is set as an array. If it is a schema, then this schema validates items after the ones specified by the items array. If it is false, then additional items will cause validation to fail."),
474
+ additionalItems: l10n.t("For arrays, only when items is set as an array. If items are a schema, this schema validates items after the ones specified by the items schema. If false, additional items will cause validation to fail."),
475
475
  items: l10n.t("For arrays. Can either be a schema to validate every element against or an array of schemas to validate each item against in order (the first schema will validate the first element, the second schema will validate the second element, and so on."),
476
476
  maxItems: l10n.t("The maximum number of items that can be inside an array. Inclusive."),
477
477
  minItems: l10n.t("The minimum number of items that can be inside an array. Inclusive."),
@@ -479,14 +479,14 @@ const descriptions = {
479
479
  maxProperties: l10n.t("The maximum number of properties an object can have. Inclusive."),
480
480
  minProperties: l10n.t("The minimum number of properties an object can have. Inclusive."),
481
481
  required: l10n.t("An array of strings that lists the names of all properties required on this object."),
482
- additionalProperties: l10n.t("Either a schema or a boolean. If a schema, then used to validate all properties not matched by 'properties' or 'patternProperties'. If false, then any properties not matched by either will cause this schema to fail."),
482
+ 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."),
483
483
  definitions: l10n.t("Not used for validation. Place subschemas here that you wish to reference inline with $ref."),
484
484
  properties: l10n.t("A map of property names to schemas for each property."),
485
485
  patternProperties: l10n.t("A map of regular expressions on property names to schemas for matching properties."),
486
486
  dependencies: l10n.t("A map of property names to either an array of property names or a schema. An array of property names means the property named in the key depends on the properties in the array being present in the object in order to be valid. If the value is a schema, then the schema is only applied to the object if the property in the key exists on the object."),
487
487
  enum: l10n.t("The set of literal values that are valid."),
488
488
  type: l10n.t("Either a string of one of the basic schema types (number, integer, null, array, object, boolean, string) or an array of strings specifying a subset of those types."),
489
- format: l10n.t("Describes the format expected for the value."),
489
+ format: l10n.t("Describes the format expected for the value. By default, not used for validation"),
490
490
  allOf: l10n.t("An array of schemas, all of which must match."),
491
491
  anyOf: l10n.t("An array of schemas, where at least one must match."),
492
492
  oneOf: l10n.t("An array of schemas, exactly one of which must match."),
@@ -502,7 +502,7 @@ const descriptions = {
502
502
  contentMediaType: l10n.t("Describes the media type of a string property."),
503
503
  contentEncoding: l10n.t("Describes the content encoding of a string property."),
504
504
  if: l10n.t("The validation outcome of the \"if\" subschema controls which of the \"then\" or \"else\" keywords are evaluated."),
505
- then: l10n.t("The \"if\" subschema is used for validation when the \"if\" subschema succeeds."),
505
+ then: l10n.t("The \"then\" subschema is used for validation when the \"if\" subschema succeeds."),
506
506
  else: l10n.t("The \"else\" subschema is used for validation when the \"if\" subschema fails.")
507
507
  };
508
508
  for (const schemaName in schemaContributions.schemas) {
@@ -205,8 +205,11 @@ export class JSONCompletion {
205
205
  insertText: this.getInsertTextForProperty(key, propertySchema, addValue, separatorAfter),
206
206
  insertTextFormat: InsertTextFormat.Snippet,
207
207
  filterText: this.getFilterTextForValue(key),
208
- documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
208
+ documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || ''
209
209
  };
210
+ if (propertySchema.completionDetail !== undefined) {
211
+ proposal.detail = propertySchema.completionDetail;
212
+ }
210
213
  if (propertySchema.suggestSortText !== undefined) {
211
214
  proposal.sortText = propertySchema.suggestSortText;
212
215
  }
@@ -229,8 +232,11 @@ export class JSONCompletion {
229
232
  insertText: this.getInsertTextForProperty(name, undefined, addValue, separatorAfter),
230
233
  insertTextFormat: InsertTextFormat.Snippet,
231
234
  filterText: this.getFilterTextForValue(name),
232
- documentation: enumDescription || this.fromMarkup(schemaPropertyNames.markdownDescription) || schemaPropertyNames.description || '',
235
+ documentation: enumDescription || this.fromMarkup(schemaPropertyNames.markdownDescription) || schemaPropertyNames.description || ''
233
236
  };
237
+ if (schemaPropertyNames.completionDetail !== undefined) {
238
+ proposal.detail = schemaPropertyNames.completionDetail;
239
+ }
234
240
  if (schemaPropertyNames.suggestSortText !== undefined) {
235
241
  proposal.sortText = schemaPropertyNames.suggestSortText;
236
242
  }
@@ -352,7 +352,7 @@ export class JSONSchemaService {
352
352
  }
353
353
  };
354
354
  const resolveExternalLink = (node, uri, refSegment, parentHandle) => {
355
- if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
355
+ if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/.*/.test(uri)) {
356
356
  uri = contextService.resolveRelativePath(uri, parentHandle.uri);
357
357
  }
358
358
  uri = normalizeId(uri);
@@ -321,12 +321,8 @@ function sortJsoncDocument(jsonDocument, propertyTree) {
321
321
  }
322
322
  return sortedJsonDocument;
323
323
  }
324
- function sortPropertiesCaseSensitive(properties) {
325
- properties.sort((a, b) => {
326
- const aName = a.propertyName ?? '';
327
- const bName = b.propertyName ?? '';
328
- return aName < bName ? -1 : aName > bName ? 1 : 0;
329
- });
324
+ function sortProperties(properties) {
325
+ properties.sort((a, b) => a.propertyName.localeCompare(b.propertyName));
330
326
  }
331
327
  function updateSortingQueue(queue, propertyTree, beginningLineNumber) {
332
328
  if (propertyTree.childrenProperties.length === 0) {
@@ -341,7 +337,7 @@ function updateSortingQueue(queue, propertyTree, beginningLineNumber) {
341
337
  }
342
338
  const diff = minimumBeginningLineNumber - propertyTree.beginningLineNumber;
343
339
  beginningLineNumber = beginningLineNumber + diff;
344
- sortPropertiesCaseSensitive(propertyTree.childrenProperties);
340
+ sortProperties(propertyTree.childrenProperties);
345
341
  queue.push(new SortingRange(beginningLineNumber, propertyTree.childrenProperties));
346
342
  }
347
343
  else if (propertyTree.type === Container.Array) {
@@ -83,6 +83,7 @@ export interface JSONSchema {
83
83
  suggestSortText?: string;
84
84
  allowComments?: boolean;
85
85
  allowTrailingCommas?: boolean;
86
+ completionDetail?: string;
86
87
  }
87
88
  export interface JSONSchemaMap {
88
89
  [name: string]: JSONSchemaRef;
@@ -190,6 +190,10 @@
190
190
  mergeEnumValues(validationResult) {
191
191
  if (!this.enumValueMatch && !validationResult.enumValueMatch && this.enumValues && validationResult.enumValues) {
192
192
  this.enumValues = this.enumValues.concat(validationResult.enumValues);
193
+ }
194
+ }
195
+ updateEnumMismatchProblemMessages() {
196
+ if (!this.enumValueMatch && this.enumValues) {
193
197
  for (const error of this.problems) {
194
198
  if (error.code === jsonLanguageTypes_1.ErrorCode.EnumValueMismatch) {
195
199
  error.message = l10n.t('Value is not accepted. Valid values: {0}.', this.enumValues.map(v => JSON.stringify(v)).join(', '));
@@ -410,6 +414,7 @@
410
414
  });
411
415
  }
412
416
  if (bestMatch) {
417
+ bestMatch.validationResult.updateEnumMismatchProblemMessages();
413
418
  validationResult.merge(bestMatch.validationResult);
414
419
  matchingSchemas.merge(bestMatch.matchingSchemas);
415
420
  }
@@ -472,8 +472,8 @@
472
472
  const descriptions = {
473
473
  id: l10n.t("A unique identifier for the schema."),
474
474
  $schema: l10n.t("The schema to verify this document against."),
475
- title: l10n.t("A descriptive title of the element."),
476
- description: l10n.t("A long description of the element. Used in hover menus and suggestions."),
475
+ title: l10n.t("A descriptive title of the schema."),
476
+ description: l10n.t("A long description of the schema. Used in hover menus and suggestions."),
477
477
  default: l10n.t("A default value. Used by suggestions."),
478
478
  multipleOf: l10n.t("A number that should cleanly divide the current value (i.e. have no remainder)."),
479
479
  maximum: l10n.t("The maximum numerical value, inclusive by default."),
@@ -483,7 +483,7 @@
483
483
  maxLength: l10n.t("The maximum length of a string."),
484
484
  minLength: l10n.t("The minimum length of a string."),
485
485
  pattern: l10n.t("A regular expression to match the string against. It is not implicitly anchored."),
486
- additionalItems: l10n.t("For arrays, only when items is set as an array. If it is a schema, then this schema validates items after the ones specified by the items array. If it is false, then additional items will cause validation to fail."),
486
+ additionalItems: l10n.t("For arrays, only when items is set as an array. If items are a schema, this schema validates items after the ones specified by the items schema. If false, additional items will cause validation to fail."),
487
487
  items: l10n.t("For arrays. Can either be a schema to validate every element against or an array of schemas to validate each item against in order (the first schema will validate the first element, the second schema will validate the second element, and so on."),
488
488
  maxItems: l10n.t("The maximum number of items that can be inside an array. Inclusive."),
489
489
  minItems: l10n.t("The minimum number of items that can be inside an array. Inclusive."),
@@ -491,14 +491,14 @@
491
491
  maxProperties: l10n.t("The maximum number of properties an object can have. Inclusive."),
492
492
  minProperties: l10n.t("The minimum number of properties an object can have. Inclusive."),
493
493
  required: l10n.t("An array of strings that lists the names of all properties required on this object."),
494
- additionalProperties: l10n.t("Either a schema or a boolean. If a schema, then used to validate all properties not matched by 'properties' or 'patternProperties'. If false, then any properties not matched by either will cause this schema to fail."),
494
+ 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."),
495
495
  definitions: l10n.t("Not used for validation. Place subschemas here that you wish to reference inline with $ref."),
496
496
  properties: l10n.t("A map of property names to schemas for each property."),
497
497
  patternProperties: l10n.t("A map of regular expressions on property names to schemas for matching properties."),
498
498
  dependencies: l10n.t("A map of property names to either an array of property names or a schema. An array of property names means the property named in the key depends on the properties in the array being present in the object in order to be valid. If the value is a schema, then the schema is only applied to the object if the property in the key exists on the object."),
499
499
  enum: l10n.t("The set of literal values that are valid."),
500
500
  type: l10n.t("Either a string of one of the basic schema types (number, integer, null, array, object, boolean, string) or an array of strings specifying a subset of those types."),
501
- format: l10n.t("Describes the format expected for the value."),
501
+ format: l10n.t("Describes the format expected for the value. By default, not used for validation"),
502
502
  allOf: l10n.t("An array of schemas, all of which must match."),
503
503
  anyOf: l10n.t("An array of schemas, where at least one must match."),
504
504
  oneOf: l10n.t("An array of schemas, exactly one of which must match."),
@@ -514,7 +514,7 @@
514
514
  contentMediaType: l10n.t("Describes the media type of a string property."),
515
515
  contentEncoding: l10n.t("Describes the content encoding of a string property."),
516
516
  if: l10n.t("The validation outcome of the \"if\" subschema controls which of the \"then\" or \"else\" keywords are evaluated."),
517
- then: l10n.t("The \"if\" subschema is used for validation when the \"if\" subschema succeeds."),
517
+ then: l10n.t("The \"then\" subschema is used for validation when the \"if\" subschema succeeds."),
518
518
  else: l10n.t("The \"else\" subschema is used for validation when the \"if\" subschema fails.")
519
519
  };
520
520
  for (const schemaName in exports.schemaContributions.schemas) {
@@ -217,8 +217,11 @@
217
217
  insertText: this.getInsertTextForProperty(key, propertySchema, addValue, separatorAfter),
218
218
  insertTextFormat: jsonLanguageTypes_1.InsertTextFormat.Snippet,
219
219
  filterText: this.getFilterTextForValue(key),
220
- documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
220
+ documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || ''
221
221
  };
222
+ if (propertySchema.completionDetail !== undefined) {
223
+ proposal.detail = propertySchema.completionDetail;
224
+ }
222
225
  if (propertySchema.suggestSortText !== undefined) {
223
226
  proposal.sortText = propertySchema.suggestSortText;
224
227
  }
@@ -241,8 +244,11 @@
241
244
  insertText: this.getInsertTextForProperty(name, undefined, addValue, separatorAfter),
242
245
  insertTextFormat: jsonLanguageTypes_1.InsertTextFormat.Snippet,
243
246
  filterText: this.getFilterTextForValue(name),
244
- documentation: enumDescription || this.fromMarkup(schemaPropertyNames.markdownDescription) || schemaPropertyNames.description || '',
247
+ documentation: enumDescription || this.fromMarkup(schemaPropertyNames.markdownDescription) || schemaPropertyNames.description || ''
245
248
  };
249
+ if (schemaPropertyNames.completionDetail !== undefined) {
250
+ proposal.detail = schemaPropertyNames.completionDetail;
251
+ }
246
252
  if (schemaPropertyNames.suggestSortText !== undefined) {
247
253
  proposal.sortText = schemaPropertyNames.suggestSortText;
248
254
  }
@@ -366,7 +366,7 @@
366
366
  }
367
367
  };
368
368
  const resolveExternalLink = (node, uri, refSegment, parentHandle) => {
369
- if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
369
+ if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/.*/.test(uri)) {
370
370
  uri = contextService.resolveRelativePath(uri, parentHandle.uri);
371
371
  }
372
372
  uri = normalizeId(uri);
@@ -333,12 +333,8 @@
333
333
  }
334
334
  return sortedJsonDocument;
335
335
  }
336
- function sortPropertiesCaseSensitive(properties) {
337
- properties.sort((a, b) => {
338
- const aName = a.propertyName ?? '';
339
- const bName = b.propertyName ?? '';
340
- return aName < bName ? -1 : aName > bName ? 1 : 0;
341
- });
336
+ function sortProperties(properties) {
337
+ properties.sort((a, b) => a.propertyName.localeCompare(b.propertyName));
342
338
  }
343
339
  function updateSortingQueue(queue, propertyTree, beginningLineNumber) {
344
340
  if (propertyTree.childrenProperties.length === 0) {
@@ -353,7 +349,7 @@
353
349
  }
354
350
  const diff = minimumBeginningLineNumber - propertyTree.beginningLineNumber;
355
351
  beginningLineNumber = beginningLineNumber + diff;
356
- sortPropertiesCaseSensitive(propertyTree.childrenProperties);
352
+ sortProperties(propertyTree.childrenProperties);
357
353
  queue.push(new SortingRange(beginningLineNumber, propertyTree.childrenProperties));
358
354
  }
359
355
  else if (propertyTree.type === propertyTree_1.Container.Array) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "5.4.1",
3
+ "version": "5.4.3",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",
@@ -15,15 +15,15 @@
15
15
  "url": "https://github.com/Microsoft/vscode-json-languageservice"
16
16
  },
17
17
  "devDependencies": {
18
- "@types/mocha": "^10.0.7",
18
+ "@types/mocha": "^10.0.10",
19
19
  "@types/node": "18.x",
20
- "@typescript-eslint/eslint-plugin": "^7.18.0",
21
- "@typescript-eslint/parser": "^7.18.0",
22
- "eslint": "^8.57.0",
20
+ "@typescript-eslint/eslint-plugin": "^8.22.0",
21
+ "@typescript-eslint/parser": "^8.22.0",
22
+ "eslint": "^9.19.0",
23
23
  "json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite.git#69acf52990b004240839ae19b4bec8fb01d50876",
24
- "mocha": "^10.7.3",
24
+ "mocha": "^11.1.0",
25
25
  "rimraf": "^6.0.1",
26
- "typescript": "^5.5.4"
26
+ "typescript": "^5.7.3"
27
27
  },
28
28
  "dependencies": {
29
29
  "jsonc-parser": "^3.3.1",