vscode-json-languageservice 3.8.4 → 3.10.0
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 +46 -17
- package/lib/esm/jsonLanguageService.d.ts +2 -0
- package/lib/esm/jsonLanguageService.js +3 -2
- package/lib/esm/jsonLanguageTypes.d.ts +9 -0
- package/lib/esm/jsonLanguageTypes.js +1 -0
- package/lib/esm/parser/jsonParser.js +6 -31
- package/lib/esm/services/{jsonDefinition.js → jsonLinks.js} +19 -29
- package/lib/esm/services/jsonSchemaService.js +11 -1
- package/lib/esm/services/jsonValidation.js +7 -5
- package/lib/umd/jsonLanguageService.d.ts +2 -0
- package/lib/umd/jsonLanguageService.js +4 -3
- package/lib/umd/jsonLanguageTypes.d.ts +9 -0
- package/lib/umd/jsonLanguageTypes.js +1 -0
- package/lib/umd/parser/jsonParser.js +6 -31
- package/lib/umd/services/{jsonDefinition.js → jsonLinks.js} +21 -31
- package/lib/umd/services/jsonSchemaService.js +11 -1
- package/lib/umd/services/jsonValidation.js +7 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
3.10.0 / 2020-11-03
|
|
2
|
+
=================
|
|
3
|
+
* new API `findLinks` return links for local `$ref` links. Replaces `findDefinition` which no longer returns results ( kept for API compatibility)
|
|
4
|
+
|
|
5
|
+
3.9.0 / 2020-09-28
|
|
6
|
+
=================
|
|
7
|
+
* new API `DocumentLanguageSettings.schemaValidation`. The severity of problems from schema validation. If set to 'ignore', schema validation will be skipped. If not set, 'warning' is used.
|
|
8
|
+
* new API `DocumentLanguageSettings.schemaRequest`. The severity of problems that occurred while resolving and loading schemas. If set to 'ignore', schema resolving problems are not reported. If not set, 'warning' is used.
|
|
9
|
+
|
|
1
10
|
3.8.0 / 2020-08-02
|
|
2
11
|
=================
|
|
3
12
|
* new API `LanguageService.getMatchingSchemas`. Matches a document against its schema and list all AST nodes along with the matching sub schemas.
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# vscode-json-languageservice
|
|
2
|
+
|
|
2
3
|
JSON language service extracted from VSCode to be reused, e.g in the Monaco editor.
|
|
3
4
|
|
|
4
5
|
[](https://www.npmjs.org/package/vscode-json-languageservice)
|
|
@@ -6,24 +7,52 @@ JSON language service extracted from VSCode to be reused, e.g in the Monaco edit
|
|
|
6
7
|
[](https://travis-ci.org/Microsoft/vscode-json-languageservice)
|
|
7
8
|
[](https://opensource.org/licenses/MIT)
|
|
8
9
|
|
|
9
|
-
Why?
|
|
10
|
-
|
|
10
|
+
## Why?
|
|
11
|
+
|
|
11
12
|
The _vscode-json-languageservice_ contains the language smarts behind the JSON editing experience of Visual Studio Code
|
|
12
13
|
and the Monaco editor.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
|
|
15
|
+
- _doValidation_ analyses an input string and returns syntax and lint errors.
|
|
16
|
+
- _doComplete_ provides completion proposals for a given location.
|
|
17
|
+
- _doResolve_ resolves a completion proposals.
|
|
18
|
+
- _doHover_ provides a hover text for a given location.
|
|
19
|
+
- _findDocumentSymbols_ provides all symbols in the given document.
|
|
20
|
+
- _findDocumentColors_ provides all color symbols in the given document.
|
|
21
|
+
- _getColorPresentations_ returns available color formats for a color symbol.
|
|
22
|
+
- _format_ formats the code at the given range.
|
|
23
|
+
- _getFoldingRanges_ gets folding ranges for the given document.
|
|
24
|
+
- _getSelectionRanges_ gets selection ranges for a given location.
|
|
25
|
+
- _getMatchingSchemas_ matches a document against its schema and returns all AST nodes along with the matching sub schemas.
|
|
26
|
+
- _parseJSONDocument_ creates a JSON document from source code.
|
|
27
|
+
- _newJSONDocument_ creates a JSON document from an AST.
|
|
28
|
+
|
|
29
|
+
For the complete API see [jsonLanguageService.ts](./src/jsonLanguageService.ts) and [jsonLanguageTypes.ts](./src/jsonLanguageTypes.ts)
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
28
32
|
|
|
29
33
|
npm install --save vscode-json-languageservice
|
|
34
|
+
|
|
35
|
+
## Development
|
|
36
|
+
|
|
37
|
+
git clone https://github.com/microsoft/vscode-json-languageservice
|
|
38
|
+
cd vscode-json-languageservice
|
|
39
|
+
yarn
|
|
40
|
+
|
|
41
|
+
Use `yarn test` to compile and run tests
|
|
42
|
+
|
|
43
|
+
### How can I run and debug the service?
|
|
44
|
+
|
|
45
|
+
- open the folder in VSCode.
|
|
46
|
+
- set breakpoints, e.g. in `jsonCompletion.ts`
|
|
47
|
+
- run the Unit tests from the run viewlet and wait until a breakpoint is hit:
|
|
48
|
+

|
|
49
|
+
|
|
50
|
+
### How can I run and debug the service inside an instance of VSCode?
|
|
51
|
+
|
|
52
|
+
- run VSCode out of sources setup as described here: https://github.com/Microsoft/vscode/wiki/How-to-Contribute
|
|
53
|
+
- use `yarn link vscode-json-languageservice` in `vscode/extensions/json-language-features/server` to run VSCode with the latest changes from `vscode-json-languageservice`
|
|
54
|
+
- run VSCode out of source (`vscode/scripts/code.sh|bat`) and open a `.json` file
|
|
55
|
+
- in VSCode window that is open on the `vscode-json-languageservice` sources, run command `Debug: Attach to Node process` and pick the `code-oss` process with the `json-language-features` path
|
|
56
|
+

|
|
57
|
+
- set breakpoints, e.g. in `jsonCompletion.ts`
|
|
58
|
+
- in the instance run from sources, invoke code completion in the `.json` file
|
|
@@ -1,4 +1,5 @@
|
|
|
1
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
|
+
import { DocumentLink } from 'vscode-languageserver-types';
|
|
2
3
|
export declare type JSONDocument = {
|
|
3
4
|
root: ASTNode | undefined;
|
|
4
5
|
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
|
|
@@ -24,5 +25,6 @@ export interface LanguageService {
|
|
|
24
25
|
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
25
26
|
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
26
27
|
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
28
|
+
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>;
|
|
27
29
|
}
|
|
28
30
|
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -13,7 +13,7 @@ import { getFoldingRanges } from './services/jsonFolding';
|
|
|
13
13
|
import { getSelectionRanges } from './services/jsonSelectionRanges';
|
|
14
14
|
import { format as formatJSON } from 'jsonc-parser';
|
|
15
15
|
import { Range, TextEdit } from './jsonLanguageTypes';
|
|
16
|
-
import {
|
|
16
|
+
import { findLinks } from './services/jsonLinks';
|
|
17
17
|
export * from './jsonLanguageTypes';
|
|
18
18
|
export function getLanguageService(params) {
|
|
19
19
|
var promise = params.promiseConstructor || Promise;
|
|
@@ -48,7 +48,8 @@ export function getLanguageService(params) {
|
|
|
48
48
|
doHover: jsonHover.doHover.bind(jsonHover),
|
|
49
49
|
getFoldingRanges: getFoldingRanges,
|
|
50
50
|
getSelectionRanges: getSelectionRanges,
|
|
51
|
-
findDefinition:
|
|
51
|
+
findDefinition: function () { return Promise.resolve([]); },
|
|
52
|
+
findLinks: findLinks,
|
|
52
53
|
format: function (d, r, o) {
|
|
53
54
|
var range = undefined;
|
|
54
55
|
if (r) {
|
|
@@ -9,6 +9,7 @@ export { TextDocument, Range, TextEdit, JSONSchema, JSONWorkerContribution, JSON
|
|
|
9
9
|
export declare enum ErrorCode {
|
|
10
10
|
Undefined = 0,
|
|
11
11
|
EnumValueMismatch = 1,
|
|
12
|
+
Deprecated = 2,
|
|
12
13
|
UnexpectedEndOfComment = 257,
|
|
13
14
|
UnexpectedEndOfString = 258,
|
|
14
15
|
UnexpectedEndOfNumber = 259,
|
|
@@ -98,6 +99,14 @@ export interface DocumentLanguageSettings {
|
|
|
98
99
|
* The severity of reported trailing commas. If not set, trailing commas will be reported as errors.
|
|
99
100
|
*/
|
|
100
101
|
trailingCommas?: SeverityLevel;
|
|
102
|
+
/**
|
|
103
|
+
* The severity of problems from schema validation. If set to 'ignore', schema validation will be skipped. If not set, 'warning' is used.
|
|
104
|
+
*/
|
|
105
|
+
schemaValidation?: SeverityLevel;
|
|
106
|
+
/**
|
|
107
|
+
* The severity of problems that occurred when resolving and loading schemas. If set to 'ignore', schema resolving problems are not reported. If not set, 'warning' is used.
|
|
108
|
+
*/
|
|
109
|
+
schemaRequest?: SeverityLevel;
|
|
101
110
|
}
|
|
102
111
|
export interface SchemaConfiguration {
|
|
103
112
|
/**
|
|
@@ -12,6 +12,7 @@ export var ErrorCode;
|
|
|
12
12
|
(function (ErrorCode) {
|
|
13
13
|
ErrorCode[ErrorCode["Undefined"] = 0] = "Undefined";
|
|
14
14
|
ErrorCode[ErrorCode["EnumValueMismatch"] = 1] = "EnumValueMismatch";
|
|
15
|
+
ErrorCode[ErrorCode["Deprecated"] = 2] = "Deprecated";
|
|
15
16
|
ErrorCode[ErrorCode["UnexpectedEndOfComment"] = 257] = "UnexpectedEndOfComment";
|
|
16
17
|
ErrorCode[ErrorCode["UnexpectedEndOfString"] = 258] = "UnexpectedEndOfString";
|
|
17
18
|
ErrorCode[ErrorCode["UnexpectedEndOfNumber"] = 259] = "UnexpectedEndOfNumber";
|
|
@@ -299,13 +299,15 @@ var JSONDocument = /** @class */ (function () {
|
|
|
299
299
|
doVisit_1(this.root);
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
|
-
JSONDocument.prototype.validate = function (textDocument, schema) {
|
|
302
|
+
JSONDocument.prototype.validate = function (textDocument, schema, severity) {
|
|
303
|
+
if (severity === void 0) { severity = DiagnosticSeverity.Warning; }
|
|
303
304
|
if (this.root && schema) {
|
|
304
305
|
var validationResult = new ValidationResult();
|
|
305
306
|
validate(this.root, schema, validationResult, NoOpSchemaCollector.instance);
|
|
306
307
|
return validationResult.problems.map(function (p) {
|
|
308
|
+
var _a;
|
|
307
309
|
var range = Range.create(textDocument.positionAt(p.location.offset), textDocument.positionAt(p.location.offset + p.location.length));
|
|
308
|
-
return Diagnostic.create(range, p.message, p.severity, p.code);
|
|
310
|
+
return Diagnostic.create(range, p.message, (_a = p.severity) !== null && _a !== void 0 ? _a : severity, p.code);
|
|
309
311
|
});
|
|
310
312
|
}
|
|
311
313
|
return undefined;
|
|
@@ -352,7 +354,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
352
354
|
if (!schema.type.some(matchesType)) {
|
|
353
355
|
validationResult.problems.push({
|
|
354
356
|
location: { offset: node.offset, length: node.length },
|
|
355
|
-
severity: DiagnosticSeverity.Warning,
|
|
356
357
|
message: schema.errorMessage || localize('typeArrayMismatchWarning', 'Incorrect type. Expected one of {0}.', schema.type.join(', '))
|
|
357
358
|
});
|
|
358
359
|
}
|
|
@@ -361,7 +362,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
361
362
|
if (!matchesType(schema.type)) {
|
|
362
363
|
validationResult.problems.push({
|
|
363
364
|
location: { offset: node.offset, length: node.length },
|
|
364
|
-
severity: DiagnosticSeverity.Warning,
|
|
365
365
|
message: schema.errorMessage || localize('typeMismatchWarning', 'Incorrect type. Expected "{0}".', schema.type)
|
|
366
366
|
});
|
|
367
367
|
}
|
|
@@ -380,7 +380,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
380
380
|
if (!subValidationResult.hasProblems()) {
|
|
381
381
|
validationResult.problems.push({
|
|
382
382
|
location: { offset: node.offset, length: node.length },
|
|
383
|
-
severity: DiagnosticSeverity.Warning,
|
|
384
383
|
message: localize('notSchemaWarning', "Matches a schema that is not allowed.")
|
|
385
384
|
});
|
|
386
385
|
}
|
|
@@ -430,7 +429,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
430
429
|
if (matches.length > 1 && maxOneMatch) {
|
|
431
430
|
validationResult.problems.push({
|
|
432
431
|
location: { offset: node.offset, length: 1 },
|
|
433
|
-
severity: DiagnosticSeverity.Warning,
|
|
434
432
|
message: localize('oneOfWarning', "Matches multiple schemas when only one must validate.")
|
|
435
433
|
});
|
|
436
434
|
}
|
|
@@ -491,7 +489,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
491
489
|
if (!enumValueMatch) {
|
|
492
490
|
validationResult.problems.push({
|
|
493
491
|
location: { offset: node.offset, length: node.length },
|
|
494
|
-
severity: DiagnosticSeverity.Warning,
|
|
495
492
|
code: ErrorCode.EnumValueMismatch,
|
|
496
493
|
message: schema.errorMessage || localize('enumWarning', 'Value is not accepted. Valid values: {0}.', schema.enum.map(function (v) { return JSON.stringify(v); }).join(', '))
|
|
497
494
|
});
|
|
@@ -502,7 +499,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
502
499
|
if (!equals(val, schema.const)) {
|
|
503
500
|
validationResult.problems.push({
|
|
504
501
|
location: { offset: node.offset, length: node.length },
|
|
505
|
-
severity: DiagnosticSeverity.Warning,
|
|
506
502
|
code: ErrorCode.EnumValueMismatch,
|
|
507
503
|
message: schema.errorMessage || localize('constWarning', 'Value must be {0}.', JSON.stringify(schema.const))
|
|
508
504
|
});
|
|
@@ -517,7 +513,8 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
517
513
|
validationResult.problems.push({
|
|
518
514
|
location: { offset: node.parent.offset, length: node.parent.length },
|
|
519
515
|
severity: DiagnosticSeverity.Warning,
|
|
520
|
-
message: schema.deprecationMessage
|
|
516
|
+
message: schema.deprecationMessage,
|
|
517
|
+
code: ErrorCode.Deprecated
|
|
521
518
|
});
|
|
522
519
|
}
|
|
523
520
|
}
|
|
@@ -554,7 +551,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
554
551
|
if (remainder !== 0) {
|
|
555
552
|
validationResult.problems.push({
|
|
556
553
|
location: { offset: node.offset, length: node.length },
|
|
557
|
-
severity: DiagnosticSeverity.Warning,
|
|
558
554
|
message: localize('multipleOfWarning', 'Value is not divisible by {0}.', schema.multipleOf)
|
|
559
555
|
});
|
|
560
556
|
}
|
|
@@ -578,7 +574,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
578
574
|
if (isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
|
|
579
575
|
validationResult.problems.push({
|
|
580
576
|
location: { offset: node.offset, length: node.length },
|
|
581
|
-
severity: DiagnosticSeverity.Warning,
|
|
582
577
|
message: localize('exclusiveMinimumWarning', 'Value is below the exclusive minimum of {0}.', exclusiveMinimum)
|
|
583
578
|
});
|
|
584
579
|
}
|
|
@@ -586,7 +581,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
586
581
|
if (isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
|
|
587
582
|
validationResult.problems.push({
|
|
588
583
|
location: { offset: node.offset, length: node.length },
|
|
589
|
-
severity: DiagnosticSeverity.Warning,
|
|
590
584
|
message: localize('exclusiveMaximumWarning', 'Value is above the exclusive maximum of {0}.', exclusiveMaximum)
|
|
591
585
|
});
|
|
592
586
|
}
|
|
@@ -594,7 +588,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
594
588
|
if (isNumber(minimum) && val < minimum) {
|
|
595
589
|
validationResult.problems.push({
|
|
596
590
|
location: { offset: node.offset, length: node.length },
|
|
597
|
-
severity: DiagnosticSeverity.Warning,
|
|
598
591
|
message: localize('minimumWarning', 'Value is below the minimum of {0}.', minimum)
|
|
599
592
|
});
|
|
600
593
|
}
|
|
@@ -602,7 +595,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
602
595
|
if (isNumber(maximum) && val > maximum) {
|
|
603
596
|
validationResult.problems.push({
|
|
604
597
|
location: { offset: node.offset, length: node.length },
|
|
605
|
-
severity: DiagnosticSeverity.Warning,
|
|
606
598
|
message: localize('maximumWarning', 'Value is above the maximum of {0}.', maximum)
|
|
607
599
|
});
|
|
608
600
|
}
|
|
@@ -611,14 +603,12 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
611
603
|
if (isNumber(schema.minLength) && node.value.length < schema.minLength) {
|
|
612
604
|
validationResult.problems.push({
|
|
613
605
|
location: { offset: node.offset, length: node.length },
|
|
614
|
-
severity: DiagnosticSeverity.Warning,
|
|
615
606
|
message: localize('minLengthWarning', 'String is shorter than the minimum length of {0}.', schema.minLength)
|
|
616
607
|
});
|
|
617
608
|
}
|
|
618
609
|
if (isNumber(schema.maxLength) && node.value.length > schema.maxLength) {
|
|
619
610
|
validationResult.problems.push({
|
|
620
611
|
location: { offset: node.offset, length: node.length },
|
|
621
|
-
severity: DiagnosticSeverity.Warning,
|
|
622
612
|
message: localize('maxLengthWarning', 'String is longer than the maximum length of {0}.', schema.maxLength)
|
|
623
613
|
});
|
|
624
614
|
}
|
|
@@ -627,7 +617,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
627
617
|
if (!regex.test(node.value)) {
|
|
628
618
|
validationResult.problems.push({
|
|
629
619
|
location: { offset: node.offset, length: node.length },
|
|
630
|
-
severity: DiagnosticSeverity.Warning,
|
|
631
620
|
message: schema.patternErrorMessage || schema.errorMessage || localize('patternWarning', 'String does not match the pattern of "{0}".', schema.pattern)
|
|
632
621
|
});
|
|
633
622
|
}
|
|
@@ -653,7 +642,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
653
642
|
if (errorMessage) {
|
|
654
643
|
validationResult.problems.push({
|
|
655
644
|
location: { offset: node.offset, length: node.length },
|
|
656
|
-
severity: DiagnosticSeverity.Warning,
|
|
657
645
|
message: schema.patternErrorMessage || schema.errorMessage || localize('uriFormatWarning', 'String is not a URI: {0}', errorMessage)
|
|
658
646
|
});
|
|
659
647
|
}
|
|
@@ -668,7 +656,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
668
656
|
if (!node.value || !format.pattern.exec(node.value)) {
|
|
669
657
|
validationResult.problems.push({
|
|
670
658
|
location: { offset: node.offset, length: node.length },
|
|
671
|
-
severity: DiagnosticSeverity.Warning,
|
|
672
659
|
message: schema.patternErrorMessage || schema.errorMessage || format.errorMessage
|
|
673
660
|
});
|
|
674
661
|
}
|
|
@@ -703,7 +690,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
703
690
|
else if (schema.additionalItems === false) {
|
|
704
691
|
validationResult.problems.push({
|
|
705
692
|
location: { offset: node.offset, length: node.length },
|
|
706
|
-
severity: DiagnosticSeverity.Warning,
|
|
707
693
|
message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer.', subSchemas.length)
|
|
708
694
|
});
|
|
709
695
|
}
|
|
@@ -730,7 +716,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
730
716
|
if (!doesContain) {
|
|
731
717
|
validationResult.problems.push({
|
|
732
718
|
location: { offset: node.offset, length: node.length },
|
|
733
|
-
severity: DiagnosticSeverity.Warning,
|
|
734
719
|
message: schema.errorMessage || localize('requiredItemMissingWarning', 'Array does not contain required item.')
|
|
735
720
|
});
|
|
736
721
|
}
|
|
@@ -738,14 +723,12 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
738
723
|
if (isNumber(schema.minItems) && node.items.length < schema.minItems) {
|
|
739
724
|
validationResult.problems.push({
|
|
740
725
|
location: { offset: node.offset, length: node.length },
|
|
741
|
-
severity: DiagnosticSeverity.Warning,
|
|
742
726
|
message: localize('minItemsWarning', 'Array has too few items. Expected {0} or more.', schema.minItems)
|
|
743
727
|
});
|
|
744
728
|
}
|
|
745
729
|
if (isNumber(schema.maxItems) && node.items.length > schema.maxItems) {
|
|
746
730
|
validationResult.problems.push({
|
|
747
731
|
location: { offset: node.offset, length: node.length },
|
|
748
|
-
severity: DiagnosticSeverity.Warning,
|
|
749
732
|
message: localize('maxItemsWarning', 'Array has too many items. Expected {0} or fewer.', schema.maxItems)
|
|
750
733
|
});
|
|
751
734
|
}
|
|
@@ -757,7 +740,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
757
740
|
if (duplicates) {
|
|
758
741
|
validationResult.problems.push({
|
|
759
742
|
location: { offset: node.offset, length: node.length },
|
|
760
|
-
severity: DiagnosticSeverity.Warning,
|
|
761
743
|
message: localize('uniqueItemsWarning', 'Array has duplicate items.')
|
|
762
744
|
});
|
|
763
745
|
}
|
|
@@ -780,7 +762,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
780
762
|
var location = keyNode ? { offset: keyNode.offset, length: keyNode.length } : { offset: node.offset, length: 1 };
|
|
781
763
|
validationResult.problems.push({
|
|
782
764
|
location: location,
|
|
783
|
-
severity: DiagnosticSeverity.Warning,
|
|
784
765
|
message: localize('MissingRequiredPropWarning', 'Missing property "{0}".', propertyName)
|
|
785
766
|
});
|
|
786
767
|
}
|
|
@@ -805,7 +786,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
805
786
|
var propertyNode = child.parent;
|
|
806
787
|
validationResult.problems.push({
|
|
807
788
|
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
|
|
808
|
-
severity: DiagnosticSeverity.Warning,
|
|
809
789
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
810
790
|
});
|
|
811
791
|
}
|
|
@@ -838,7 +818,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
838
818
|
var propertyNode = child.parent;
|
|
839
819
|
validationResult.problems.push({
|
|
840
820
|
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
|
|
841
|
-
severity: DiagnosticSeverity.Warning,
|
|
842
821
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
843
822
|
});
|
|
844
823
|
}
|
|
@@ -877,7 +856,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
877
856
|
var propertyNode = child.parent;
|
|
878
857
|
validationResult.problems.push({
|
|
879
858
|
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
|
|
880
|
-
severity: DiagnosticSeverity.Warning,
|
|
881
859
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
882
860
|
});
|
|
883
861
|
}
|
|
@@ -888,7 +866,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
888
866
|
if (node.properties.length > schema.maxProperties) {
|
|
889
867
|
validationResult.problems.push({
|
|
890
868
|
location: { offset: node.offset, length: node.length },
|
|
891
|
-
severity: DiagnosticSeverity.Warning,
|
|
892
869
|
message: localize('MaxPropWarning', 'Object has more properties than limit of {0}.', schema.maxProperties)
|
|
893
870
|
});
|
|
894
871
|
}
|
|
@@ -897,7 +874,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
897
874
|
if (node.properties.length < schema.minProperties) {
|
|
898
875
|
validationResult.problems.push({
|
|
899
876
|
location: { offset: node.offset, length: node.length },
|
|
900
|
-
severity: DiagnosticSeverity.Warning,
|
|
901
877
|
message: localize('MinPropWarning', 'Object has fewer properties than the required number of {0}', schema.minProperties)
|
|
902
878
|
});
|
|
903
879
|
}
|
|
@@ -914,7 +890,6 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
914
890
|
if (!seenKeys[requiredProp]) {
|
|
915
891
|
validationResult.problems.push({
|
|
916
892
|
location: { offset: node.offset, length: node.length },
|
|
917
|
-
severity: DiagnosticSeverity.Warning,
|
|
918
893
|
message: localize('RequiredDependentPropWarning', 'Object is missing property {0} required by property {1}.', requiredProp, key)
|
|
919
894
|
});
|
|
920
895
|
}
|
|
@@ -3,37 +3,27 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { Range } from '../jsonLanguageTypes';
|
|
6
|
-
export function
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
return Promise.resolve([definition]);
|
|
6
|
+
export function findLinks(document, doc) {
|
|
7
|
+
var links = [];
|
|
8
|
+
doc.visit(function (node) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (node.type === "property" && node.keyNode.value === "$ref" && ((_a = node.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'string') {
|
|
11
|
+
var path = node.valueNode.value;
|
|
12
|
+
var targetNode = findTargetNode(doc, path);
|
|
13
|
+
if (targetNode) {
|
|
14
|
+
var targetPos = document.positionAt(targetNode.offset);
|
|
15
|
+
links.push({
|
|
16
|
+
target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
|
|
17
|
+
range: createRange(document, node.valueNode)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
return Promise.resolve(links);
|
|
26
24
|
}
|
|
27
25
|
function createRange(document, node) {
|
|
28
|
-
return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
29
|
-
}
|
|
30
|
-
function isRef(node) {
|
|
31
|
-
return node.type === 'string' &&
|
|
32
|
-
node.parent &&
|
|
33
|
-
node.parent.type === 'property' &&
|
|
34
|
-
node.parent.valueNode === node &&
|
|
35
|
-
node.parent.keyNode.value === "$ref" ||
|
|
36
|
-
false;
|
|
26
|
+
return Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
|
|
37
27
|
}
|
|
38
28
|
function findTargetNode(doc, path) {
|
|
39
29
|
var tokens = parseJSONPointer(path);
|
|
@@ -445,9 +445,10 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
445
445
|
}
|
|
446
446
|
var seen = Object.create(null);
|
|
447
447
|
var schemas = [];
|
|
448
|
+
var normalizedResource = normalizeResourceForMatching(resource);
|
|
448
449
|
for (var _i = 0, _a = this.filePatternAssociations; _i < _a.length; _i++) {
|
|
449
450
|
var entry = _a[_i];
|
|
450
|
-
if (entry.matchesPattern(
|
|
451
|
+
if (entry.matchesPattern(normalizedResource)) {
|
|
451
452
|
for (var _b = 0, _c = entry.getURIs(); _b < _c.length; _b++) {
|
|
452
453
|
var schemaId = _c[_b];
|
|
453
454
|
if (!seen[schemaId]) {
|
|
@@ -500,6 +501,15 @@ function normalizeId(id) {
|
|
|
500
501
|
return id;
|
|
501
502
|
}
|
|
502
503
|
}
|
|
504
|
+
function normalizeResourceForMatching(resource) {
|
|
505
|
+
// remove querues and fragments, normalize drive capitalization
|
|
506
|
+
try {
|
|
507
|
+
return URI.parse(resource).with({ fragment: null, query: null }).toString();
|
|
508
|
+
}
|
|
509
|
+
catch (e) {
|
|
510
|
+
return resource;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
503
513
|
function toDisplayString(url) {
|
|
504
514
|
try {
|
|
505
515
|
var uri = URI.parse(url);
|
|
@@ -37,22 +37,24 @@ var JSONValidation = /** @class */ (function () {
|
|
|
37
37
|
var getDiagnostics = function (schema) {
|
|
38
38
|
var trailingCommaSeverity = documentSettings ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
|
|
39
39
|
var commentSeverity = documentSettings ? toDiagnosticSeverity(documentSettings.comments) : _this.commentSeverity;
|
|
40
|
+
var schemaValidation = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaValidation) ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
|
|
41
|
+
var schemaRequest = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaRequest) ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
|
|
40
42
|
if (schema) {
|
|
41
|
-
if (schema.errors.length && jsonDocument.root) {
|
|
43
|
+
if (schema.errors.length && jsonDocument.root && schemaRequest) {
|
|
42
44
|
var astRoot = jsonDocument.root;
|
|
43
45
|
var property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
44
46
|
if (property && property.keyNode.value === '$schema') {
|
|
45
47
|
var node = property.valueNode || property;
|
|
46
48
|
var range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
47
|
-
addProblem(Diagnostic.create(range, schema.errors[0],
|
|
49
|
+
addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
|
|
48
50
|
}
|
|
49
51
|
else {
|
|
50
52
|
var range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
51
|
-
addProblem(Diagnostic.create(range, schema.errors[0],
|
|
53
|
+
addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
else {
|
|
55
|
-
var semanticErrors = jsonDocument.validate(textDocument, schema.schema);
|
|
56
|
+
else if (schemaValidation) {
|
|
57
|
+
var semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
|
|
56
58
|
if (semanticErrors) {
|
|
57
59
|
semanticErrors.forEach(addProblem);
|
|
58
60
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
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
|
+
import { DocumentLink } from 'vscode-languageserver-types';
|
|
2
3
|
export declare type JSONDocument = {
|
|
3
4
|
root: ASTNode | undefined;
|
|
4
5
|
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
|
|
@@ -24,5 +25,6 @@ export interface LanguageService {
|
|
|
24
25
|
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
25
26
|
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
26
27
|
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
28
|
+
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>;
|
|
27
29
|
}
|
|
28
30
|
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
if (v !== undefined) module.exports = v;
|
|
19
19
|
}
|
|
20
20
|
else if (typeof define === "function" && define.amd) {
|
|
21
|
-
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "jsonc-parser", "./jsonLanguageTypes", "./services/
|
|
21
|
+
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "jsonc-parser", "./jsonLanguageTypes", "./services/jsonLinks", "./jsonLanguageTypes"], factory);
|
|
22
22
|
}
|
|
23
23
|
})(function (require, exports) {
|
|
24
24
|
"use strict";
|
|
@@ -35,7 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
var jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
|
|
36
36
|
var jsonc_parser_1 = require("jsonc-parser");
|
|
37
37
|
var jsonLanguageTypes_1 = require("./jsonLanguageTypes");
|
|
38
|
-
var
|
|
38
|
+
var jsonLinks_1 = require("./services/jsonLinks");
|
|
39
39
|
__exportStar(require("./jsonLanguageTypes"), exports);
|
|
40
40
|
function getLanguageService(params) {
|
|
41
41
|
var promise = params.promiseConstructor || Promise;
|
|
@@ -70,7 +70,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
70
70
|
doHover: jsonHover.doHover.bind(jsonHover),
|
|
71
71
|
getFoldingRanges: jsonFolding_1.getFoldingRanges,
|
|
72
72
|
getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
|
|
73
|
-
findDefinition:
|
|
73
|
+
findDefinition: function () { return Promise.resolve([]); },
|
|
74
|
+
findLinks: jsonLinks_1.findLinks,
|
|
74
75
|
format: function (d, r, o) {
|
|
75
76
|
var range = undefined;
|
|
76
77
|
if (r) {
|
|
@@ -9,6 +9,7 @@ export { TextDocument, Range, TextEdit, JSONSchema, JSONWorkerContribution, JSON
|
|
|
9
9
|
export declare enum ErrorCode {
|
|
10
10
|
Undefined = 0,
|
|
11
11
|
EnumValueMismatch = 1,
|
|
12
|
+
Deprecated = 2,
|
|
12
13
|
UnexpectedEndOfComment = 257,
|
|
13
14
|
UnexpectedEndOfString = 258,
|
|
14
15
|
UnexpectedEndOfNumber = 259,
|
|
@@ -98,6 +99,14 @@ export interface DocumentLanguageSettings {
|
|
|
98
99
|
* The severity of reported trailing commas. If not set, trailing commas will be reported as errors.
|
|
99
100
|
*/
|
|
100
101
|
trailingCommas?: SeverityLevel;
|
|
102
|
+
/**
|
|
103
|
+
* The severity of problems from schema validation. If set to 'ignore', schema validation will be skipped. If not set, 'warning' is used.
|
|
104
|
+
*/
|
|
105
|
+
schemaValidation?: SeverityLevel;
|
|
106
|
+
/**
|
|
107
|
+
* The severity of problems that occurred when resolving and loading schemas. If set to 'ignore', schema resolving problems are not reported. If not set, 'warning' is used.
|
|
108
|
+
*/
|
|
109
|
+
schemaRequest?: SeverityLevel;
|
|
101
110
|
}
|
|
102
111
|
export interface SchemaConfiguration {
|
|
103
112
|
/**
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
(function (ErrorCode) {
|
|
49
49
|
ErrorCode[ErrorCode["Undefined"] = 0] = "Undefined";
|
|
50
50
|
ErrorCode[ErrorCode["EnumValueMismatch"] = 1] = "EnumValueMismatch";
|
|
51
|
+
ErrorCode[ErrorCode["Deprecated"] = 2] = "Deprecated";
|
|
51
52
|
ErrorCode[ErrorCode["UnexpectedEndOfComment"] = 257] = "UnexpectedEndOfComment";
|
|
52
53
|
ErrorCode[ErrorCode["UnexpectedEndOfString"] = 258] = "UnexpectedEndOfString";
|
|
53
54
|
ErrorCode[ErrorCode["UnexpectedEndOfNumber"] = 259] = "UnexpectedEndOfNumber";
|
|
@@ -316,13 +316,15 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
316
316
|
doVisit_1(this.root);
|
|
317
317
|
}
|
|
318
318
|
};
|
|
319
|
-
JSONDocument.prototype.validate = function (textDocument, schema) {
|
|
319
|
+
JSONDocument.prototype.validate = function (textDocument, schema, severity) {
|
|
320
|
+
if (severity === void 0) { severity = jsonLanguageTypes_1.DiagnosticSeverity.Warning; }
|
|
320
321
|
if (this.root && schema) {
|
|
321
322
|
var validationResult = new ValidationResult();
|
|
322
323
|
validate(this.root, schema, validationResult, NoOpSchemaCollector.instance);
|
|
323
324
|
return validationResult.problems.map(function (p) {
|
|
325
|
+
var _a;
|
|
324
326
|
var range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(p.location.offset), textDocument.positionAt(p.location.offset + p.location.length));
|
|
325
|
-
return jsonLanguageTypes_1.Diagnostic.create(range, p.message, p.severity, p.code);
|
|
327
|
+
return jsonLanguageTypes_1.Diagnostic.create(range, p.message, (_a = p.severity) !== null && _a !== void 0 ? _a : severity, p.code);
|
|
326
328
|
});
|
|
327
329
|
}
|
|
328
330
|
return undefined;
|
|
@@ -369,7 +371,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
369
371
|
if (!schema.type.some(matchesType)) {
|
|
370
372
|
validationResult.problems.push({
|
|
371
373
|
location: { offset: node.offset, length: node.length },
|
|
372
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
373
374
|
message: schema.errorMessage || localize('typeArrayMismatchWarning', 'Incorrect type. Expected one of {0}.', schema.type.join(', '))
|
|
374
375
|
});
|
|
375
376
|
}
|
|
@@ -378,7 +379,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
378
379
|
if (!matchesType(schema.type)) {
|
|
379
380
|
validationResult.problems.push({
|
|
380
381
|
location: { offset: node.offset, length: node.length },
|
|
381
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
382
382
|
message: schema.errorMessage || localize('typeMismatchWarning', 'Incorrect type. Expected "{0}".', schema.type)
|
|
383
383
|
});
|
|
384
384
|
}
|
|
@@ -397,7 +397,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
397
397
|
if (!subValidationResult.hasProblems()) {
|
|
398
398
|
validationResult.problems.push({
|
|
399
399
|
location: { offset: node.offset, length: node.length },
|
|
400
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
401
400
|
message: localize('notSchemaWarning', "Matches a schema that is not allowed.")
|
|
402
401
|
});
|
|
403
402
|
}
|
|
@@ -447,7 +446,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
447
446
|
if (matches.length > 1 && maxOneMatch) {
|
|
448
447
|
validationResult.problems.push({
|
|
449
448
|
location: { offset: node.offset, length: 1 },
|
|
450
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
451
449
|
message: localize('oneOfWarning', "Matches multiple schemas when only one must validate.")
|
|
452
450
|
});
|
|
453
451
|
}
|
|
@@ -508,7 +506,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
508
506
|
if (!enumValueMatch) {
|
|
509
507
|
validationResult.problems.push({
|
|
510
508
|
location: { offset: node.offset, length: node.length },
|
|
511
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
512
509
|
code: jsonLanguageTypes_1.ErrorCode.EnumValueMismatch,
|
|
513
510
|
message: schema.errorMessage || localize('enumWarning', 'Value is not accepted. Valid values: {0}.', schema.enum.map(function (v) { return JSON.stringify(v); }).join(', '))
|
|
514
511
|
});
|
|
@@ -519,7 +516,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
519
516
|
if (!objects_1.equals(val, schema.const)) {
|
|
520
517
|
validationResult.problems.push({
|
|
521
518
|
location: { offset: node.offset, length: node.length },
|
|
522
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
523
519
|
code: jsonLanguageTypes_1.ErrorCode.EnumValueMismatch,
|
|
524
520
|
message: schema.errorMessage || localize('constWarning', 'Value must be {0}.', JSON.stringify(schema.const))
|
|
525
521
|
});
|
|
@@ -534,7 +530,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
534
530
|
validationResult.problems.push({
|
|
535
531
|
location: { offset: node.parent.offset, length: node.parent.length },
|
|
536
532
|
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
537
|
-
message: schema.deprecationMessage
|
|
533
|
+
message: schema.deprecationMessage,
|
|
534
|
+
code: jsonLanguageTypes_1.ErrorCode.Deprecated
|
|
538
535
|
});
|
|
539
536
|
}
|
|
540
537
|
}
|
|
@@ -571,7 +568,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
571
568
|
if (remainder !== 0) {
|
|
572
569
|
validationResult.problems.push({
|
|
573
570
|
location: { offset: node.offset, length: node.length },
|
|
574
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
575
571
|
message: localize('multipleOfWarning', 'Value is not divisible by {0}.', schema.multipleOf)
|
|
576
572
|
});
|
|
577
573
|
}
|
|
@@ -595,7 +591,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
595
591
|
if (objects_1.isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
|
|
596
592
|
validationResult.problems.push({
|
|
597
593
|
location: { offset: node.offset, length: node.length },
|
|
598
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
599
594
|
message: localize('exclusiveMinimumWarning', 'Value is below the exclusive minimum of {0}.', exclusiveMinimum)
|
|
600
595
|
});
|
|
601
596
|
}
|
|
@@ -603,7 +598,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
603
598
|
if (objects_1.isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
|
|
604
599
|
validationResult.problems.push({
|
|
605
600
|
location: { offset: node.offset, length: node.length },
|
|
606
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
607
601
|
message: localize('exclusiveMaximumWarning', 'Value is above the exclusive maximum of {0}.', exclusiveMaximum)
|
|
608
602
|
});
|
|
609
603
|
}
|
|
@@ -611,7 +605,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
611
605
|
if (objects_1.isNumber(minimum) && val < minimum) {
|
|
612
606
|
validationResult.problems.push({
|
|
613
607
|
location: { offset: node.offset, length: node.length },
|
|
614
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
615
608
|
message: localize('minimumWarning', 'Value is below the minimum of {0}.', minimum)
|
|
616
609
|
});
|
|
617
610
|
}
|
|
@@ -619,7 +612,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
619
612
|
if (objects_1.isNumber(maximum) && val > maximum) {
|
|
620
613
|
validationResult.problems.push({
|
|
621
614
|
location: { offset: node.offset, length: node.length },
|
|
622
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
623
615
|
message: localize('maximumWarning', 'Value is above the maximum of {0}.', maximum)
|
|
624
616
|
});
|
|
625
617
|
}
|
|
@@ -628,14 +620,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
628
620
|
if (objects_1.isNumber(schema.minLength) && node.value.length < schema.minLength) {
|
|
629
621
|
validationResult.problems.push({
|
|
630
622
|
location: { offset: node.offset, length: node.length },
|
|
631
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
632
623
|
message: localize('minLengthWarning', 'String is shorter than the minimum length of {0}.', schema.minLength)
|
|
633
624
|
});
|
|
634
625
|
}
|
|
635
626
|
if (objects_1.isNumber(schema.maxLength) && node.value.length > schema.maxLength) {
|
|
636
627
|
validationResult.problems.push({
|
|
637
628
|
location: { offset: node.offset, length: node.length },
|
|
638
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
639
629
|
message: localize('maxLengthWarning', 'String is longer than the maximum length of {0}.', schema.maxLength)
|
|
640
630
|
});
|
|
641
631
|
}
|
|
@@ -644,7 +634,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
644
634
|
if (!regex.test(node.value)) {
|
|
645
635
|
validationResult.problems.push({
|
|
646
636
|
location: { offset: node.offset, length: node.length },
|
|
647
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
648
637
|
message: schema.patternErrorMessage || schema.errorMessage || localize('patternWarning', 'String does not match the pattern of "{0}".', schema.pattern)
|
|
649
638
|
});
|
|
650
639
|
}
|
|
@@ -670,7 +659,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
670
659
|
if (errorMessage) {
|
|
671
660
|
validationResult.problems.push({
|
|
672
661
|
location: { offset: node.offset, length: node.length },
|
|
673
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
674
662
|
message: schema.patternErrorMessage || schema.errorMessage || localize('uriFormatWarning', 'String is not a URI: {0}', errorMessage)
|
|
675
663
|
});
|
|
676
664
|
}
|
|
@@ -685,7 +673,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
685
673
|
if (!node.value || !format.pattern.exec(node.value)) {
|
|
686
674
|
validationResult.problems.push({
|
|
687
675
|
location: { offset: node.offset, length: node.length },
|
|
688
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
689
676
|
message: schema.patternErrorMessage || schema.errorMessage || format.errorMessage
|
|
690
677
|
});
|
|
691
678
|
}
|
|
@@ -720,7 +707,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
720
707
|
else if (schema.additionalItems === false) {
|
|
721
708
|
validationResult.problems.push({
|
|
722
709
|
location: { offset: node.offset, length: node.length },
|
|
723
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
724
710
|
message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer.', subSchemas.length)
|
|
725
711
|
});
|
|
726
712
|
}
|
|
@@ -747,7 +733,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
747
733
|
if (!doesContain) {
|
|
748
734
|
validationResult.problems.push({
|
|
749
735
|
location: { offset: node.offset, length: node.length },
|
|
750
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
751
736
|
message: schema.errorMessage || localize('requiredItemMissingWarning', 'Array does not contain required item.')
|
|
752
737
|
});
|
|
753
738
|
}
|
|
@@ -755,14 +740,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
755
740
|
if (objects_1.isNumber(schema.minItems) && node.items.length < schema.minItems) {
|
|
756
741
|
validationResult.problems.push({
|
|
757
742
|
location: { offset: node.offset, length: node.length },
|
|
758
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
759
743
|
message: localize('minItemsWarning', 'Array has too few items. Expected {0} or more.', schema.minItems)
|
|
760
744
|
});
|
|
761
745
|
}
|
|
762
746
|
if (objects_1.isNumber(schema.maxItems) && node.items.length > schema.maxItems) {
|
|
763
747
|
validationResult.problems.push({
|
|
764
748
|
location: { offset: node.offset, length: node.length },
|
|
765
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
766
749
|
message: localize('maxItemsWarning', 'Array has too many items. Expected {0} or fewer.', schema.maxItems)
|
|
767
750
|
});
|
|
768
751
|
}
|
|
@@ -774,7 +757,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
774
757
|
if (duplicates) {
|
|
775
758
|
validationResult.problems.push({
|
|
776
759
|
location: { offset: node.offset, length: node.length },
|
|
777
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
778
760
|
message: localize('uniqueItemsWarning', 'Array has duplicate items.')
|
|
779
761
|
});
|
|
780
762
|
}
|
|
@@ -797,7 +779,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
797
779
|
var location = keyNode ? { offset: keyNode.offset, length: keyNode.length } : { offset: node.offset, length: 1 };
|
|
798
780
|
validationResult.problems.push({
|
|
799
781
|
location: location,
|
|
800
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
801
782
|
message: localize('MissingRequiredPropWarning', 'Missing property "{0}".', propertyName)
|
|
802
783
|
});
|
|
803
784
|
}
|
|
@@ -822,7 +803,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
822
803
|
var propertyNode = child.parent;
|
|
823
804
|
validationResult.problems.push({
|
|
824
805
|
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
|
|
825
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
826
806
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
827
807
|
});
|
|
828
808
|
}
|
|
@@ -855,7 +835,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
855
835
|
var propertyNode = child.parent;
|
|
856
836
|
validationResult.problems.push({
|
|
857
837
|
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
|
|
858
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
859
838
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
860
839
|
});
|
|
861
840
|
}
|
|
@@ -894,7 +873,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
894
873
|
var propertyNode = child.parent;
|
|
895
874
|
validationResult.problems.push({
|
|
896
875
|
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
|
|
897
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
898
876
|
message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
|
|
899
877
|
});
|
|
900
878
|
}
|
|
@@ -905,7 +883,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
905
883
|
if (node.properties.length > schema.maxProperties) {
|
|
906
884
|
validationResult.problems.push({
|
|
907
885
|
location: { offset: node.offset, length: node.length },
|
|
908
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
909
886
|
message: localize('MaxPropWarning', 'Object has more properties than limit of {0}.', schema.maxProperties)
|
|
910
887
|
});
|
|
911
888
|
}
|
|
@@ -914,7 +891,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
914
891
|
if (node.properties.length < schema.minProperties) {
|
|
915
892
|
validationResult.problems.push({
|
|
916
893
|
location: { offset: node.offset, length: node.length },
|
|
917
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
918
894
|
message: localize('MinPropWarning', 'Object has fewer properties than the required number of {0}', schema.minProperties)
|
|
919
895
|
});
|
|
920
896
|
}
|
|
@@ -931,7 +907,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
931
907
|
if (!seenKeys[requiredProp]) {
|
|
932
908
|
validationResult.problems.push({
|
|
933
909
|
location: { offset: node.offset, length: node.length },
|
|
934
|
-
severity: jsonLanguageTypes_1.DiagnosticSeverity.Warning,
|
|
935
910
|
message: localize('RequiredDependentPropWarning', 'Object is missing property {0} required by property {1}.', requiredProp, key)
|
|
936
911
|
});
|
|
937
912
|
}
|
|
@@ -13,40 +13,30 @@
|
|
|
13
13
|
})(function (require, exports) {
|
|
14
14
|
"use strict";
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.findLinks = void 0;
|
|
17
17
|
var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
|
|
18
|
-
function
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
return Promise.resolve([definition]);
|
|
18
|
+
function findLinks(document, doc) {
|
|
19
|
+
var links = [];
|
|
20
|
+
doc.visit(function (node) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (node.type === "property" && node.keyNode.value === "$ref" && ((_a = node.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'string') {
|
|
23
|
+
var path = node.valueNode.value;
|
|
24
|
+
var targetNode = findTargetNode(doc, path);
|
|
25
|
+
if (targetNode) {
|
|
26
|
+
var targetPos = document.positionAt(targetNode.offset);
|
|
27
|
+
links.push({
|
|
28
|
+
target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
|
|
29
|
+
range: createRange(document, node.valueNode)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
return Promise.resolve(links);
|
|
38
36
|
}
|
|
39
|
-
exports.
|
|
37
|
+
exports.findLinks = findLinks;
|
|
40
38
|
function createRange(document, node) {
|
|
41
|
-
return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
42
|
-
}
|
|
43
|
-
function isRef(node) {
|
|
44
|
-
return node.type === 'string' &&
|
|
45
|
-
node.parent &&
|
|
46
|
-
node.parent.type === 'property' &&
|
|
47
|
-
node.parent.valueNode === node &&
|
|
48
|
-
node.parent.keyNode.value === "$ref" ||
|
|
49
|
-
false;
|
|
39
|
+
return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
|
|
50
40
|
}
|
|
51
41
|
function findTargetNode(doc, path) {
|
|
52
42
|
var tokens = parseJSONPointer(path);
|
|
@@ -457,9 +457,10 @@
|
|
|
457
457
|
}
|
|
458
458
|
var seen = Object.create(null);
|
|
459
459
|
var schemas = [];
|
|
460
|
+
var normalizedResource = normalizeResourceForMatching(resource);
|
|
460
461
|
for (var _i = 0, _a = this.filePatternAssociations; _i < _a.length; _i++) {
|
|
461
462
|
var entry = _a[_i];
|
|
462
|
-
if (entry.matchesPattern(
|
|
463
|
+
if (entry.matchesPattern(normalizedResource)) {
|
|
463
464
|
for (var _b = 0, _c = entry.getURIs(); _b < _c.length; _b++) {
|
|
464
465
|
var schemaId = _c[_b];
|
|
465
466
|
if (!seen[schemaId]) {
|
|
@@ -512,6 +513,15 @@
|
|
|
512
513
|
return id;
|
|
513
514
|
}
|
|
514
515
|
}
|
|
516
|
+
function normalizeResourceForMatching(resource) {
|
|
517
|
+
// remove querues and fragments, normalize drive capitalization
|
|
518
|
+
try {
|
|
519
|
+
return vscode_uri_1.URI.parse(resource).with({ fragment: null, query: null }).toString();
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
return resource;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
515
525
|
function toDisplayString(url) {
|
|
516
526
|
try {
|
|
517
527
|
var uri = vscode_uri_1.URI.parse(url);
|
|
@@ -49,22 +49,24 @@
|
|
|
49
49
|
var getDiagnostics = function (schema) {
|
|
50
50
|
var trailingCommaSeverity = documentSettings ? toDiagnosticSeverity(documentSettings.trailingCommas) : jsonLanguageTypes_1.DiagnosticSeverity.Error;
|
|
51
51
|
var commentSeverity = documentSettings ? toDiagnosticSeverity(documentSettings.comments) : _this.commentSeverity;
|
|
52
|
+
var schemaValidation = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaValidation) ? toDiagnosticSeverity(documentSettings.schemaValidation) : jsonLanguageTypes_1.DiagnosticSeverity.Warning;
|
|
53
|
+
var schemaRequest = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaRequest) ? toDiagnosticSeverity(documentSettings.schemaRequest) : jsonLanguageTypes_1.DiagnosticSeverity.Warning;
|
|
52
54
|
if (schema) {
|
|
53
|
-
if (schema.errors.length && jsonDocument.root) {
|
|
55
|
+
if (schema.errors.length && jsonDocument.root && schemaRequest) {
|
|
54
56
|
var astRoot = jsonDocument.root;
|
|
55
57
|
var property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
56
58
|
if (property && property.keyNode.value === '$schema') {
|
|
57
59
|
var node = property.valueNode || property;
|
|
58
60
|
var range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
59
|
-
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, schema.errors[0],
|
|
61
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, schema.errors[0], schemaRequest, jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
64
|
var range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
63
|
-
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, schema.errors[0],
|
|
65
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, schema.errors[0], schemaRequest, jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
else {
|
|
67
|
-
var semanticErrors = jsonDocument.validate(textDocument, schema.schema);
|
|
68
|
+
else if (schemaValidation) {
|
|
69
|
+
var semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
|
|
68
70
|
if (semanticErrors) {
|
|
69
71
|
semanticErrors.forEach(addProblem);
|
|
70
72
|
}
|