vscode-json-languageservice 4.2.0 → 5.1.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 +10 -1
- package/SECURITY.md +41 -0
- package/lib/esm/jsonLanguageService.js +22 -22
- package/lib/esm/jsonLanguageTypes.d.ts +3 -1
- package/lib/esm/jsonLanguageTypes.js +3 -2
- package/lib/esm/jsonSchema.d.ts +21 -2
- package/lib/esm/parser/jsonParser.js +488 -488
- package/lib/esm/services/configuration.js +9 -9
- package/lib/esm/services/jsonCompletion.js +280 -290
- package/lib/esm/services/jsonDocumentSymbols.js +88 -99
- package/lib/esm/services/jsonFolding.js +38 -39
- package/lib/esm/services/jsonHover.js +40 -43
- package/lib/esm/services/jsonLinks.js +12 -13
- package/lib/esm/services/jsonSchemaService.js +234 -253
- package/lib/esm/services/jsonSelectionRanges.js +9 -9
- package/lib/esm/services/jsonValidation.js +53 -51
- package/lib/esm/utils/colors.js +7 -8
- package/lib/esm/utils/glob.js +12 -12
- package/lib/esm/utils/json.js +7 -7
- package/lib/esm/utils/objects.js +3 -0
- package/lib/esm/utils/strings.js +3 -3
- package/lib/umd/jsonLanguageService.js +36 -32
- package/lib/umd/jsonLanguageTypes.d.ts +3 -1
- package/lib/umd/jsonLanguageTypes.js +5 -3
- package/lib/umd/jsonSchema.d.ts +21 -2
- package/lib/umd/parser/jsonParser.js +492 -482
- package/lib/umd/services/configuration.js +9 -9
- package/lib/umd/services/jsonCompletion.js +287 -296
- package/lib/umd/services/jsonDocumentSymbols.js +92 -102
- package/lib/umd/services/jsonFolding.js +40 -41
- package/lib/umd/services/jsonHover.js +42 -44
- package/lib/umd/services/jsonLinks.js +13 -14
- package/lib/umd/services/jsonSchemaService.js +241 -257
- package/lib/umd/services/jsonSelectionRanges.js +11 -11
- package/lib/umd/services/jsonValidation.js +56 -53
- package/lib/umd/utils/colors.js +7 -8
- package/lib/umd/utils/glob.js +12 -12
- package/lib/umd/utils/json.js +7 -7
- package/lib/umd/utils/objects.js +5 -1
- package/lib/umd/utils/strings.js +3 -3
- package/package.json +12 -12
|
@@ -6,16 +6,16 @@ import { Range, SelectionRange } from '../jsonLanguageTypes';
|
|
|
6
6
|
import { createScanner } from 'jsonc-parser';
|
|
7
7
|
export function getSelectionRanges(document, positions, doc) {
|
|
8
8
|
function getSelectionRange(position) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
let offset = document.offsetAt(position);
|
|
10
|
+
let node = doc.getNodeFromOffset(offset, true);
|
|
11
|
+
const result = [];
|
|
12
12
|
while (node) {
|
|
13
13
|
switch (node.type) {
|
|
14
14
|
case 'string':
|
|
15
15
|
case 'object':
|
|
16
16
|
case 'array':
|
|
17
17
|
// range without ", [ or {
|
|
18
|
-
|
|
18
|
+
const cStart = node.offset + 1, cEnd = node.offset + node.length - 1;
|
|
19
19
|
if (cStart < cEnd && offset >= cStart && offset <= cEnd) {
|
|
20
20
|
result.push(newRange(cStart, cEnd));
|
|
21
21
|
}
|
|
@@ -29,15 +29,15 @@ export function getSelectionRanges(document, positions, doc) {
|
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
31
|
if (node.type === 'property' || node.parent && node.parent.type === 'array') {
|
|
32
|
-
|
|
32
|
+
const afterCommaOffset = getOffsetAfterNextToken(node.offset + node.length, 5 /* SyntaxKind.CommaToken */);
|
|
33
33
|
if (afterCommaOffset !== -1) {
|
|
34
34
|
result.push(newRange(node.offset, afterCommaOffset));
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
node = node.parent;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
for (
|
|
39
|
+
let current = undefined;
|
|
40
|
+
for (let index = result.length - 1; index >= 0; index--) {
|
|
41
41
|
current = SelectionRange.create(result[index], current);
|
|
42
42
|
}
|
|
43
43
|
if (!current) {
|
|
@@ -48,10 +48,10 @@ export function getSelectionRanges(document, positions, doc) {
|
|
|
48
48
|
function newRange(start, end) {
|
|
49
49
|
return Range.create(document.positionAt(start), document.positionAt(end));
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const scanner = createScanner(document.getText(), true);
|
|
52
52
|
function getOffsetAfterNextToken(offset, expectedToken) {
|
|
53
53
|
scanner.setPosition(offset);
|
|
54
|
-
|
|
54
|
+
let token = scanner.scan();
|
|
55
55
|
if (token === expectedToken) {
|
|
56
56
|
return scanner.getTokenOffset() + scanner.getTokenLength();
|
|
57
57
|
}
|
|
@@ -5,55 +5,62 @@
|
|
|
5
5
|
import { ErrorCode, Diagnostic, DiagnosticSeverity, Range } from '../jsonLanguageTypes';
|
|
6
6
|
import * as nls from 'vscode-nls';
|
|
7
7
|
import { isBoolean } from '../utils/objects';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const localize = nls.loadMessageBundle();
|
|
9
|
+
export class JSONValidation {
|
|
10
|
+
constructor(jsonSchemaService, promiseConstructor) {
|
|
11
11
|
this.jsonSchemaService = jsonSchemaService;
|
|
12
12
|
this.promise = promiseConstructor;
|
|
13
13
|
this.validationEnabled = true;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
configure(raw) {
|
|
16
16
|
if (raw) {
|
|
17
17
|
this.validationEnabled = raw.validate !== false;
|
|
18
18
|
this.commentSeverity = raw.allowComments ? undefined : DiagnosticSeverity.Error;
|
|
19
19
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var _this = this;
|
|
20
|
+
}
|
|
21
|
+
doValidation(textDocument, jsonDocument, documentSettings, schema) {
|
|
23
22
|
if (!this.validationEnabled) {
|
|
24
23
|
return this.promise.resolve([]);
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const diagnostics = [];
|
|
26
|
+
const added = {};
|
|
27
|
+
const addProblem = (problem) => {
|
|
29
28
|
// remove duplicated messages
|
|
30
|
-
|
|
29
|
+
const signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
|
|
31
30
|
if (!added[signature]) {
|
|
32
31
|
added[signature] = true;
|
|
33
32
|
diagnostics.push(problem);
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const getDiagnostics = (schema) => {
|
|
36
|
+
let trailingCommaSeverity = documentSettings?.trailingCommas ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
|
|
37
|
+
let commentSeverity = documentSettings?.comments ? toDiagnosticSeverity(documentSettings.comments) : this.commentSeverity;
|
|
38
|
+
let schemaValidation = documentSettings?.schemaValidation ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
|
|
39
|
+
let schemaRequest = documentSettings?.schemaRequest ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
|
|
41
40
|
if (schema) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
const addSchemaProblem = (errorMessage, errorCode) => {
|
|
42
|
+
if (jsonDocument.root && schemaRequest) {
|
|
43
|
+
const astRoot = jsonDocument.root;
|
|
44
|
+
const property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
45
|
+
if (property && property.keyNode.value === '$schema') {
|
|
46
|
+
const node = property.valueNode || property;
|
|
47
|
+
const range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
48
|
+
addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
52
|
+
addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
|
|
53
|
+
}
|
|
53
54
|
}
|
|
55
|
+
};
|
|
56
|
+
if (schema.errors.length) {
|
|
57
|
+
addSchemaProblem(schema.errors[0], ErrorCode.SchemaResolveError);
|
|
54
58
|
}
|
|
55
59
|
else if (schemaValidation) {
|
|
56
|
-
|
|
60
|
+
for (const warning of schema.warnings) {
|
|
61
|
+
addSchemaProblem(warning, ErrorCode.SchemaUnsupportedFeature);
|
|
62
|
+
}
|
|
63
|
+
const semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
|
|
57
64
|
if (semanticErrors) {
|
|
58
65
|
semanticErrors.forEach(addProblem);
|
|
59
66
|
}
|
|
@@ -65,8 +72,7 @@ var JSONValidation = /** @class */ (function () {
|
|
|
65
72
|
trailingCommaSeverity = undefined;
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
|
-
for (
|
|
69
|
-
var p = _a[_i];
|
|
75
|
+
for (const p of jsonDocument.syntaxErrors) {
|
|
70
76
|
if (p.code === ErrorCode.TrailingComma) {
|
|
71
77
|
if (typeof trailingCommaSeverity !== 'number') {
|
|
72
78
|
continue;
|
|
@@ -76,40 +82,37 @@ var JSONValidation = /** @class */ (function () {
|
|
|
76
82
|
addProblem(p);
|
|
77
83
|
}
|
|
78
84
|
if (typeof commentSeverity === 'number') {
|
|
79
|
-
|
|
80
|
-
jsonDocument.comments.forEach(
|
|
81
|
-
addProblem(Diagnostic.create(c,
|
|
85
|
+
const message = localize('InvalidCommentToken', 'Comments are not permitted in JSON.');
|
|
86
|
+
jsonDocument.comments.forEach(c => {
|
|
87
|
+
addProblem(Diagnostic.create(c, message, commentSeverity, ErrorCode.CommentNotPermitted));
|
|
82
88
|
});
|
|
83
89
|
}
|
|
84
90
|
return diagnostics;
|
|
85
91
|
};
|
|
86
92
|
if (schema) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return handle.getResolvedSchema().then(
|
|
93
|
+
const id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
|
94
|
+
const handle = this.jsonSchemaService.registerExternalSchema(id, [], schema);
|
|
95
|
+
return handle.getResolvedSchema().then(resolvedSchema => {
|
|
90
96
|
return getDiagnostics(resolvedSchema);
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
|
-
return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(
|
|
99
|
+
return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(schema => {
|
|
94
100
|
return getDiagnostics(schema);
|
|
95
101
|
});
|
|
96
|
-
}
|
|
97
|
-
|
|
102
|
+
}
|
|
103
|
+
getLanguageStatus(textDocument, jsonDocument) {
|
|
98
104
|
return { schemas: this.jsonSchemaService.getSchemaURIsForResource(textDocument.uri, jsonDocument) };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export { JSONValidation };
|
|
103
|
-
var idCounter = 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let idCounter = 0;
|
|
104
108
|
function schemaAllowsComments(schemaRef) {
|
|
105
109
|
if (schemaRef && typeof schemaRef === 'object') {
|
|
106
110
|
if (isBoolean(schemaRef.allowComments)) {
|
|
107
111
|
return schemaRef.allowComments;
|
|
108
112
|
}
|
|
109
113
|
if (schemaRef.allOf) {
|
|
110
|
-
for (
|
|
111
|
-
|
|
112
|
-
var allow = schemaAllowsComments(schema);
|
|
114
|
+
for (const schema of schemaRef.allOf) {
|
|
115
|
+
const allow = schemaAllowsComments(schema);
|
|
113
116
|
if (isBoolean(allow)) {
|
|
114
117
|
return allow;
|
|
115
118
|
}
|
|
@@ -123,14 +126,13 @@ function schemaAllowsTrailingCommas(schemaRef) {
|
|
|
123
126
|
if (isBoolean(schemaRef.allowTrailingCommas)) {
|
|
124
127
|
return schemaRef.allowTrailingCommas;
|
|
125
128
|
}
|
|
126
|
-
|
|
129
|
+
const deprSchemaRef = schemaRef;
|
|
127
130
|
if (isBoolean(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
|
|
128
131
|
return deprSchemaRef['allowsTrailingCommas'];
|
|
129
132
|
}
|
|
130
133
|
if (schemaRef.allOf) {
|
|
131
|
-
for (
|
|
132
|
-
|
|
133
|
-
var allow = schemaAllowsTrailingCommas(schema);
|
|
134
|
+
for (const schema of schemaRef.allOf) {
|
|
135
|
+
const allow = schemaAllowsTrailingCommas(schema);
|
|
134
136
|
if (isBoolean(allow)) {
|
|
135
137
|
return allow;
|
|
136
138
|
}
|
package/lib/esm/utils/colors.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const Digit0 = 48;
|
|
6
|
+
const Digit9 = 57;
|
|
7
|
+
const A = 65;
|
|
8
|
+
const a = 97;
|
|
9
|
+
const f = 102;
|
|
10
10
|
export function hexDigit(charCode) {
|
|
11
11
|
if (charCode < Digit0) {
|
|
12
12
|
return 0;
|
|
@@ -58,12 +58,11 @@ export function colorFromHex(text) {
|
|
|
58
58
|
}
|
|
59
59
|
return undefined;
|
|
60
60
|
}
|
|
61
|
-
export function colorFrom256RGB(red, green, blue, alpha) {
|
|
62
|
-
if (alpha === void 0) { alpha = 1.0; }
|
|
61
|
+
export function colorFrom256RGB(red, green, blue, alpha = 1.0) {
|
|
63
62
|
return {
|
|
64
63
|
red: red / 255.0,
|
|
65
64
|
green: green / 255.0,
|
|
66
65
|
blue: blue / 255.0,
|
|
67
|
-
alpha
|
|
66
|
+
alpha
|
|
68
67
|
};
|
|
69
68
|
}
|
package/lib/esm/utils/glob.js
CHANGED
|
@@ -7,13 +7,13 @@ export function createRegex(glob, opts) {
|
|
|
7
7
|
if (typeof glob !== 'string') {
|
|
8
8
|
throw new TypeError('Expected a string');
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const str = String(glob);
|
|
11
11
|
// The regexp we are building, as a string.
|
|
12
|
-
|
|
12
|
+
let reStr = "";
|
|
13
13
|
// Whether we are matching so called "extended" globs (like bash) and should
|
|
14
14
|
// support single character matching, matching ranges of characters, group
|
|
15
15
|
// matching, etc.
|
|
16
|
-
|
|
16
|
+
const extended = opts ? !!opts.extended : false;
|
|
17
17
|
// When globstar is _false_ (default), '/foo/*' is translated a regexp like
|
|
18
18
|
// '^\/foo\/.*$' which will match any string beginning with '/foo/'
|
|
19
19
|
// When globstar is _true_, '/foo/*' is translated to regexp like
|
|
@@ -23,14 +23,14 @@ export function createRegex(glob, opts) {
|
|
|
23
23
|
// these will not '/foo/bar/baz', '/foo/bar/baz.txt'
|
|
24
24
|
// Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
|
|
25
25
|
// globstar is _false_
|
|
26
|
-
|
|
26
|
+
const globstar = opts ? !!opts.globstar : false;
|
|
27
27
|
// If we are doing extended matching, this boolean is true when we are inside
|
|
28
28
|
// a group (eg {*.html,*.js}), and false otherwise.
|
|
29
|
-
|
|
29
|
+
let inGroup = false;
|
|
30
30
|
// RegExp flags (eg "i" ) to pass in to RegExp constructor.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (
|
|
31
|
+
const flags = opts && typeof (opts.flags) === "string" ? opts.flags : "";
|
|
32
|
+
let c;
|
|
33
|
+
for (let i = 0, len = str.length; i < len; i++) {
|
|
34
34
|
c = str[i];
|
|
35
35
|
switch (c) {
|
|
36
36
|
case "/":
|
|
@@ -78,20 +78,20 @@ export function createRegex(glob, opts) {
|
|
|
78
78
|
case "*":
|
|
79
79
|
// Move over all consecutive "*"'s.
|
|
80
80
|
// Also store the previous and next characters
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const prevChar = str[i - 1];
|
|
82
|
+
let starCount = 1;
|
|
83
83
|
while (str[i + 1] === "*") {
|
|
84
84
|
starCount++;
|
|
85
85
|
i++;
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
const nextChar = str[i + 1];
|
|
88
88
|
if (!globstar) {
|
|
89
89
|
// globstar is disabled, so treat any number of "*" as one
|
|
90
90
|
reStr += ".*";
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
93
|
// globstar is enabled, so determine if this is a globstar segment
|
|
94
|
-
|
|
94
|
+
const isGlobstar = starCount > 1 // multiple "*"'s
|
|
95
95
|
&& (prevChar === "/" || prevChar === undefined || prevChar === '{' || prevChar === ',') // from the start of the segment
|
|
96
96
|
&& (nextChar === "/" || nextChar === undefined || nextChar === ',' || nextChar === '}'); // to the end of the segment
|
|
97
97
|
if (isGlobstar) {
|
package/lib/esm/utils/json.js
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
export function stringifyObject(obj, indent, stringifyLiteral) {
|
|
6
6
|
if (obj !== null && typeof obj === 'object') {
|
|
7
|
-
|
|
7
|
+
const newIndent = indent + '\t';
|
|
8
8
|
if (Array.isArray(obj)) {
|
|
9
9
|
if (obj.length === 0) {
|
|
10
10
|
return '[]';
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
for (
|
|
12
|
+
let result = '[\n';
|
|
13
|
+
for (let i = 0; i < obj.length; i++) {
|
|
14
14
|
result += newIndent + stringifyObject(obj[i], newIndent, stringifyLiteral);
|
|
15
15
|
if (i < obj.length - 1) {
|
|
16
16
|
result += ',';
|
|
@@ -21,13 +21,13 @@ export function stringifyObject(obj, indent, stringifyLiteral) {
|
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
|
|
24
|
+
const keys = Object.keys(obj);
|
|
25
25
|
if (keys.length === 0) {
|
|
26
26
|
return '{}';
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
for (
|
|
30
|
-
|
|
28
|
+
let result = '{\n';
|
|
29
|
+
for (let i = 0; i < keys.length; i++) {
|
|
30
|
+
const key = keys[i];
|
|
31
31
|
result += newIndent + JSON.stringify(key) + ': ' + stringifyObject(obj[key], newIndent, stringifyLiteral);
|
|
32
32
|
if (i < keys.length - 1) {
|
|
33
33
|
result += ',';
|
package/lib/esm/utils/objects.js
CHANGED
package/lib/esm/utils/strings.js
CHANGED
|
@@ -6,7 +6,7 @@ export function startsWith(haystack, needle) {
|
|
|
6
6
|
if (haystack.length < needle.length) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
for (
|
|
9
|
+
for (let i = 0; i < needle.length; i++) {
|
|
10
10
|
if (haystack[i] !== needle[i]) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
@@ -17,7 +17,7 @@ export function startsWith(haystack, needle) {
|
|
|
17
17
|
* Determines if haystack ends with needle.
|
|
18
18
|
*/
|
|
19
19
|
export function endsWith(haystack, needle) {
|
|
20
|
-
|
|
20
|
+
const diff = haystack.length - needle.length;
|
|
21
21
|
if (diff > 0) {
|
|
22
22
|
return haystack.lastIndexOf(needle) === diff;
|
|
23
23
|
}
|
|
@@ -43,7 +43,7 @@ export function repeat(value, count) {
|
|
|
43
43
|
return s;
|
|
44
44
|
}
|
|
45
45
|
export function extendedRegExp(pattern) {
|
|
46
|
-
|
|
46
|
+
let flags = '';
|
|
47
47
|
if (startsWith(pattern, '(?i)')) {
|
|
48
48
|
pattern = pattern.substring(4);
|
|
49
49
|
flags = 'i';
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
8
12
|
}) : (function(o, m, k, k2) {
|
|
9
13
|
if (k2 === undefined) k2 = k;
|
|
10
14
|
o[k2] = m[k];
|
|
@@ -24,42 +28,42 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
24
28
|
"use strict";
|
|
25
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
30
|
exports.getLanguageService = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const jsonCompletion_1 = require("./services/jsonCompletion");
|
|
32
|
+
const jsonHover_1 = require("./services/jsonHover");
|
|
33
|
+
const jsonValidation_1 = require("./services/jsonValidation");
|
|
34
|
+
const jsonDocumentSymbols_1 = require("./services/jsonDocumentSymbols");
|
|
35
|
+
const jsonParser_1 = require("./parser/jsonParser");
|
|
36
|
+
const configuration_1 = require("./services/configuration");
|
|
37
|
+
const jsonSchemaService_1 = require("./services/jsonSchemaService");
|
|
38
|
+
const jsonFolding_1 = require("./services/jsonFolding");
|
|
39
|
+
const jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
|
|
40
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
41
|
+
const jsonLanguageTypes_1 = require("./jsonLanguageTypes");
|
|
42
|
+
const jsonLinks_1 = require("./services/jsonLinks");
|
|
39
43
|
__exportStar(require("./jsonLanguageTypes"), exports);
|
|
40
44
|
function getLanguageService(params) {
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const promise = params.promiseConstructor || Promise;
|
|
46
|
+
const jsonSchemaService = new jsonSchemaService_1.JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
|
|
43
47
|
jsonSchemaService.setSchemaContributions(configuration_1.schemaContributions);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const jsonCompletion = new jsonCompletion_1.JSONCompletion(jsonSchemaService, params.contributions, promise, params.clientCapabilities);
|
|
49
|
+
const jsonHover = new jsonHover_1.JSONHover(jsonSchemaService, params.contributions, promise);
|
|
50
|
+
const jsonDocumentSymbols = new jsonDocumentSymbols_1.JSONDocumentSymbols(jsonSchemaService);
|
|
51
|
+
const jsonValidation = new jsonValidation_1.JSONValidation(jsonSchemaService, promise);
|
|
48
52
|
return {
|
|
49
|
-
configure:
|
|
53
|
+
configure: (settings) => {
|
|
50
54
|
jsonSchemaService.clearExternalSchemas();
|
|
51
55
|
if (settings.schemas) {
|
|
52
|
-
settings.schemas.forEach(
|
|
56
|
+
settings.schemas.forEach(settings => {
|
|
53
57
|
jsonSchemaService.registerExternalSchema(settings.uri, settings.fileMatch, settings.schema);
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
jsonValidation.configure(settings);
|
|
57
61
|
},
|
|
58
|
-
resetSchema:
|
|
62
|
+
resetSchema: (uri) => jsonSchemaService.onResourceChange(uri),
|
|
59
63
|
doValidation: jsonValidation.doValidation.bind(jsonValidation),
|
|
60
64
|
getLanguageStatus: jsonValidation.getLanguageStatus.bind(jsonValidation),
|
|
61
|
-
parseJSONDocument:
|
|
62
|
-
newJSONDocument:
|
|
65
|
+
parseJSONDocument: (document) => (0, jsonParser_1.parse)(document, { collectComments: true }),
|
|
66
|
+
newJSONDocument: (root, diagnostics) => (0, jsonParser_1.newJSONDocument)(root, diagnostics),
|
|
63
67
|
getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
|
|
64
68
|
doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
|
|
65
69
|
doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
|
|
@@ -70,17 +74,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
70
74
|
doHover: jsonHover.doHover.bind(jsonHover),
|
|
71
75
|
getFoldingRanges: jsonFolding_1.getFoldingRanges,
|
|
72
76
|
getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
|
|
73
|
-
findDefinition:
|
|
77
|
+
findDefinition: () => Promise.resolve([]),
|
|
74
78
|
findLinks: jsonLinks_1.findLinks,
|
|
75
|
-
format:
|
|
76
|
-
|
|
79
|
+
format: (d, r, o) => {
|
|
80
|
+
let range = undefined;
|
|
77
81
|
if (r) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
range = { offset
|
|
82
|
+
const offset = d.offsetAt(r.start);
|
|
83
|
+
const length = d.offsetAt(r.end) - offset;
|
|
84
|
+
range = { offset, length };
|
|
81
85
|
}
|
|
82
|
-
|
|
83
|
-
return (0, jsonc_parser_1.format)(d.getText(), range, options).map(
|
|
86
|
+
const options = { tabSize: o ? o.tabSize : 4, insertSpaces: o?.insertSpaces === true, insertFinalNewline: o?.insertFinalNewline === true, eol: '\n', keepLines: o?.keepLines === true };
|
|
87
|
+
return (0, jsonc_parser_1.format)(d.getText(), range, options).map(e => {
|
|
84
88
|
return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
|
|
85
89
|
});
|
|
86
90
|
}
|
|
@@ -25,7 +25,8 @@ export declare enum ErrorCode {
|
|
|
25
25
|
TrailingComma = 519,
|
|
26
26
|
DuplicateKey = 520,
|
|
27
27
|
CommentNotPermitted = 521,
|
|
28
|
-
SchemaResolveError = 768
|
|
28
|
+
SchemaResolveError = 768,
|
|
29
|
+
SchemaUnsupportedFeature = 769
|
|
29
30
|
}
|
|
30
31
|
export declare type ASTNode = ObjectASTNode | PropertyASTNode | ArrayASTNode | StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode;
|
|
31
32
|
export interface BaseASTNode {
|
|
@@ -275,4 +276,5 @@ export interface ColorInformationContext {
|
|
|
275
276
|
}
|
|
276
277
|
export interface FormattingOptions extends LSPFormattingOptions {
|
|
277
278
|
insertFinalNewline?: boolean;
|
|
279
|
+
keepLines?: boolean;
|
|
278
280
|
}
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
})(function (require, exports) {
|
|
14
14
|
"use strict";
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ClientCapabilities = exports.ErrorCode = exports.DocumentHighlightKind = exports.VersionedTextDocumentIdentifier = exports.TextDocumentEdit = exports.CodeActionKind = exports.TextEdit = exports.WorkspaceEdit = exports.DocumentLink = exports.DocumentHighlight = exports.CodeAction = exports.Command = exports.CodeActionContext = exports.MarkedString = exports.Hover = exports.Location = exports.DocumentSymbol = exports.SymbolKind = exports.SymbolInformation = exports.InsertTextFormat = exports.CompletionItemTag = exports.CompletionList = exports.CompletionItemKind = exports.CompletionItem = exports.DiagnosticSeverity = exports.Diagnostic = exports.SelectionRange = exports.FoldingRangeKind = exports.FoldingRange = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.MarkupKind = exports.MarkupContent = exports.Position = exports.Range = exports.TextDocument = void 0;
|
|
17
|
-
|
|
16
|
+
exports.ClientCapabilities = exports.ErrorCode = exports.DocumentHighlightKind = exports.VersionedTextDocumentIdentifier = exports.TextDocumentEdit = exports.CodeActionKind = exports.TextEdit = exports.WorkspaceEdit = exports.DocumentLink = exports.DocumentHighlight = exports.CodeAction = exports.Command = exports.CodeActionContext = exports.MarkedString = exports.Hover = exports.Location = exports.DocumentSymbol = exports.SymbolKind = exports.SymbolInformation = exports.InsertTextFormat = exports.CompletionItemTag = exports.CompletionList = exports.CompletionItemKind = exports.CompletionItem = exports.DiagnosticSeverity = exports.Diagnostic = exports.SelectionRange = exports.FoldingRangeKind = exports.FoldingRange = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.MarkupKind = exports.MarkupContent = exports.DocumentUri = exports.Position = exports.Range = exports.TextDocument = void 0;
|
|
17
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
18
18
|
Object.defineProperty(exports, "Range", { enumerable: true, get: function () { return vscode_languageserver_types_1.Range; } });
|
|
19
19
|
Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return vscode_languageserver_types_1.Position; } });
|
|
20
|
+
Object.defineProperty(exports, "DocumentUri", { enumerable: true, get: function () { return vscode_languageserver_types_1.DocumentUri; } });
|
|
20
21
|
Object.defineProperty(exports, "MarkupContent", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkupContent; } });
|
|
21
22
|
Object.defineProperty(exports, "MarkupKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkupKind; } });
|
|
22
23
|
Object.defineProperty(exports, "Color", { enumerable: true, get: function () { return vscode_languageserver_types_1.Color; } });
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
Object.defineProperty(exports, "TextDocumentEdit", { enumerable: true, get: function () { return vscode_languageserver_types_1.TextDocumentEdit; } });
|
|
50
51
|
Object.defineProperty(exports, "VersionedTextDocumentIdentifier", { enumerable: true, get: function () { return vscode_languageserver_types_1.VersionedTextDocumentIdentifier; } });
|
|
51
52
|
Object.defineProperty(exports, "DocumentHighlightKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.DocumentHighlightKind; } });
|
|
52
|
-
|
|
53
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
53
54
|
Object.defineProperty(exports, "TextDocument", { enumerable: true, get: function () { return vscode_languageserver_textdocument_1.TextDocument; } });
|
|
54
55
|
/**
|
|
55
56
|
* Error codes used by diagnostics
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
ErrorCode[ErrorCode["DuplicateKey"] = 520] = "DuplicateKey";
|
|
76
77
|
ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
|
|
77
78
|
ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
|
|
79
|
+
ErrorCode[ErrorCode["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
|
|
78
80
|
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
|
|
79
81
|
var ClientCapabilities;
|
|
80
82
|
(function (ClientCapabilities) {
|
package/lib/umd/jsonSchema.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface JSONSchema {
|
|
|
12
12
|
description?: string;
|
|
13
13
|
properties?: JSONSchemaMap;
|
|
14
14
|
patternProperties?: JSONSchemaMap;
|
|
15
|
-
additionalProperties?:
|
|
15
|
+
additionalProperties?: JSONSchemaRef;
|
|
16
16
|
minProperties?: number;
|
|
17
17
|
maxProperties?: number;
|
|
18
18
|
dependencies?: JSONSchemaMap | {
|
|
@@ -22,7 +22,7 @@ export interface JSONSchema {
|
|
|
22
22
|
minItems?: number;
|
|
23
23
|
maxItems?: number;
|
|
24
24
|
uniqueItems?: boolean;
|
|
25
|
-
additionalItems?:
|
|
25
|
+
additionalItems?: JSONSchemaRef;
|
|
26
26
|
pattern?: string;
|
|
27
27
|
minLength?: number;
|
|
28
28
|
maxLength?: number;
|
|
@@ -47,6 +47,25 @@ export interface JSONSchema {
|
|
|
47
47
|
if?: JSONSchemaRef;
|
|
48
48
|
then?: JSONSchemaRef;
|
|
49
49
|
else?: JSONSchemaRef;
|
|
50
|
+
unevaluatedProperties?: boolean | JSONSchemaRef;
|
|
51
|
+
unevaluatedItems?: boolean | JSONSchemaRef;
|
|
52
|
+
minContains?: number;
|
|
53
|
+
maxContains?: number;
|
|
54
|
+
deprecated?: boolean;
|
|
55
|
+
dependentRequired?: {
|
|
56
|
+
[prop: string]: string[];
|
|
57
|
+
};
|
|
58
|
+
dependentSchemas?: JSONSchemaMap;
|
|
59
|
+
$defs?: {
|
|
60
|
+
[name: string]: JSONSchema;
|
|
61
|
+
};
|
|
62
|
+
$anchor?: string;
|
|
63
|
+
$recursiveRef?: string;
|
|
64
|
+
$recursiveAnchor?: string;
|
|
65
|
+
$vocabulary?: any;
|
|
66
|
+
prefixItems?: JSONSchemaRef[];
|
|
67
|
+
$dynamicRef?: string;
|
|
68
|
+
$dynamicAnchor?: string;
|
|
50
69
|
defaultSnippets?: {
|
|
51
70
|
label?: string;
|
|
52
71
|
description?: string;
|