vscode-json-languageservice 3.7.0 → 3.8.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +12 -8
  2. package/README.md +2 -1
  3. package/lib/esm/jsonLanguageService.d.ts +6 -2
  4. package/lib/esm/jsonLanguageService.js +1 -0
  5. package/lib/esm/jsonLanguageTypes.d.ts +7 -4
  6. package/lib/esm/jsonLanguageTypes.js +7 -3
  7. package/lib/esm/parser/jsonParser.js +33 -6
  8. package/lib/esm/services/jsonCompletion.js +61 -3
  9. package/lib/esm/services/jsonSchemaService.js +18 -3
  10. package/lib/umd/jsonLanguageService.d.ts +6 -2
  11. package/lib/umd/jsonLanguageService.js +13 -4
  12. package/lib/umd/jsonLanguageTypes.d.ts +7 -4
  13. package/lib/umd/jsonLanguageTypes.js +31 -6
  14. package/lib/umd/parser/jsonParser.js +34 -6
  15. package/lib/umd/services/configuration.js +1 -0
  16. package/lib/umd/services/jsonCompletion.js +62 -3
  17. package/lib/umd/services/jsonDefinition.js +1 -0
  18. package/lib/umd/services/jsonDocumentSymbols.js +1 -0
  19. package/lib/umd/services/jsonFolding.js +1 -0
  20. package/lib/umd/services/jsonHover.js +1 -0
  21. package/lib/umd/services/jsonSchemaService.js +19 -3
  22. package/lib/umd/services/jsonSelectionRanges.js +1 -0
  23. package/lib/umd/services/jsonValidation.js +1 -0
  24. package/lib/umd/utils/colors.js +1 -0
  25. package/lib/umd/utils/json.js +1 -0
  26. package/lib/umd/utils/objects.js +1 -0
  27. package/lib/umd/utils/strings.js +1 -0
  28. package/package.json +1 -1
  29. package/.nyc_output/0abe3076-16a9-4975-87da-4ecfc24d9226.json +0 -1
  30. package/.nyc_output/5a0d1463-368f-4136-8a80-4c7fda7ca33b.json +0 -1
  31. package/.nyc_output/65e3530f-ee58-4bcb-8484-70eb1822427e.json +0 -1
  32. package/.nyc_output/a37c9066-0aa4-4d91-a56b-17754005a42d.json +0 -1
  33. package/.nyc_output/b7eb272f-3bf3-48c4-9a42-90600332b363.json +0 -1
  34. package/.nyc_output/cabc6994-64f7-4258-bb45-9bb5529b388e.json +0 -1
  35. package/.nyc_output/processinfo/0abe3076-16a9-4975-87da-4ecfc24d9226.json +0 -1
  36. package/.nyc_output/processinfo/5a0d1463-368f-4136-8a80-4c7fda7ca33b.json +0 -1
  37. package/.nyc_output/processinfo/65e3530f-ee58-4bcb-8484-70eb1822427e.json +0 -1
  38. package/.nyc_output/processinfo/a37c9066-0aa4-4d91-a56b-17754005a42d.json +0 -1
  39. package/.nyc_output/processinfo/b7eb272f-3bf3-48c4-9a42-90600332b363.json +0 -1
  40. package/.nyc_output/processinfo/cabc6994-64f7-4258-bb45-9bb5529b388e.json +0 -1
  41. package/.nyc_output/processinfo/index.json +0 -1
  42. package/coverage/lcov-report/base.css +0 -224
  43. package/coverage/lcov-report/block-navigation.js +0 -79
  44. package/coverage/lcov-report/favicon.png +0 -0
  45. package/coverage/lcov-report/index.html +0 -156
  46. package/coverage/lcov-report/prettify.css +0 -1
  47. package/coverage/lcov-report/prettify.js +0 -2
  48. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  49. package/coverage/lcov-report/sorter.js +0 -170
  50. package/coverage/lcov-report/src/index.html +0 -126
  51. package/coverage/lcov-report/src/jsonLanguageService.ts.html +0 -383
  52. package/coverage/lcov-report/src/jsonLanguageTypes.ts.html +0 -968
  53. package/coverage/lcov-report/src/parser/index.html +0 -111
  54. package/coverage/lcov-report/src/parser/jsonParser.ts.html +0 -3860
  55. package/coverage/lcov-report/src/services/configuration.ts.html +0 -1679
  56. package/coverage/lcov-report/src/services/index.html +0 -216
  57. package/coverage/lcov-report/src/services/jsonCompletion.ts.html +0 -2843
  58. package/coverage/lcov-report/src/services/jsonDocumentSymbols.ts.html +0 -911
  59. package/coverage/lcov-report/src/services/jsonFolding.ts.html +0 -455
  60. package/coverage/lcov-report/src/services/jsonHover.ts.html +0 -461
  61. package/coverage/lcov-report/src/services/jsonSchemaService.ts.html +0 -1895
  62. package/coverage/lcov-report/src/services/jsonSelectionRanges.ts.html +0 -311
  63. package/coverage/lcov-report/src/services/jsonValidation.ts.html +0 -560
  64. package/coverage/lcov-report/src/utils/colors.ts.html +0 -299
  65. package/coverage/lcov-report/src/utils/index.html +0 -156
  66. package/coverage/lcov-report/src/utils/json.ts.html +0 -206
  67. package/coverage/lcov-report/src/utils/objects.ts.html +0 -296
  68. package/coverage/lcov-report/src/utils/strings.ts.html +0 -224
  69. package/coverage/lcov.info +0 -4219
package/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ 3.8.0 / 2020-08-02
2
+ =================
3
+ * new API `LanguageService.getMatchingSchemas`. Matches a document against its schema and list all AST nodes along with the matching sub schemas.
4
+
1
5
  3.7.0 / 2020-06-04
2
6
  ==================
3
- * New API `JSONSchema.suggestSortText` to set the sort order of completion proposals (VSCode specific JSON schema extension)
7
+ * New API `JSONSchema.suggestSortText` to set the sort order of completion proposals (VS Code specific JSON schema extension)
4
8
 
5
9
  3.6.0 / 2020-04-27
6
10
  ==================
@@ -16,22 +20,22 @@
16
20
 
17
21
  3.4.0 / 2019-10-28
18
22
  ==================
19
- * Added `DocumentSymbolsContext` and `ColorInformationContext` with `resultLimit` and `onResultLimitExceeded`. `onResultLimitExceeded` is called when the result was cropped.
20
- * Added commit characters for completion proposals (if supported by ClientCapabilities)
21
- * Warn when using draft-03 or draft-08 schemas
23
+ * Added `DocumentSymbolsContext` and `ColorInformationContext` with `resultLimit` and `onResultLimitExceeded`. `onResultLimitExceeded` is called when the result was cropped.
24
+ * Added commit characters for completion proposals (if supported by ClientCapabilities)
25
+ * Warn when using draft-03 or draft-08 schemas
22
26
 
23
27
  3.3.4 / 2019-09-20
24
28
  ==================
25
- * Renamed `schema.allowsTrailingCommas` -> `schema.allowTrailingCommas`
29
+ * Renamed `schema.allowsTrailingCommas` -> `schema.allowTrailingCommas`
26
30
 
27
31
  3.3.3 / 2019-08-29
28
32
  ==================
29
- * Schemas can configure whether comments and/or trailing commas are permitted.
33
+ * Schemas can configure whether comments and/or trailing commas are permitted.
30
34
 
31
35
  3.3.0 / 2019-06-12
32
36
  ==================
33
- * New API `LanguageService.getSelectionRanges` to get semantic selection ranges.
34
- * Manage schema dependencies so that `resetSchema` also resets schemas that depend on the schema.
37
+ * New API `LanguageService.getSelectionRanges` to get semantic selection ranges.
38
+ * Manage schema dependencies so that `resetSchema` also resets schemas that depend on the schema.
35
39
 
36
40
  3.2.0 / 2018-09-27
37
41
  ==================
package/README.md CHANGED
@@ -10,7 +10,7 @@ Why?
10
10
  ----
11
11
  The _vscode-json-languageservice_ contains the language smarts behind the JSON editing experience of Visual Studio Code
12
12
  and the Monaco editor.
13
- - *doValidation* analyses an input string and returns syntax and lint errros.
13
+ - *doValidation* analyses an input string and returns syntax and lint errors.
14
14
  - *doComplete* provides completion proposals for a given location. *doResolve* resolves a completion proposal
15
15
  - *doResolve* resolves a completion proposals.
16
16
  - *doHover* provides a hover text for a given location.
@@ -19,6 +19,7 @@ and the Monaco editor.
19
19
  - *format* formats the code at the given range.
20
20
  - *getFoldingRanges* gets folding ranges for the given document
21
21
  - *getSelectionRanges* gets selection ranges for a given location.
22
+ - *getMatchingSchemas* matches a document against its schema and returns all AST nodes along with the matching sub schemas
22
23
 
23
24
  - use *parseJSONDocument* create a JSON document from source code, or *newJSONDocument* to create the document from an AST.
24
25
 
@@ -1,5 +1,8 @@
1
- import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink } from './jsonLanguageTypes';
2
- export declare type JSONDocument = {};
1
+ import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema } from './jsonLanguageTypes';
2
+ export declare type JSONDocument = {
3
+ root: ASTNode | undefined;
4
+ getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
5
+ };
3
6
  export * from './jsonLanguageTypes';
4
7
  export interface LanguageService {
5
8
  configure(settings: LanguageSettings): void;
@@ -7,6 +10,7 @@ export interface LanguageService {
7
10
  parseJSONDocument(document: TextDocument): JSONDocument;
8
11
  newJSONDocument(rootNode: ASTNode, syntaxDiagnostics?: Diagnostic[]): JSONDocument;
9
12
  resetSchema(uri: string): boolean;
13
+ getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): Thenable<MatchingSchema[]>;
10
14
  doResolve(item: CompletionItem): Thenable<CompletionItem>;
11
15
  doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable<CompletionList | null>;
12
16
  findDocumentSymbols(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): SymbolInformation[];
@@ -37,6 +37,7 @@ export function getLanguageService(params) {
37
37
  doValidation: jsonValidation.doValidation.bind(jsonValidation),
38
38
  parseJSONDocument: function (document) { return parseJSON(document, { collectComments: true }); },
39
39
  newJSONDocument: function (root, diagnostics) { return newJSONDocument(root, diagnostics); },
40
+ getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
40
41
  doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
41
42
  doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
42
43
  findDocumentSymbols: jsonDocumentSymbols.findDocumentSymbols.bind(jsonDocumentSymbols),
@@ -1,9 +1,8 @@
1
1
  import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
2
2
  import { JSONSchema } from './jsonSchema';
3
- import { MarkupKind } from 'vscode-languageserver-types';
4
- export { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, JSONSchema };
5
- export { TextDocument } from 'vscode-languageserver-textdocument';
6
- export * from 'vscode-languageserver-types';
3
+ import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, Position, InsertTextFormat, MarkupContent, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions, DefinitionLink } from 'vscode-languageserver-types';
4
+ import { TextDocument } from 'vscode-languageserver-textdocument';
5
+ export { TextDocument, Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, Position, InsertTextFormat, MarkupContent, MarkupKind, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions };
7
6
  /**
8
7
  * Error codes used by diagnostics
9
8
  */
@@ -70,6 +69,10 @@ export interface NullASTNode extends BaseASTNode {
70
69
  readonly type: 'null';
71
70
  readonly value: null;
72
71
  }
72
+ export interface MatchingSchema {
73
+ node: ASTNode;
74
+ schema: JSONSchema;
75
+ }
73
76
  export interface LanguageSettings {
74
77
  /**
75
78
  * If set, the validator will return syntax and semantic errors.
@@ -1,6 +1,10 @@
1
- import { MarkupKind } from 'vscode-languageserver-types';
2
- export { TextDocument } from 'vscode-languageserver-textdocument';
3
- export * from 'vscode-languageserver-types';
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, Position, InsertTextFormat, MarkupContent, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions } from 'vscode-languageserver-types';
6
+ import { TextDocument } from 'vscode-languageserver-textdocument';
7
+ export { TextDocument, Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, Position, InsertTextFormat, MarkupContent, MarkupKind, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions };
4
8
  /**
5
9
  * Error codes used by diagnostics
6
10
  */
@@ -38,7 +38,7 @@ var ASTNodeImpl = /** @class */ (function () {
38
38
  get: function () {
39
39
  return [];
40
40
  },
41
- enumerable: true,
41
+ enumerable: false,
42
42
  configurable: true
43
43
  });
44
44
  ASTNodeImpl.prototype.toString = function () {
@@ -81,7 +81,7 @@ var ArrayASTNodeImpl = /** @class */ (function (_super) {
81
81
  get: function () {
82
82
  return this.items;
83
83
  },
84
- enumerable: true,
84
+ enumerable: false,
85
85
  configurable: true
86
86
  });
87
87
  return ArrayASTNodeImpl;
@@ -123,7 +123,7 @@ var PropertyASTNodeImpl = /** @class */ (function (_super) {
123
123
  get: function () {
124
124
  return this.valueNode ? [this.keyNode, this.valueNode] : [this.keyNode];
125
125
  },
126
- enumerable: true,
126
+ enumerable: false,
127
127
  configurable: true
128
128
  });
129
129
  return PropertyASTNodeImpl;
@@ -141,7 +141,7 @@ var ObjectASTNodeImpl = /** @class */ (function (_super) {
141
141
  get: function () {
142
142
  return this.properties;
143
143
  },
144
- enumerable: true,
144
+ enumerable: false,
145
145
  configurable: true
146
146
  });
147
147
  return ObjectASTNodeImpl;
@@ -184,7 +184,7 @@ var NoOpSchemaCollector = /** @class */ (function () {
184
184
  }
185
185
  Object.defineProperty(NoOpSchemaCollector.prototype, "schemas", {
186
186
  get: function () { return []; },
187
- enumerable: true,
187
+ enumerable: false,
188
188
  configurable: true
189
189
  });
190
190
  NoOpSchemaCollector.prototype.add = function (schema) { };
@@ -523,8 +523,35 @@ function validate(n, schema, validationResult, matchingSchemas) {
523
523
  }
524
524
  function _validateNumberNode(node, schema, validationResult, matchingSchemas) {
525
525
  var val = node.value;
526
+ function normalizeFloats(float) {
527
+ var _a;
528
+ var parts = /^(-?\d+)(?:\.(\d+))?(?:e([-+]\d+))?$/.exec(float.toString());
529
+ return parts && {
530
+ value: Number(parts[1] + (parts[2] || '')),
531
+ multiplier: (((_a = parts[2]) === null || _a === void 0 ? void 0 : _a.length) || 0) - (parseInt(parts[3]) || 0)
532
+ };
533
+ }
534
+ ;
526
535
  if (isNumber(schema.multipleOf)) {
527
- if (val % schema.multipleOf !== 0) {
536
+ var remainder = -1;
537
+ if (Number.isInteger(schema.multipleOf)) {
538
+ remainder = val % schema.multipleOf;
539
+ }
540
+ else {
541
+ var normMultipleOf = normalizeFloats(schema.multipleOf);
542
+ var normValue = normalizeFloats(val);
543
+ if (normMultipleOf && normValue) {
544
+ var multiplier = Math.pow(10, Math.abs(normValue.multiplier - normMultipleOf.multiplier));
545
+ if (normValue.multiplier < normMultipleOf.multiplier) {
546
+ normValue.value *= multiplier;
547
+ }
548
+ else {
549
+ normMultipleOf.value *= multiplier;
550
+ }
551
+ remainder = normValue.value % normMultipleOf.value;
552
+ }
553
+ }
554
+ if (remainder !== 0) {
528
555
  validationResult.problems.push({
529
556
  location: { offset: node.offset, length: node.length },
530
557
  severity: DiagnosticSeverity.Warning,
@@ -223,6 +223,45 @@ var JSONCompletion = /** @class */ (function () {
223
223
  }
224
224
  });
225
225
  }
226
+ var schemaPropertyNames_1 = s.schema.propertyNames;
227
+ if (typeof schemaPropertyNames_1 === 'object' && !schemaPropertyNames_1.deprecationMessage && !schemaPropertyNames_1.doNotSuggest) {
228
+ var propertyNameCompletionItem = function (name, enumDescription) {
229
+ if (enumDescription === void 0) { enumDescription = undefined; }
230
+ var proposal = {
231
+ kind: CompletionItemKind.Property,
232
+ label: name,
233
+ insertText: _this.getInsertTextForProperty(name, undefined, addValue, separatorAfter),
234
+ insertTextFormat: InsertTextFormat.Snippet,
235
+ filterText: _this.getFilterTextForValue(name),
236
+ documentation: enumDescription || _this.fromMarkup(schemaPropertyNames_1.markdownDescription) || schemaPropertyNames_1.description || '',
237
+ };
238
+ if (schemaPropertyNames_1.suggestSortText !== undefined) {
239
+ proposal.sortText = schemaPropertyNames_1.suggestSortText;
240
+ }
241
+ if (proposal.insertText && endsWith(proposal.insertText, "$1" + separatorAfter)) {
242
+ proposal.command = {
243
+ title: 'Suggest',
244
+ command: 'editor.action.triggerSuggest'
245
+ };
246
+ }
247
+ collector.add(proposal);
248
+ };
249
+ if (schemaPropertyNames_1.enum) {
250
+ for (var i = 0; i < schemaPropertyNames_1.enum.length; i++) {
251
+ var enumDescription = undefined;
252
+ if (schemaPropertyNames_1.markdownEnumDescriptions && i < schemaPropertyNames_1.markdownEnumDescriptions.length) {
253
+ enumDescription = _this.fromMarkup(schemaPropertyNames_1.markdownEnumDescriptions[i]);
254
+ }
255
+ else if (schemaPropertyNames_1.enumDescriptions && i < schemaPropertyNames_1.enumDescriptions.length) {
256
+ enumDescription = schemaPropertyNames_1.enumDescriptions[i];
257
+ }
258
+ propertyNameCompletionItem(schemaPropertyNames_1.enum[i], enumDescription);
259
+ }
260
+ }
261
+ if (schemaPropertyNames_1.const) {
262
+ propertyNameCompletionItem(schemaPropertyNames_1.const);
263
+ }
264
+ }
226
265
  }
227
266
  });
228
267
  };
@@ -383,9 +422,28 @@ var JSONCompletion = /** @class */ (function () {
383
422
  this.addSchemaValueCompletions(s.schema.items, separatorAfter, collector, types);
384
423
  }
385
424
  }
386
- if (s.schema.properties && parentKey !== undefined) {
387
- var propertySchema = s.schema.properties[parentKey];
388
- if (propertySchema) {
425
+ if (parentKey !== undefined) {
426
+ var propertyMatched = false;
427
+ if (s.schema.properties) {
428
+ var propertySchema = s.schema.properties[parentKey];
429
+ if (propertySchema) {
430
+ propertyMatched = true;
431
+ this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
432
+ }
433
+ }
434
+ if (s.schema.patternProperties && !propertyMatched) {
435
+ for (var _a = 0, _b = Object.keys(s.schema.patternProperties); _a < _b.length; _a++) {
436
+ var pattern = _b[_a];
437
+ var regex = new RegExp(pattern);
438
+ if (regex.test(parentKey)) {
439
+ propertyMatched = true;
440
+ var propertySchema = s.schema.patternProperties[pattern];
441
+ this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
442
+ }
443
+ }
444
+ }
445
+ if (s.schema.additionalProperties && !propertyMatched) {
446
+ var propertySchema = s.schema.additionalProperties;
389
447
  this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
390
448
  }
391
449
  }
@@ -157,7 +157,7 @@ var JSONSchemaService = /** @class */ (function () {
157
157
  get: function () {
158
158
  return this.promiseConstructor;
159
159
  },
160
- enumerable: true,
160
+ enumerable: false,
161
161
  configurable: true
162
162
  });
163
163
  JSONSchemaService.prototype.dispose = function () {
@@ -287,7 +287,7 @@ var JSONSchemaService = /** @class */ (function () {
287
287
  return this.promise.resolve(new ResolvedSchema({}, [localize('json.schema.draft03.notsupported', "Draft-03 schemas are not supported.")]));
288
288
  }
289
289
  else if (id === 'https://json-schema.org/draft/2019-09/schema') {
290
- schemaToResolve.errors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));
290
+ resolveErrors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));
291
291
  }
292
292
  }
293
293
  var contextService = this.contextService;
@@ -406,7 +406,7 @@ var JSONSchemaService = /** @class */ (function () {
406
406
  }
407
407
  }
408
408
  }
409
- collectEntries(next.items, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
409
+ collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
410
410
  collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
411
411
  collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
412
412
  };
@@ -473,9 +473,24 @@ var JSONSchemaService = /** @class */ (function () {
473
473
  return this.addSchemaHandle(combinedSchemaId, combinedSchema);
474
474
  }
475
475
  };
476
+ JSONSchemaService.prototype.getMatchingSchemas = function (document, jsonDocument, schema) {
477
+ if (schema) {
478
+ var id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
479
+ return this.resolveSchemaContent(new UnresolvedSchema(schema), id, {}).then(function (resolvedSchema) {
480
+ return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(function (s) { return !s.inverted; });
481
+ });
482
+ }
483
+ return this.getSchemaForResource(document.uri, jsonDocument).then(function (schema) {
484
+ if (schema) {
485
+ return jsonDocument.getMatchingSchemas(schema.schema).filter(function (s) { return !s.inverted; });
486
+ }
487
+ return [];
488
+ });
489
+ };
476
490
  return JSONSchemaService;
477
491
  }());
478
492
  export { JSONSchemaService };
493
+ var idCounter = 0;
479
494
  function normalizeId(id) {
480
495
  // remove trailing '#', normalize drive capitalization
481
496
  try {
@@ -1,5 +1,8 @@
1
- import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink } from './jsonLanguageTypes';
2
- export declare type JSONDocument = {};
1
+ import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema } from './jsonLanguageTypes';
2
+ export declare type JSONDocument = {
3
+ root: ASTNode | undefined;
4
+ getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
5
+ };
3
6
  export * from './jsonLanguageTypes';
4
7
  export interface LanguageService {
5
8
  configure(settings: LanguageSettings): void;
@@ -7,6 +10,7 @@ export interface LanguageService {
7
10
  parseJSONDocument(document: TextDocument): JSONDocument;
8
11
  newJSONDocument(rootNode: ASTNode, syntaxDiagnostics?: Diagnostic[]): JSONDocument;
9
12
  resetSchema(uri: string): boolean;
13
+ getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): Thenable<MatchingSchema[]>;
10
14
  doResolve(item: CompletionItem): Thenable<CompletionItem>;
11
15
  doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable<CompletionList | null>;
12
16
  findDocumentSymbols(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): SymbolInformation[];
@@ -2,6 +2,16 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
14
+ };
5
15
  (function (factory) {
6
16
  if (typeof module === "object" && typeof module.exports === "object") {
7
17
  var v = factory(require, exports);
@@ -12,10 +22,8 @@
12
22
  }
13
23
  })(function (require, exports) {
14
24
  "use strict";
15
- function __export(m) {
16
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
17
- }
18
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getLanguageService = void 0;
19
27
  var jsonCompletion_1 = require("./services/jsonCompletion");
20
28
  var jsonHover_1 = require("./services/jsonHover");
21
29
  var jsonValidation_1 = require("./services/jsonValidation");
@@ -28,7 +36,7 @@
28
36
  var jsonc_parser_1 = require("jsonc-parser");
29
37
  var jsonLanguageTypes_1 = require("./jsonLanguageTypes");
30
38
  var jsonDefinition_1 = require("./services/jsonDefinition");
31
- __export(require("./jsonLanguageTypes"));
39
+ __exportStar(require("./jsonLanguageTypes"), exports);
32
40
  function getLanguageService(params) {
33
41
  var promise = params.promiseConstructor || Promise;
34
42
  var jsonSchemaService = new jsonSchemaService_1.JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
@@ -51,6 +59,7 @@
51
59
  doValidation: jsonValidation.doValidation.bind(jsonValidation),
52
60
  parseJSONDocument: function (document) { return jsonParser_1.parse(document, { collectComments: true }); },
53
61
  newJSONDocument: function (root, diagnostics) { return jsonParser_1.newJSONDocument(root, diagnostics); },
62
+ getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
54
63
  doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
55
64
  doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
56
65
  findDocumentSymbols: jsonDocumentSymbols.findDocumentSymbols.bind(jsonDocumentSymbols),
@@ -1,9 +1,8 @@
1
1
  import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
2
2
  import { JSONSchema } from './jsonSchema';
3
- import { MarkupKind } from 'vscode-languageserver-types';
4
- export { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, JSONSchema };
5
- export { TextDocument } from 'vscode-languageserver-textdocument';
6
- export * from 'vscode-languageserver-types';
3
+ import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, Position, InsertTextFormat, MarkupContent, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions, DefinitionLink } from 'vscode-languageserver-types';
4
+ import { TextDocument } from 'vscode-languageserver-textdocument';
5
+ export { TextDocument, Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, Position, InsertTextFormat, MarkupContent, MarkupKind, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions };
7
6
  /**
8
7
  * Error codes used by diagnostics
9
8
  */
@@ -70,6 +69,10 @@ export interface NullASTNode extends BaseASTNode {
70
69
  readonly type: 'null';
71
70
  readonly value: null;
72
71
  }
72
+ export interface MatchingSchema {
73
+ node: ASTNode;
74
+ schema: JSONSchema;
75
+ }
73
76
  export interface LanguageSettings {
74
77
  /**
75
78
  * If set, the validator will return syntax and semantic errors.
@@ -1,21 +1,46 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
1
5
  (function (factory) {
2
6
  if (typeof module === "object" && typeof module.exports === "object") {
3
7
  var v = factory(require, exports);
4
8
  if (v !== undefined) module.exports = v;
5
9
  }
6
10
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "vscode-languageserver-types", "vscode-languageserver-textdocument", "vscode-languageserver-types"], factory);
11
+ define(["require", "exports", "vscode-languageserver-types", "vscode-languageserver-textdocument"], factory);
8
12
  }
9
13
  })(function (require, exports) {
10
14
  "use strict";
11
- function __export(m) {
12
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
13
- }
14
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.ClientCapabilities = exports.ErrorCode = exports.FormattingOptions = exports.MarkedString = exports.Hover = exports.Location = exports.DocumentSymbol = exports.SymbolKind = exports.SymbolInformation = exports.MarkupKind = exports.MarkupContent = exports.InsertTextFormat = exports.Position = exports.CompletionList = exports.CompletionItemKind = exports.CompletionItem = exports.DiagnosticSeverity = exports.Diagnostic = exports.SelectionRange = exports.FoldingRangeKind = exports.FoldingRange = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.TextEdit = exports.Range = exports.TextDocument = void 0;
15
17
  var vscode_languageserver_types_1 = require("vscode-languageserver-types");
18
+ Object.defineProperty(exports, "Range", { enumerable: true, get: function () { return vscode_languageserver_types_1.Range; } });
19
+ Object.defineProperty(exports, "TextEdit", { enumerable: true, get: function () { return vscode_languageserver_types_1.TextEdit; } });
20
+ Object.defineProperty(exports, "Color", { enumerable: true, get: function () { return vscode_languageserver_types_1.Color; } });
21
+ Object.defineProperty(exports, "ColorInformation", { enumerable: true, get: function () { return vscode_languageserver_types_1.ColorInformation; } });
22
+ Object.defineProperty(exports, "ColorPresentation", { enumerable: true, get: function () { return vscode_languageserver_types_1.ColorPresentation; } });
23
+ Object.defineProperty(exports, "FoldingRange", { enumerable: true, get: function () { return vscode_languageserver_types_1.FoldingRange; } });
24
+ Object.defineProperty(exports, "FoldingRangeKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.FoldingRangeKind; } });
25
+ Object.defineProperty(exports, "MarkupKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkupKind; } });
26
+ Object.defineProperty(exports, "SelectionRange", { enumerable: true, get: function () { return vscode_languageserver_types_1.SelectionRange; } });
27
+ Object.defineProperty(exports, "Diagnostic", { enumerable: true, get: function () { return vscode_languageserver_types_1.Diagnostic; } });
28
+ Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return vscode_languageserver_types_1.DiagnosticSeverity; } });
29
+ Object.defineProperty(exports, "CompletionItem", { enumerable: true, get: function () { return vscode_languageserver_types_1.CompletionItem; } });
30
+ Object.defineProperty(exports, "CompletionItemKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.CompletionItemKind; } });
31
+ Object.defineProperty(exports, "CompletionList", { enumerable: true, get: function () { return vscode_languageserver_types_1.CompletionList; } });
32
+ Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return vscode_languageserver_types_1.Position; } });
33
+ Object.defineProperty(exports, "InsertTextFormat", { enumerable: true, get: function () { return vscode_languageserver_types_1.InsertTextFormat; } });
34
+ Object.defineProperty(exports, "MarkupContent", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkupContent; } });
35
+ Object.defineProperty(exports, "SymbolInformation", { enumerable: true, get: function () { return vscode_languageserver_types_1.SymbolInformation; } });
36
+ Object.defineProperty(exports, "SymbolKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.SymbolKind; } });
37
+ Object.defineProperty(exports, "DocumentSymbol", { enumerable: true, get: function () { return vscode_languageserver_types_1.DocumentSymbol; } });
38
+ Object.defineProperty(exports, "Location", { enumerable: true, get: function () { return vscode_languageserver_types_1.Location; } });
39
+ Object.defineProperty(exports, "Hover", { enumerable: true, get: function () { return vscode_languageserver_types_1.Hover; } });
40
+ Object.defineProperty(exports, "MarkedString", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkedString; } });
41
+ Object.defineProperty(exports, "FormattingOptions", { enumerable: true, get: function () { return vscode_languageserver_types_1.FormattingOptions; } });
16
42
  var vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
17
- exports.TextDocument = vscode_languageserver_textdocument_1.TextDocument;
18
- __export(require("vscode-languageserver-types"));
43
+ Object.defineProperty(exports, "TextDocument", { enumerable: true, get: function () { return vscode_languageserver_textdocument_1.TextDocument; } });
19
44
  /**
20
45
  * Error codes used by diagnostics
21
46
  */
@@ -26,6 +26,7 @@ var __extends = (this && this.__extends) || (function () {
26
26
  })(function (require, exports) {
27
27
  "use strict";
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.parse = exports.JSONDocument = exports.contains = exports.getNodePath = exports.getNodeValue = exports.newJSONDocument = exports.ValidationResult = exports.EnumMatch = exports.asSchema = exports.ObjectASTNodeImpl = exports.PropertyASTNodeImpl = exports.StringASTNodeImpl = exports.NumberASTNodeImpl = exports.ArrayASTNodeImpl = exports.BooleanASTNodeImpl = exports.NullASTNodeImpl = exports.ASTNodeImpl = void 0;
29
30
  var Json = require("jsonc-parser");
30
31
  var objects_1 = require("../utils/objects");
31
32
  var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
@@ -49,7 +50,7 @@ var __extends = (this && this.__extends) || (function () {
49
50
  get: function () {
50
51
  return [];
51
52
  },
52
- enumerable: true,
53
+ enumerable: false,
53
54
  configurable: true
54
55
  });
55
56
  ASTNodeImpl.prototype.toString = function () {
@@ -92,7 +93,7 @@ var __extends = (this && this.__extends) || (function () {
92
93
  get: function () {
93
94
  return this.items;
94
95
  },
95
- enumerable: true,
96
+ enumerable: false,
96
97
  configurable: true
97
98
  });
98
99
  return ArrayASTNodeImpl;
@@ -134,7 +135,7 @@ var __extends = (this && this.__extends) || (function () {
134
135
  get: function () {
135
136
  return this.valueNode ? [this.keyNode, this.valueNode] : [this.keyNode];
136
137
  },
137
- enumerable: true,
138
+ enumerable: false,
138
139
  configurable: true
139
140
  });
140
141
  return PropertyASTNodeImpl;
@@ -152,7 +153,7 @@ var __extends = (this && this.__extends) || (function () {
152
153
  get: function () {
153
154
  return this.properties;
154
155
  },
155
- enumerable: true,
156
+ enumerable: false,
156
157
  configurable: true
157
158
  });
158
159
  return ObjectASTNodeImpl;
@@ -196,7 +197,7 @@ var __extends = (this && this.__extends) || (function () {
196
197
  }
197
198
  Object.defineProperty(NoOpSchemaCollector.prototype, "schemas", {
198
199
  get: function () { return []; },
199
- enumerable: true,
200
+ enumerable: false,
200
201
  configurable: true
201
202
  });
202
203
  NoOpSchemaCollector.prototype.add = function (schema) { };
@@ -539,8 +540,35 @@ var __extends = (this && this.__extends) || (function () {
539
540
  }
540
541
  function _validateNumberNode(node, schema, validationResult, matchingSchemas) {
541
542
  var val = node.value;
543
+ function normalizeFloats(float) {
544
+ var _a;
545
+ var parts = /^(-?\d+)(?:\.(\d+))?(?:e([-+]\d+))?$/.exec(float.toString());
546
+ return parts && {
547
+ value: Number(parts[1] + (parts[2] || '')),
548
+ multiplier: (((_a = parts[2]) === null || _a === void 0 ? void 0 : _a.length) || 0) - (parseInt(parts[3]) || 0)
549
+ };
550
+ }
551
+ ;
542
552
  if (objects_1.isNumber(schema.multipleOf)) {
543
- if (val % schema.multipleOf !== 0) {
553
+ var remainder = -1;
554
+ if (Number.isInteger(schema.multipleOf)) {
555
+ remainder = val % schema.multipleOf;
556
+ }
557
+ else {
558
+ var normMultipleOf = normalizeFloats(schema.multipleOf);
559
+ var normValue = normalizeFloats(val);
560
+ if (normMultipleOf && normValue) {
561
+ var multiplier = Math.pow(10, Math.abs(normValue.multiplier - normMultipleOf.multiplier));
562
+ if (normValue.multiplier < normMultipleOf.multiplier) {
563
+ normValue.value *= multiplier;
564
+ }
565
+ else {
566
+ normMultipleOf.value *= multiplier;
567
+ }
568
+ remainder = normValue.value % normMultipleOf.value;
569
+ }
570
+ }
571
+ if (remainder !== 0) {
544
572
  validationResult.problems.push({
545
573
  location: { offset: node.offset, length: node.length },
546
574
  severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
@@ -13,6 +13,7 @@
13
13
  })(function (require, exports) {
14
14
  "use strict";
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.schemaContributions = void 0;
16
17
  var nls = require("vscode-nls");
17
18
  var localize = nls.loadMessageBundle();
18
19
  exports.schemaContributions = {