vscode-json-languageservice 5.3.4 → 5.3.6

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.
@@ -8,8 +8,13 @@ export interface JSONWorkerContribution {
8
8
  }
9
9
  export type Segment = string | number;
10
10
  export type JSONPath = Segment[];
11
+ export type JSONCompletionItem = CompletionItem & {
12
+ insertText: string;
13
+ };
11
14
  export interface CompletionsCollector {
12
- add(suggestion: CompletionItem): void;
15
+ add(suggestion: JSONCompletionItem & {
16
+ insertText: string;
17
+ }): void;
13
18
  error(message: string): void;
14
19
  setAsIncomplete(): void;
15
20
  getNumberOfProposals(): number;
@@ -25,6 +25,7 @@ export declare enum ErrorCode {
25
25
  TrailingComma = 519,
26
26
  DuplicateKey = 520,
27
27
  CommentNotPermitted = 521,
28
+ PropertyKeysMustBeDoublequoted = 528,
28
29
  SchemaResolveError = 768,
29
30
  SchemaUnsupportedFeature = 769
30
31
  }
@@ -28,6 +28,7 @@ export var ErrorCode;
28
28
  ErrorCode[ErrorCode["TrailingComma"] = 519] = "TrailingComma";
29
29
  ErrorCode[ErrorCode["DuplicateKey"] = 520] = "DuplicateKey";
30
30
  ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
31
+ ErrorCode[ErrorCode["PropertyKeysMustBeDoublequoted"] = 528] = "PropertyKeysMustBeDoublequoted";
31
32
  ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
32
33
  ErrorCode[ErrorCode["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
33
34
  })(ErrorCode || (ErrorCode = {}));
@@ -1091,7 +1091,7 @@ export function parse(textDocument, config) {
1091
1091
  if (!key) {
1092
1092
  if (scanner.getToken() === 16 /* Json.SyntaxKind.Unknown */) {
1093
1093
  // give a more helpful error message
1094
- _error(l10n.t('Property keys must be doublequoted'), ErrorCode.Undefined);
1094
+ _error(l10n.t('Property keys must be doublequoted'), ErrorCode.PropertyKeysMustBeDoublequoted);
1095
1095
  const keyNode = new StringASTNodeImpl(node, scanner.getTokenOffset(), scanner.getTokenLength());
1096
1096
  keyNode.value = scanner.getTokenValue();
1097
1097
  key = keyNode;
@@ -6,10 +6,6 @@ import * as l10n from '@vscode/l10n';
6
6
  export const schemaContributions = {
7
7
  schemaAssociations: [],
8
8
  schemas: {
9
- // refer to the latest schema
10
- 'http://json-schema.org/schema#': {
11
- $ref: 'http://json-schema.org/draft-07/schema#'
12
- },
13
9
  // bundle the schema-schema to include (localized) descriptions
14
10
  'http://json-schema.org/draft-04/schema#': {
15
11
  '$schema': 'http://json-schema.org/draft-04/schema#',
@@ -74,9 +74,7 @@ export class JSONCompletion {
74
74
  label = shortendedLabel;
75
75
  }
76
76
  }
77
- if (overwriteRange && suggestion.insertText !== undefined) {
78
- suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
79
- }
77
+ suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
80
78
  if (supportsCommitCharacters) {
81
79
  suggestion.commitCharacters = suggestion.kind === CompletionItemKind.Property ? propertyCommitCharacters : valueCommitCharacters;
82
80
  }
@@ -407,26 +405,31 @@ export class JSONCompletion {
407
405
  for (const s of matchingSchemas) {
408
406
  if (s.node === node && !s.inverted && s.schema) {
409
407
  if (node.type === 'array' && s.schema.items) {
410
- const arrayValues = Parser.getNodeValue(node);
411
- const self = this;
412
- const filteringCollector = {
413
- ...collector,
414
- add(suggestion) {
415
- const value = self.getValueFromLabel(suggestion.label);
416
- if (s.schema.uniqueItems === true && arrayValues.includes(value)) {
417
- return;
408
+ let c = collector;
409
+ if (s.schema.uniqueItems) {
410
+ const existingValues = new Set();
411
+ node.children.forEach(n => {
412
+ if (n.type !== 'array' && n.type !== 'object') {
413
+ existingValues.add(this.getLabelForValue(Parser.getNodeValue(n)));
418
414
  }
419
- collector.add(suggestion);
420
- },
421
- };
415
+ });
416
+ c = {
417
+ ...collector,
418
+ add(suggestion) {
419
+ if (!existingValues.has(suggestion.label)) {
420
+ collector.add(suggestion);
421
+ }
422
+ }
423
+ };
424
+ }
422
425
  if (Array.isArray(s.schema.items)) {
423
426
  const index = this.findItemAtOffset(node, document, offset);
424
427
  if (index < s.schema.items.length) {
425
- this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, filteringCollector, types);
428
+ this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, c, types);
426
429
  }
427
430
  }
428
431
  else {
429
- this.addSchemaValueCompletions(s.schema.items, separatorAfter, filteringCollector, types);
432
+ this.addSchemaValueCompletions(s.schema.items, separatorAfter, c, types);
430
433
  }
431
434
  }
432
435
  if (parentKey !== undefined) {
@@ -683,13 +686,18 @@ export class JSONCompletion {
683
686
  }
684
687
  addDollarSchemaCompletions(separatorAfter, collector) {
685
688
  const schemaIds = this.schemaService.getRegisteredSchemaIds(schema => schema === 'http' || schema === 'https');
686
- schemaIds.forEach(schemaId => collector.add({
687
- kind: CompletionItemKind.Module,
688
- label: this.getLabelForValue(schemaId),
689
- filterText: this.getFilterTextForValue(schemaId),
690
- insertText: this.getInsertTextForValue(schemaId, separatorAfter),
691
- insertTextFormat: InsertTextFormat.Snippet, documentation: ''
692
- }));
689
+ schemaIds.forEach(schemaId => {
690
+ if (schemaId.startsWith('http://json-schema.org/draft-')) {
691
+ schemaId = schemaId + '#';
692
+ }
693
+ collector.add({
694
+ kind: CompletionItemKind.Module,
695
+ label: this.getLabelForValue(schemaId),
696
+ filterText: this.getFilterTextForValue(schemaId),
697
+ insertText: this.getInsertTextForValue(schemaId, separatorAfter),
698
+ insertTextFormat: InsertTextFormat.Snippet, documentation: ''
699
+ });
700
+ });
693
701
  }
694
702
  getLabelForValue(value) {
695
703
  return JSON.stringify(value);
@@ -8,8 +8,13 @@ export interface JSONWorkerContribution {
8
8
  }
9
9
  export type Segment = string | number;
10
10
  export type JSONPath = Segment[];
11
+ export type JSONCompletionItem = CompletionItem & {
12
+ insertText: string;
13
+ };
11
14
  export interface CompletionsCollector {
12
- add(suggestion: CompletionItem): void;
15
+ add(suggestion: JSONCompletionItem & {
16
+ insertText: string;
17
+ }): void;
13
18
  error(message: string): void;
14
19
  setAsIncomplete(): void;
15
20
  getNumberOfProposals(): number;
@@ -25,6 +25,7 @@ export declare enum ErrorCode {
25
25
  TrailingComma = 519,
26
26
  DuplicateKey = 520,
27
27
  CommentNotPermitted = 521,
28
+ PropertyKeysMustBeDoublequoted = 528,
28
29
  SchemaResolveError = 768,
29
30
  SchemaUnsupportedFeature = 769
30
31
  }
@@ -75,9 +75,10 @@
75
75
  ErrorCode[ErrorCode["TrailingComma"] = 519] = "TrailingComma";
76
76
  ErrorCode[ErrorCode["DuplicateKey"] = 520] = "DuplicateKey";
77
77
  ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
78
+ ErrorCode[ErrorCode["PropertyKeysMustBeDoublequoted"] = 528] = "PropertyKeysMustBeDoublequoted";
78
79
  ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
79
80
  ErrorCode[ErrorCode["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
80
- })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
81
+ })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
81
82
  var SchemaDraft;
82
83
  (function (SchemaDraft) {
83
84
  SchemaDraft[SchemaDraft["v3"] = 3] = "v3";
@@ -86,7 +87,7 @@
86
87
  SchemaDraft[SchemaDraft["v7"] = 7] = "v7";
87
88
  SchemaDraft[SchemaDraft["v2019_09"] = 19] = "v2019_09";
88
89
  SchemaDraft[SchemaDraft["v2020_12"] = 20] = "v2020_12";
89
- })(SchemaDraft = exports.SchemaDraft || (exports.SchemaDraft = {}));
90
+ })(SchemaDraft || (exports.SchemaDraft = SchemaDraft = {}));
90
91
  var ClientCapabilities;
91
92
  (function (ClientCapabilities) {
92
93
  ClientCapabilities.LATEST = {
@@ -100,5 +101,5 @@
100
101
  }
101
102
  }
102
103
  };
103
- })(ClientCapabilities = exports.ClientCapabilities || (exports.ClientCapabilities = {}));
104
+ })(ClientCapabilities || (exports.ClientCapabilities = ClientCapabilities = {}));
104
105
  });
@@ -121,7 +121,7 @@
121
121
  (function (EnumMatch) {
122
122
  EnumMatch[EnumMatch["Key"] = 0] = "Key";
123
123
  EnumMatch[EnumMatch["Enum"] = 1] = "Enum";
124
- })(EnumMatch = exports.EnumMatch || (exports.EnumMatch = {}));
124
+ })(EnumMatch || (exports.EnumMatch = EnumMatch = {}));
125
125
  const schemaDraftFromId = {
126
126
  'http://json-schema.org/draft-03/schema#': jsonLanguageTypes_1.SchemaDraft.v3,
127
127
  'http://json-schema.org/draft-04/schema#': jsonLanguageTypes_1.SchemaDraft.v4,
@@ -1118,7 +1118,7 @@
1118
1118
  if (!key) {
1119
1119
  if (scanner.getToken() === 16 /* Json.SyntaxKind.Unknown */) {
1120
1120
  // give a more helpful error message
1121
- _error(l10n.t('Property keys must be doublequoted'), jsonLanguageTypes_1.ErrorCode.Undefined);
1121
+ _error(l10n.t('Property keys must be doublequoted'), jsonLanguageTypes_1.ErrorCode.PropertyKeysMustBeDoublequoted);
1122
1122
  const keyNode = new StringASTNodeImpl(node, scanner.getTokenOffset(), scanner.getTokenLength());
1123
1123
  keyNode.value = scanner.getTokenValue();
1124
1124
  key = keyNode;
@@ -18,10 +18,6 @@
18
18
  exports.schemaContributions = {
19
19
  schemaAssociations: [],
20
20
  schemas: {
21
- // refer to the latest schema
22
- 'http://json-schema.org/schema#': {
23
- $ref: 'http://json-schema.org/draft-07/schema#'
24
- },
25
21
  // bundle the schema-schema to include (localized) descriptions
26
22
  'http://json-schema.org/draft-04/schema#': {
27
23
  '$schema': 'http://json-schema.org/draft-04/schema#',
@@ -86,9 +86,7 @@
86
86
  label = shortendedLabel;
87
87
  }
88
88
  }
89
- if (overwriteRange && suggestion.insertText !== undefined) {
90
- suggestion.textEdit = jsonLanguageTypes_1.TextEdit.replace(overwriteRange, suggestion.insertText);
91
- }
89
+ suggestion.textEdit = jsonLanguageTypes_1.TextEdit.replace(overwriteRange, suggestion.insertText);
92
90
  if (supportsCommitCharacters) {
93
91
  suggestion.commitCharacters = suggestion.kind === jsonLanguageTypes_1.CompletionItemKind.Property ? propertyCommitCharacters : valueCommitCharacters;
94
92
  }
@@ -419,26 +417,31 @@
419
417
  for (const s of matchingSchemas) {
420
418
  if (s.node === node && !s.inverted && s.schema) {
421
419
  if (node.type === 'array' && s.schema.items) {
422
- const arrayValues = Parser.getNodeValue(node);
423
- const self = this;
424
- const filteringCollector = {
425
- ...collector,
426
- add(suggestion) {
427
- const value = self.getValueFromLabel(suggestion.label);
428
- if (s.schema.uniqueItems === true && arrayValues.includes(value)) {
429
- return;
420
+ let c = collector;
421
+ if (s.schema.uniqueItems) {
422
+ const existingValues = new Set();
423
+ node.children.forEach(n => {
424
+ if (n.type !== 'array' && n.type !== 'object') {
425
+ existingValues.add(this.getLabelForValue(Parser.getNodeValue(n)));
430
426
  }
431
- collector.add(suggestion);
432
- },
433
- };
427
+ });
428
+ c = {
429
+ ...collector,
430
+ add(suggestion) {
431
+ if (!existingValues.has(suggestion.label)) {
432
+ collector.add(suggestion);
433
+ }
434
+ }
435
+ };
436
+ }
434
437
  if (Array.isArray(s.schema.items)) {
435
438
  const index = this.findItemAtOffset(node, document, offset);
436
439
  if (index < s.schema.items.length) {
437
- this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, filteringCollector, types);
440
+ this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, c, types);
438
441
  }
439
442
  }
440
443
  else {
441
- this.addSchemaValueCompletions(s.schema.items, separatorAfter, filteringCollector, types);
444
+ this.addSchemaValueCompletions(s.schema.items, separatorAfter, c, types);
442
445
  }
443
446
  }
444
447
  if (parentKey !== undefined) {
@@ -695,13 +698,18 @@
695
698
  }
696
699
  addDollarSchemaCompletions(separatorAfter, collector) {
697
700
  const schemaIds = this.schemaService.getRegisteredSchemaIds(schema => schema === 'http' || schema === 'https');
698
- schemaIds.forEach(schemaId => collector.add({
699
- kind: jsonLanguageTypes_1.CompletionItemKind.Module,
700
- label: this.getLabelForValue(schemaId),
701
- filterText: this.getFilterTextForValue(schemaId),
702
- insertText: this.getInsertTextForValue(schemaId, separatorAfter),
703
- insertTextFormat: jsonLanguageTypes_1.InsertTextFormat.Snippet, documentation: ''
704
- }));
701
+ schemaIds.forEach(schemaId => {
702
+ if (schemaId.startsWith('http://json-schema.org/draft-')) {
703
+ schemaId = schemaId + '#';
704
+ }
705
+ collector.add({
706
+ kind: jsonLanguageTypes_1.CompletionItemKind.Module,
707
+ label: this.getLabelForValue(schemaId),
708
+ filterText: this.getFilterTextForValue(schemaId),
709
+ insertText: this.getInsertTextForValue(schemaId, separatorAfter),
710
+ insertTextFormat: jsonLanguageTypes_1.InsertTextFormat.Snippet, documentation: ''
711
+ });
712
+ });
705
713
  }
706
714
  getLabelForValue(value) {
707
715
  return JSON.stringify(value);
@@ -18,7 +18,7 @@
18
18
  (function (Container) {
19
19
  Container[Container["Object"] = 0] = "Object";
20
20
  Container[Container["Array"] = 1] = "Array";
21
- })(Container = exports.Container || (exports.Container = {}));
21
+ })(Container || (exports.Container = Container = {}));
22
22
  class PropertyTree {
23
23
  constructor(propertyName, beginningLineNumber) {
24
24
  this.propertyName = propertyName ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "5.3.4",
3
+ "version": "5.3.6",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",
@@ -17,20 +17,20 @@
17
17
  "devDependencies": {
18
18
  "@types/mocha": "^10.0.1",
19
19
  "@types/node": "16.x",
20
- "@typescript-eslint/eslint-plugin": "^5.59.1",
21
- "@typescript-eslint/parser": "^5.59.1",
22
- "eslint": "^8.39.0",
20
+ "@typescript-eslint/eslint-plugin": "^6.5.0",
21
+ "@typescript-eslint/parser": "^6.5.0",
22
+ "eslint": "^8.48.0",
23
23
  "json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite.git#69acf52990b004240839ae19b4bec8fb01d50876",
24
24
  "mocha": "^10.2.0",
25
- "rimraf": "^5.0.0",
26
- "typescript": "^5.0.4"
25
+ "rimraf": "^5.0.1",
26
+ "typescript": "^5.2.2"
27
27
  },
28
28
  "dependencies": {
29
29
  "jsonc-parser": "^3.2.0",
30
30
  "vscode-languageserver-textdocument": "^1.0.8",
31
31
  "vscode-languageserver-types": "^3.17.3",
32
32
  "vscode-uri": "^3.0.7",
33
- "@vscode/l10n": "^0.0.13"
33
+ "@vscode/l10n": "^0.0.16"
34
34
  },
35
35
  "scripts": {
36
36
  "prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",