vscode-json-languageservice 3.1.7 → 3.2.1
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.
- package/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/lib/esm/jsonLanguageService.js +1 -1
- package/lib/esm/jsonLanguageTypes.d.ts +44 -1
- package/lib/esm/jsonLanguageTypes.js +13 -1
- package/lib/esm/jsonSchema.d.ts +2 -0
- package/lib/esm/parser/jsonParser.js +89 -73
- package/lib/esm/services/configuration.js +374 -98
- package/lib/esm/services/jsonCompletion.js +56 -19
- package/lib/esm/services/jsonSchemaService.js +22 -17
- package/lib/esm/utils/objects.js +12 -0
- package/lib/umd/jsonLanguageService.js +1 -1
- package/lib/umd/jsonLanguageTypes.d.ts +44 -1
- package/lib/umd/jsonLanguageTypes.js +12 -0
- package/lib/umd/jsonSchema.d.ts +2 -0
- package/lib/umd/parser/jsonParser.js +89 -73
- package/lib/umd/services/configuration.js +374 -98
- package/lib/umd/services/jsonCompletion.js +62 -25
- package/lib/umd/services/jsonSchemaService.js +22 -17
- package/lib/umd/utils/objects.js +16 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
3.2.0 / 2018-09-27
|
|
2
|
+
==================
|
|
3
|
+
* New API `LanguageServiceParams.ClientCapabilities` to define what LSP capabilities the client supports.
|
|
4
|
+
* For the best experiences, clients should always use `LanguageServiceParams.ClientCapabilities.LATEST`, which has all the latest LSP cpabilities enabled.
|
|
5
|
+
* `LanguageServiceParams.ClientCapabilities` can allow `MarkupKind.Markdown` as valid documentationFormat (used by completions if schemas use `markdownDescription` or `markdownEnumDescriptions`).
|
|
6
|
+
* snippets can now provide the description also in markdown format.
|
|
7
|
+
* Bundled draft-07-schema with descriptions.
|
|
8
|
+
* Propose `examples` in code completions.
|
|
9
|
+
|
|
1
10
|
3.1.5 / 2018-08-14
|
|
2
11
|
==================
|
|
3
12
|
* support for JSON schema draft-07
|
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ JSON language service extracted from VSCode to be reused, e.g in the Monaco edit
|
|
|
4
4
|
[](https://www.npmjs.org/package/vscode-json-languageservice)
|
|
5
5
|
[](https://npmjs.org/package/vscode-json-languageservice)
|
|
6
6
|
[](https://travis-ci.org/Microsoft/vscode-json-languageservice)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
8
|
|
|
8
9
|
Why?
|
|
9
10
|
----
|
|
@@ -19,7 +19,7 @@ export function getLanguageService(params) {
|
|
|
19
19
|
var promise = params.promiseConstructor || Promise;
|
|
20
20
|
var jsonSchemaService = new JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
|
|
21
21
|
jsonSchemaService.setSchemaContributions(schemaContributions);
|
|
22
|
-
var jsonCompletion = new JSONCompletion(jsonSchemaService, params.contributions, promise);
|
|
22
|
+
var jsonCompletion = new JSONCompletion(jsonSchemaService, params.contributions, promise, params.clientCapabilities);
|
|
23
23
|
var jsonHover = new JSONHover(jsonSchemaService, params.contributions, promise);
|
|
24
24
|
var jsonDocumentSymbols = new JSONDocumentSymbols(jsonSchemaService);
|
|
25
25
|
var jsonValidation = new JSONValidation(jsonSchemaService, promise);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
|
|
2
2
|
import { JSONSchema } from './jsonSchema';
|
|
3
|
-
import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind } from 'vscode-languageserver-types';
|
|
3
|
+
import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind } from 'vscode-languageserver-types';
|
|
4
4
|
export { Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind };
|
|
5
5
|
/**
|
|
6
6
|
* Error codes used by diagnostics
|
|
@@ -175,4 +175,47 @@ export interface LanguageServiceParams {
|
|
|
175
175
|
* A promise constructor. If not set, the ES5 Promise will be used.
|
|
176
176
|
*/
|
|
177
177
|
promiseConstructor?: PromiseConstructor;
|
|
178
|
+
/**
|
|
179
|
+
* Describes the LSP capabilities the client supports.
|
|
180
|
+
*/
|
|
181
|
+
clientCapabilities?: ClientCapabilities;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Describes what LSP capabilities the client supports
|
|
185
|
+
*/
|
|
186
|
+
export interface ClientCapabilities {
|
|
187
|
+
/**
|
|
188
|
+
* The text document client capabilities
|
|
189
|
+
*/
|
|
190
|
+
textDocument?: {
|
|
191
|
+
/**
|
|
192
|
+
* Capabilities specific to completions.
|
|
193
|
+
*/
|
|
194
|
+
completion?: {
|
|
195
|
+
/**
|
|
196
|
+
* The client supports the following `CompletionItem` specific
|
|
197
|
+
* capabilities.
|
|
198
|
+
*/
|
|
199
|
+
completionItem?: {
|
|
200
|
+
/**
|
|
201
|
+
* Client supports the follow content formats for the documentation
|
|
202
|
+
* property. The order describes the preferred format of the client.
|
|
203
|
+
*/
|
|
204
|
+
documentationFormat?: MarkupKind[];
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Capabilities specific to hovers.
|
|
209
|
+
*/
|
|
210
|
+
hover?: {
|
|
211
|
+
/**
|
|
212
|
+
* Client supports the follow content formats for the content
|
|
213
|
+
* property. The order describes the preferred format of the client.
|
|
214
|
+
*/
|
|
215
|
+
contentFormat?: MarkupKind[];
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export declare namespace ClientCapabilities {
|
|
220
|
+
const LATEST: ClientCapabilities;
|
|
178
221
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
'use strict';
|
|
6
|
-
import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind } from 'vscode-languageserver-types';
|
|
6
|
+
import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind } from 'vscode-languageserver-types';
|
|
7
7
|
export { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind };
|
|
8
8
|
/**
|
|
9
9
|
* Error codes used by diagnostics
|
|
@@ -29,4 +29,16 @@ export var ErrorCode;
|
|
|
29
29
|
ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
|
|
30
30
|
ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
|
|
31
31
|
})(ErrorCode || (ErrorCode = {}));
|
|
32
|
+
export var ClientCapabilities;
|
|
33
|
+
(function (ClientCapabilities) {
|
|
34
|
+
ClientCapabilities.LATEST = {
|
|
35
|
+
textDocument: {
|
|
36
|
+
completion: {
|
|
37
|
+
completionItem: {
|
|
38
|
+
documentationFormat: [MarkupKind.Markdown, MarkupKind.PlainText]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
})(ClientCapabilities || (ClientCapabilities = {}));
|
|
32
44
|
//# sourceMappingURL=jsonLanguageTypes.js.map
|
package/lib/esm/jsonSchema.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export interface JSONSchema {
|
|
|
42
42
|
const?: any;
|
|
43
43
|
contains?: JSONSchemaRef;
|
|
44
44
|
propertyNames?: JSONSchemaRef;
|
|
45
|
+
examples?: any[];
|
|
45
46
|
$comment?: string;
|
|
46
47
|
if?: JSONSchemaRef;
|
|
47
48
|
then?: JSONSchemaRef;
|
|
@@ -49,6 +50,7 @@ export interface JSONSchema {
|
|
|
49
50
|
defaultSnippets?: {
|
|
50
51
|
label?: string;
|
|
51
52
|
description?: string;
|
|
53
|
+
markdownDescription?: string;
|
|
52
54
|
body?: any;
|
|
53
55
|
bodyText?: string;
|
|
54
56
|
}[];
|
|
@@ -17,7 +17,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
};
|
|
18
18
|
})();
|
|
19
19
|
import * as Json from 'jsonc-parser';
|
|
20
|
-
import
|
|
20
|
+
import { isNumber, equals, isBoolean, isString, isDefined } from '../utils/objects';
|
|
21
21
|
import { ErrorCode } from '../jsonLanguageTypes';
|
|
22
22
|
import * as nls from 'vscode-nls';
|
|
23
23
|
import Uri from 'vscode-uri';
|
|
@@ -144,7 +144,7 @@ var ObjectASTNodeImpl = /** @class */ (function (_super) {
|
|
|
144
144
|
}(ASTNodeImpl));
|
|
145
145
|
export { ObjectASTNodeImpl };
|
|
146
146
|
export function asSchema(schema) {
|
|
147
|
-
if (
|
|
147
|
+
if (isBoolean(schema)) {
|
|
148
148
|
return schema ? {} : { "not": {} };
|
|
149
149
|
}
|
|
150
150
|
return schema;
|
|
@@ -205,10 +205,10 @@ var ValidationResult = /** @class */ (function () {
|
|
|
205
205
|
return !!this.problems.length;
|
|
206
206
|
};
|
|
207
207
|
ValidationResult.prototype.mergeAll = function (validationResults) {
|
|
208
|
-
var
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
208
|
+
for (var _i = 0, validationResults_1 = validationResults; _i < validationResults_1.length; _i++) {
|
|
209
|
+
var validationResult = validationResults_1[_i];
|
|
210
|
+
this.merge(validationResult);
|
|
211
|
+
}
|
|
212
212
|
};
|
|
213
213
|
ValidationResult.prototype.merge = function (validationResult) {
|
|
214
214
|
this.problems = this.problems.concat(validationResult.problems);
|
|
@@ -365,9 +365,10 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
if (Array.isArray(schema.allOf)) {
|
|
368
|
-
schema.allOf.
|
|
368
|
+
for (var _i = 0, _a = schema.allOf; _i < _a.length; _i++) {
|
|
369
|
+
var subSchemaRef = _a[_i];
|
|
369
370
|
validate(node, asSchema(subSchemaRef), validationResult, matchingSchemas);
|
|
370
|
-
}
|
|
371
|
+
}
|
|
371
372
|
}
|
|
372
373
|
var notSchema = asSchema(schema.not);
|
|
373
374
|
if (notSchema) {
|
|
@@ -381,16 +382,18 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
381
382
|
message: localize('notSchemaWarning', "Matches a schema that is not allowed.")
|
|
382
383
|
});
|
|
383
384
|
}
|
|
384
|
-
subMatchingSchemas.schemas.
|
|
385
|
+
for (var _b = 0, _c = subMatchingSchemas.schemas; _b < _c.length; _b++) {
|
|
386
|
+
var ms = _c[_b];
|
|
385
387
|
ms.inverted = !ms.inverted;
|
|
386
388
|
matchingSchemas.add(ms);
|
|
387
|
-
}
|
|
389
|
+
}
|
|
388
390
|
}
|
|
389
391
|
var testAlternatives = function (alternatives, maxOneMatch) {
|
|
390
392
|
var matches = [];
|
|
391
393
|
// remember the best match that is used for error messages
|
|
392
394
|
var bestMatch = null;
|
|
393
|
-
alternatives.
|
|
395
|
+
for (var _i = 0, alternatives_1 = alternatives; _i < alternatives_1.length; _i++) {
|
|
396
|
+
var subSchemaRef = alternatives_1[_i];
|
|
394
397
|
var subSchema = asSchema(subSchemaRef);
|
|
395
398
|
var subValidationResult = new ValidationResult();
|
|
396
399
|
var subMatchingSchemas = matchingSchemas.newSub();
|
|
@@ -421,7 +424,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
421
424
|
}
|
|
422
425
|
}
|
|
423
426
|
}
|
|
424
|
-
}
|
|
427
|
+
}
|
|
425
428
|
if (matches.length > 1 && maxOneMatch) {
|
|
426
429
|
validationResult.problems.push({
|
|
427
430
|
location: { offset: node.offset, length: 1 },
|
|
@@ -444,10 +447,9 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
444
447
|
testAlternatives(schema.oneOf, true);
|
|
445
448
|
}
|
|
446
449
|
var testBranch = function (schema) {
|
|
447
|
-
var subSchema = asSchema(schema);
|
|
448
450
|
var subValidationResult = new ValidationResult();
|
|
449
451
|
var subMatchingSchemas = matchingSchemas.newSub();
|
|
450
|
-
validate(node,
|
|
452
|
+
validate(node, asSchema(schema), subValidationResult, subMatchingSchemas);
|
|
451
453
|
validationResult.merge(subValidationResult);
|
|
452
454
|
validationResult.propertiesMatches += subValidationResult.propertiesMatches;
|
|
453
455
|
validationResult.propertiesValueMatches += subValidationResult.propertiesValueMatches;
|
|
@@ -458,6 +460,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
458
460
|
var subValidationResult = new ValidationResult();
|
|
459
461
|
var subMatchingSchemas = matchingSchemas.newSub();
|
|
460
462
|
validate(node, subSchema, subValidationResult, subMatchingSchemas);
|
|
463
|
+
matchingSchemas.merge(subMatchingSchemas);
|
|
461
464
|
if (!subValidationResult.hasProblems()) {
|
|
462
465
|
if (thenSchema) {
|
|
463
466
|
testBranch(thenSchema);
|
|
@@ -467,15 +470,16 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
467
470
|
testBranch(elseSchema);
|
|
468
471
|
}
|
|
469
472
|
};
|
|
470
|
-
|
|
471
|
-
|
|
473
|
+
var ifSchema = asSchema(schema.if);
|
|
474
|
+
if (ifSchema) {
|
|
475
|
+
testCondition(ifSchema, asSchema(schema.then), asSchema(schema.else));
|
|
472
476
|
}
|
|
473
477
|
if (Array.isArray(schema.enum)) {
|
|
474
478
|
var val = getNodeValue(node);
|
|
475
479
|
var enumValueMatch = false;
|
|
476
|
-
for (var
|
|
477
|
-
var e =
|
|
478
|
-
if (
|
|
480
|
+
for (var _d = 0, _e = schema.enum; _d < _e.length; _d++) {
|
|
481
|
+
var e = _e[_d];
|
|
482
|
+
if (equals(val, e)) {
|
|
479
483
|
enumValueMatch = true;
|
|
480
484
|
break;
|
|
481
485
|
}
|
|
@@ -491,9 +495,9 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
491
495
|
});
|
|
492
496
|
}
|
|
493
497
|
}
|
|
494
|
-
if (schema.const) {
|
|
498
|
+
if (isDefined(schema.const)) {
|
|
495
499
|
var val = getNodeValue(node);
|
|
496
|
-
if (!
|
|
500
|
+
if (!equals(val, schema.const)) {
|
|
497
501
|
validationResult.problems.push({
|
|
498
502
|
location: { offset: node.offset, length: node.length },
|
|
499
503
|
severity: DiagnosticSeverity.Warning,
|
|
@@ -517,7 +521,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
517
521
|
}
|
|
518
522
|
function _validateNumberNode(node, schema, validationResult, matchingSchemas) {
|
|
519
523
|
var val = node.value;
|
|
520
|
-
if (
|
|
524
|
+
if (isNumber(schema.multipleOf)) {
|
|
521
525
|
if (val % schema.multipleOf !== 0) {
|
|
522
526
|
validationResult.problems.push({
|
|
523
527
|
location: { offset: node.offset, length: node.length },
|
|
@@ -527,22 +531,22 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
527
531
|
}
|
|
528
532
|
}
|
|
529
533
|
function getExclusiveLimit(limit, exclusive) {
|
|
530
|
-
if (
|
|
534
|
+
if (isNumber(exclusive)) {
|
|
531
535
|
return exclusive;
|
|
532
536
|
}
|
|
533
|
-
if (
|
|
537
|
+
if (isBoolean(exclusive) && exclusive) {
|
|
534
538
|
return limit;
|
|
535
539
|
}
|
|
536
540
|
return void 0;
|
|
537
541
|
}
|
|
538
542
|
function getLimit(limit, exclusive) {
|
|
539
|
-
if (
|
|
543
|
+
if (!isBoolean(exclusive) || !exclusive) {
|
|
540
544
|
return limit;
|
|
541
545
|
}
|
|
542
546
|
return void 0;
|
|
543
547
|
}
|
|
544
548
|
var exclusiveMinimum = getExclusiveLimit(schema.minimum, schema.exclusiveMinimum);
|
|
545
|
-
if (
|
|
549
|
+
if (isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
|
|
546
550
|
validationResult.problems.push({
|
|
547
551
|
location: { offset: node.offset, length: node.length },
|
|
548
552
|
severity: DiagnosticSeverity.Warning,
|
|
@@ -550,7 +554,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
550
554
|
});
|
|
551
555
|
}
|
|
552
556
|
var exclusiveMaximum = getExclusiveLimit(schema.maximum, schema.exclusiveMaximum);
|
|
553
|
-
if (
|
|
557
|
+
if (isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
|
|
554
558
|
validationResult.problems.push({
|
|
555
559
|
location: { offset: node.offset, length: node.length },
|
|
556
560
|
severity: DiagnosticSeverity.Warning,
|
|
@@ -558,7 +562,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
558
562
|
});
|
|
559
563
|
}
|
|
560
564
|
var minimum = getLimit(schema.minimum, schema.exclusiveMinimum);
|
|
561
|
-
if (
|
|
565
|
+
if (isNumber(minimum) && val < minimum) {
|
|
562
566
|
validationResult.problems.push({
|
|
563
567
|
location: { offset: node.offset, length: node.length },
|
|
564
568
|
severity: DiagnosticSeverity.Warning,
|
|
@@ -566,7 +570,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
566
570
|
});
|
|
567
571
|
}
|
|
568
572
|
var maximum = getLimit(schema.maximum, schema.exclusiveMaximum);
|
|
569
|
-
if (
|
|
573
|
+
if (isNumber(maximum) && val > maximum) {
|
|
570
574
|
validationResult.problems.push({
|
|
571
575
|
location: { offset: node.offset, length: node.length },
|
|
572
576
|
severity: DiagnosticSeverity.Warning,
|
|
@@ -575,21 +579,21 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
575
579
|
}
|
|
576
580
|
}
|
|
577
581
|
function _validateStringNode(node, schema, validationResult, matchingSchemas) {
|
|
578
|
-
if (schema.minLength && node.value.length < schema.minLength) {
|
|
582
|
+
if (isNumber(schema.minLength) && node.value.length < schema.minLength) {
|
|
579
583
|
validationResult.problems.push({
|
|
580
584
|
location: { offset: node.offset, length: node.length },
|
|
581
585
|
severity: DiagnosticSeverity.Warning,
|
|
582
586
|
message: localize('minLengthWarning', 'String is shorter than the minimum length of {0}.', schema.minLength)
|
|
583
587
|
});
|
|
584
588
|
}
|
|
585
|
-
if (schema.maxLength && node.value.length > schema.maxLength) {
|
|
589
|
+
if (isNumber(schema.maxLength) && node.value.length > schema.maxLength) {
|
|
586
590
|
validationResult.problems.push({
|
|
587
591
|
location: { offset: node.offset, length: node.length },
|
|
588
592
|
severity: DiagnosticSeverity.Warning,
|
|
589
593
|
message: localize('maxLengthWarning', 'String is longer than the maximum length of {0}.', schema.maxLength)
|
|
590
594
|
});
|
|
591
595
|
}
|
|
592
|
-
if (schema.pattern) {
|
|
596
|
+
if (isString(schema.pattern)) {
|
|
593
597
|
var regex = new RegExp(schema.pattern);
|
|
594
598
|
if (!regex.test(node.value)) {
|
|
595
599
|
validationResult.problems.push({
|
|
@@ -656,8 +660,9 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
656
660
|
}
|
|
657
661
|
function _validateArrayNode(node, schema, validationResult, matchingSchemas) {
|
|
658
662
|
if (Array.isArray(schema.items)) {
|
|
659
|
-
var
|
|
660
|
-
|
|
663
|
+
var subSchemas = schema.items;
|
|
664
|
+
for (var index = 0; index < subSchemas.length; index++) {
|
|
665
|
+
var subSchemaRef = subSchemas[index];
|
|
661
666
|
var subSchema = asSchema(subSchemaRef);
|
|
662
667
|
var itemValidationResult = new ValidationResult();
|
|
663
668
|
var item = node.items[index];
|
|
@@ -665,13 +670,13 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
665
670
|
validate(item, subSchema, itemValidationResult, matchingSchemas);
|
|
666
671
|
validationResult.mergePropertyMatch(itemValidationResult);
|
|
667
672
|
}
|
|
668
|
-
else if (node.items.length >=
|
|
673
|
+
else if (node.items.length >= subSchemas.length) {
|
|
669
674
|
validationResult.propertiesValueMatches++;
|
|
670
675
|
}
|
|
671
|
-
}
|
|
672
|
-
if (node.items.length >
|
|
676
|
+
}
|
|
677
|
+
if (node.items.length > subSchemas.length) {
|
|
673
678
|
if (typeof schema.additionalItems === 'object') {
|
|
674
|
-
for (var i =
|
|
679
|
+
for (var i = subSchemas.length; i < node.items.length; i++) {
|
|
675
680
|
var itemValidationResult = new ValidationResult();
|
|
676
681
|
validate(node.items[i], schema.additionalItems, itemValidationResult, matchingSchemas);
|
|
677
682
|
validationResult.mergePropertyMatch(itemValidationResult);
|
|
@@ -681,19 +686,20 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
681
686
|
validationResult.problems.push({
|
|
682
687
|
location: { offset: node.offset, length: node.length },
|
|
683
688
|
severity: DiagnosticSeverity.Warning,
|
|
684
|
-
message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer.',
|
|
689
|
+
message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer.', subSchemas.length)
|
|
685
690
|
});
|
|
686
691
|
}
|
|
687
692
|
}
|
|
688
693
|
}
|
|
689
694
|
else {
|
|
690
|
-
var
|
|
691
|
-
if (
|
|
692
|
-
node.items.
|
|
695
|
+
var itemSchema = asSchema(schema.items);
|
|
696
|
+
if (itemSchema) {
|
|
697
|
+
for (var _i = 0, _a = node.items; _i < _a.length; _i++) {
|
|
698
|
+
var item = _a[_i];
|
|
693
699
|
var itemValidationResult = new ValidationResult();
|
|
694
|
-
validate(item,
|
|
700
|
+
validate(item, itemSchema, itemValidationResult, matchingSchemas);
|
|
695
701
|
validationResult.mergePropertyMatch(itemValidationResult);
|
|
696
|
-
}
|
|
702
|
+
}
|
|
697
703
|
}
|
|
698
704
|
}
|
|
699
705
|
var containsSchema = asSchema(schema.contains);
|
|
@@ -711,14 +717,14 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
711
717
|
});
|
|
712
718
|
}
|
|
713
719
|
}
|
|
714
|
-
if (schema.minItems && node.items.length < schema.minItems) {
|
|
720
|
+
if (isNumber(schema.minItems) && node.items.length < schema.minItems) {
|
|
715
721
|
validationResult.problems.push({
|
|
716
722
|
location: { offset: node.offset, length: node.length },
|
|
717
723
|
severity: DiagnosticSeverity.Warning,
|
|
718
724
|
message: localize('minItemsWarning', 'Array has too few items. Expected {0} or more.', schema.minItems)
|
|
719
725
|
});
|
|
720
726
|
}
|
|
721
|
-
if (schema.maxItems && node.items.length > schema.maxItems) {
|
|
727
|
+
if (isNumber(schema.maxItems) && node.items.length > schema.maxItems) {
|
|
722
728
|
validationResult.problems.push({
|
|
723
729
|
location: { offset: node.offset, length: node.length },
|
|
724
730
|
severity: DiagnosticSeverity.Warning,
|
|
@@ -742,13 +748,15 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
742
748
|
function _validateObjectNode(node, schema, validationResult, matchingSchemas) {
|
|
743
749
|
var seenKeys = Object.create(null);
|
|
744
750
|
var unprocessedProperties = [];
|
|
745
|
-
node.properties.
|
|
746
|
-
var
|
|
747
|
-
|
|
751
|
+
for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
|
|
752
|
+
var propertyNode = _a[_i];
|
|
753
|
+
var key = propertyNode.keyNode.value;
|
|
754
|
+
seenKeys[key] = propertyNode.valueNode;
|
|
748
755
|
unprocessedProperties.push(key);
|
|
749
|
-
}
|
|
756
|
+
}
|
|
750
757
|
if (Array.isArray(schema.required)) {
|
|
751
|
-
schema.required.
|
|
758
|
+
for (var _b = 0, _c = schema.required; _b < _c.length; _b++) {
|
|
759
|
+
var propertyName = _c[_b];
|
|
752
760
|
if (!seenKeys[propertyName]) {
|
|
753
761
|
var keyNode = node.parent && node.parent.type === 'property' && node.parent.keyNode;
|
|
754
762
|
var location = keyNode ? { offset: keyNode.offset, length: keyNode.length } : { offset: node.offset, length: 1 };
|
|
@@ -758,7 +766,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
758
766
|
message: localize('MissingRequiredPropWarning', 'Missing property "{0}".', propertyName)
|
|
759
767
|
});
|
|
760
768
|
}
|
|
761
|
-
}
|
|
769
|
+
}
|
|
762
770
|
}
|
|
763
771
|
var propertyProcessed = function (prop) {
|
|
764
772
|
var index = unprocessedProperties.indexOf(prop);
|
|
@@ -768,12 +776,13 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
768
776
|
}
|
|
769
777
|
};
|
|
770
778
|
if (schema.properties) {
|
|
771
|
-
Object.keys(schema.properties).
|
|
779
|
+
for (var _d = 0, _e = Object.keys(schema.properties); _d < _e.length; _d++) {
|
|
780
|
+
var propertyName = _e[_d];
|
|
772
781
|
propertyProcessed(propertyName);
|
|
773
782
|
var propertySchema = schema.properties[propertyName];
|
|
774
783
|
var child = seenKeys[propertyName];
|
|
775
784
|
if (child) {
|
|
776
|
-
if (
|
|
785
|
+
if (isBoolean(propertySchema)) {
|
|
777
786
|
if (!propertySchema) {
|
|
778
787
|
var propertyNode = child.parent;
|
|
779
788
|
validationResult.problems.push({
|
|
@@ -793,18 +802,20 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
793
802
|
validationResult.mergePropertyMatch(propertyValidationResult);
|
|
794
803
|
}
|
|
795
804
|
}
|
|
796
|
-
}
|
|
805
|
+
}
|
|
797
806
|
}
|
|
798
807
|
if (schema.patternProperties) {
|
|
799
|
-
Object.keys(schema.patternProperties).
|
|
808
|
+
for (var _f = 0, _g = Object.keys(schema.patternProperties); _f < _g.length; _f++) {
|
|
809
|
+
var propertyPattern = _g[_f];
|
|
800
810
|
var regex = new RegExp(propertyPattern);
|
|
801
|
-
unprocessedProperties.slice(0).
|
|
811
|
+
for (var _h = 0, _j = unprocessedProperties.slice(0); _h < _j.length; _h++) {
|
|
812
|
+
var propertyName = _j[_h];
|
|
802
813
|
if (regex.test(propertyName)) {
|
|
803
814
|
propertyProcessed(propertyName);
|
|
804
815
|
var child = seenKeys[propertyName];
|
|
805
816
|
if (child) {
|
|
806
817
|
var propertySchema = schema.patternProperties[propertyPattern];
|
|
807
|
-
if (
|
|
818
|
+
if (isBoolean(propertySchema)) {
|
|
808
819
|
if (!propertySchema) {
|
|
809
820
|
var propertyNode = child.parent;
|
|
810
821
|
validationResult.problems.push({
|
|
@@ -825,22 +836,24 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
825
836
|
}
|
|
826
837
|
}
|
|
827
838
|
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
830
841
|
}
|
|
831
842
|
if (typeof schema.additionalProperties === 'object') {
|
|
832
|
-
unprocessedProperties.
|
|
843
|
+
for (var _k = 0, unprocessedProperties_1 = unprocessedProperties; _k < unprocessedProperties_1.length; _k++) {
|
|
844
|
+
var propertyName = unprocessedProperties_1[_k];
|
|
833
845
|
var child = seenKeys[propertyName];
|
|
834
846
|
if (child) {
|
|
835
847
|
var propertyValidationResult = new ValidationResult();
|
|
836
848
|
validate(child, schema.additionalProperties, propertyValidationResult, matchingSchemas);
|
|
837
849
|
validationResult.mergePropertyMatch(propertyValidationResult);
|
|
838
850
|
}
|
|
839
|
-
}
|
|
851
|
+
}
|
|
840
852
|
}
|
|
841
853
|
else if (schema.additionalProperties === false) {
|
|
842
854
|
if (unprocessedProperties.length > 0) {
|
|
843
|
-
unprocessedProperties.
|
|
855
|
+
for (var _l = 0, unprocessedProperties_2 = unprocessedProperties; _l < unprocessedProperties_2.length; _l++) {
|
|
856
|
+
var propertyName = unprocessedProperties_2[_l];
|
|
844
857
|
var child = seenKeys[propertyName];
|
|
845
858
|
if (child) {
|
|
846
859
|
var propertyNode = child.parent;
|
|
@@ -850,10 +863,10 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
850
863
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
851
864
|
});
|
|
852
865
|
}
|
|
853
|
-
}
|
|
866
|
+
}
|
|
854
867
|
}
|
|
855
868
|
}
|
|
856
|
-
if (schema.maxProperties) {
|
|
869
|
+
if (isNumber(schema.maxProperties)) {
|
|
857
870
|
if (node.properties.length > schema.maxProperties) {
|
|
858
871
|
validationResult.problems.push({
|
|
859
872
|
location: { offset: node.offset, length: node.length },
|
|
@@ -862,7 +875,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
862
875
|
});
|
|
863
876
|
}
|
|
864
877
|
}
|
|
865
|
-
if (schema.minProperties) {
|
|
878
|
+
if (isNumber(schema.minProperties)) {
|
|
866
879
|
if (node.properties.length < schema.minProperties) {
|
|
867
880
|
validationResult.problems.push({
|
|
868
881
|
location: { offset: node.offset, length: node.length },
|
|
@@ -872,12 +885,14 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
872
885
|
}
|
|
873
886
|
}
|
|
874
887
|
if (schema.dependencies) {
|
|
875
|
-
Object.keys(schema.dependencies).
|
|
888
|
+
for (var _m = 0, _o = Object.keys(schema.dependencies); _m < _o.length; _m++) {
|
|
889
|
+
var key = _o[_m];
|
|
876
890
|
var prop = seenKeys[key];
|
|
877
891
|
if (prop) {
|
|
878
892
|
var propertyDep = schema.dependencies[key];
|
|
879
893
|
if (Array.isArray(propertyDep)) {
|
|
880
|
-
propertyDep.
|
|
894
|
+
for (var _p = 0, propertyDep_1 = propertyDep; _p < propertyDep_1.length; _p++) {
|
|
895
|
+
var requiredProp = propertyDep_1[_p];
|
|
881
896
|
if (!seenKeys[requiredProp]) {
|
|
882
897
|
validationResult.problems.push({
|
|
883
898
|
location: { offset: node.offset, length: node.length },
|
|
@@ -888,7 +903,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
888
903
|
else {
|
|
889
904
|
validationResult.propertiesValueMatches++;
|
|
890
905
|
}
|
|
891
|
-
}
|
|
906
|
+
}
|
|
892
907
|
}
|
|
893
908
|
else {
|
|
894
909
|
var propertySchema = asSchema(propertyDep);
|
|
@@ -899,16 +914,17 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
899
914
|
}
|
|
900
915
|
}
|
|
901
916
|
}
|
|
902
|
-
}
|
|
917
|
+
}
|
|
903
918
|
}
|
|
904
919
|
var propertyNames = asSchema(schema.propertyNames);
|
|
905
920
|
if (propertyNames) {
|
|
906
|
-
node.properties.
|
|
921
|
+
for (var _q = 0, _r = node.properties; _q < _r.length; _q++) {
|
|
922
|
+
var f = _r[_q];
|
|
907
923
|
var key = f.keyNode;
|
|
908
924
|
if (key) {
|
|
909
925
|
validate(key, propertyNames, validationResult, NoOpSchemaCollector.instance);
|
|
910
926
|
}
|
|
911
|
-
}
|
|
927
|
+
}
|
|
912
928
|
}
|
|
913
929
|
}
|
|
914
930
|
}
|
|
@@ -1156,7 +1172,7 @@ export function parse(textDocument, config) {
|
|
|
1156
1172
|
var tokenValue = scanner.getTokenValue();
|
|
1157
1173
|
try {
|
|
1158
1174
|
var numberValue = JSON.parse(tokenValue);
|
|
1159
|
-
if (
|
|
1175
|
+
if (!isNumber(numberValue)) {
|
|
1160
1176
|
return _error(localize('InvalidNumberFormat', 'Invalid number format.'), ErrorCode.Undefined, node);
|
|
1161
1177
|
}
|
|
1162
1178
|
node.value = numberValue;
|