vscode-json-languageservice 5.3.4 → 5.3.5

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;
@@ -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) {
@@ -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;
@@ -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) {
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.5",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",