vscode-json-languageservice 4.1.8
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 +133 -0
- package/LICENSE.md +47 -0
- package/README.md +65 -0
- package/lib/esm/jsonContributions.d.ts +17 -0
- package/lib/esm/jsonContributions.js +1 -0
- package/lib/esm/jsonLanguageService.d.ts +28 -0
- package/lib/esm/jsonLanguageService.js +65 -0
- package/lib/esm/jsonLanguageTypes.d.ts +275 -0
- package/lib/esm/jsonLanguageTypes.js +45 -0
- package/lib/esm/jsonSchema.d.ts +70 -0
- package/lib/esm/jsonSchema.js +1 -0
- package/lib/esm/parser/jsonParser.js +1212 -0
- package/lib/esm/services/configuration.js +528 -0
- package/lib/esm/services/jsonCompletion.js +934 -0
- package/lib/esm/services/jsonDocumentSymbols.js +278 -0
- package/lib/esm/services/jsonFolding.js +121 -0
- package/lib/esm/services/jsonHover.js +112 -0
- package/lib/esm/services/jsonLinks.js +73 -0
- package/lib/esm/services/jsonSchemaService.js +535 -0
- package/lib/esm/services/jsonSelectionRanges.js +61 -0
- package/lib/esm/services/jsonValidation.js +146 -0
- package/lib/esm/utils/colors.js +69 -0
- package/lib/esm/utils/glob.js +124 -0
- package/lib/esm/utils/json.js +42 -0
- package/lib/esm/utils/objects.js +65 -0
- package/lib/esm/utils/strings.js +52 -0
- package/lib/umd/jsonContributions.d.ts +17 -0
- package/lib/umd/jsonContributions.js +12 -0
- package/lib/umd/jsonLanguageService.d.ts +28 -0
- package/lib/umd/jsonLanguageService.js +89 -0
- package/lib/umd/jsonLanguageTypes.d.ts +275 -0
- package/lib/umd/jsonLanguageTypes.js +92 -0
- package/lib/umd/jsonSchema.d.ts +70 -0
- package/lib/umd/jsonSchema.js +12 -0
- package/lib/umd/parser/jsonParser.js +1231 -0
- package/lib/umd/services/configuration.js +541 -0
- package/lib/umd/services/jsonCompletion.js +947 -0
- package/lib/umd/services/jsonDocumentSymbols.js +291 -0
- package/lib/umd/services/jsonFolding.js +135 -0
- package/lib/umd/services/jsonHover.js +125 -0
- package/lib/umd/services/jsonLinks.js +87 -0
- package/lib/umd/services/jsonSchemaService.js +548 -0
- package/lib/umd/services/jsonSelectionRanges.js +75 -0
- package/lib/umd/services/jsonValidation.js +159 -0
- package/lib/umd/utils/colors.js +85 -0
- package/lib/umd/utils/glob.js +138 -0
- package/lib/umd/utils/json.js +56 -0
- package/lib/umd/utils/objects.js +83 -0
- package/lib/umd/utils/strings.js +70 -0
- package/package.json +55 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { UnresolvedSchema } from './jsonSchemaService';
|
|
6
|
+
import { ErrorCode, Diagnostic, DiagnosticSeverity, Range } from '../jsonLanguageTypes';
|
|
7
|
+
import * as nls from 'vscode-nls';
|
|
8
|
+
import { isBoolean } from '../utils/objects';
|
|
9
|
+
var localize = nls.loadMessageBundle();
|
|
10
|
+
var JSONValidation = /** @class */ (function () {
|
|
11
|
+
function JSONValidation(jsonSchemaService, promiseConstructor) {
|
|
12
|
+
this.jsonSchemaService = jsonSchemaService;
|
|
13
|
+
this.promise = promiseConstructor;
|
|
14
|
+
this.validationEnabled = true;
|
|
15
|
+
}
|
|
16
|
+
JSONValidation.prototype.configure = function (raw) {
|
|
17
|
+
if (raw) {
|
|
18
|
+
this.validationEnabled = raw.validate !== false;
|
|
19
|
+
this.commentSeverity = raw.allowComments ? undefined : DiagnosticSeverity.Error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
JSONValidation.prototype.doValidation = function (textDocument, jsonDocument, documentSettings, schema) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
if (!this.validationEnabled) {
|
|
25
|
+
return this.promise.resolve([]);
|
|
26
|
+
}
|
|
27
|
+
var diagnostics = [];
|
|
28
|
+
var added = {};
|
|
29
|
+
var addProblem = function (problem) {
|
|
30
|
+
// remove duplicated messages
|
|
31
|
+
var signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
|
|
32
|
+
if (!added[signature]) {
|
|
33
|
+
added[signature] = true;
|
|
34
|
+
diagnostics.push(problem);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var getDiagnostics = function (schema) {
|
|
38
|
+
var trailingCommaSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.trailingCommas) ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
|
|
39
|
+
var commentSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.comments) ? 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;
|
|
42
|
+
if (schema) {
|
|
43
|
+
if (schema.errors.length && jsonDocument.root && schemaRequest) {
|
|
44
|
+
var astRoot = jsonDocument.root;
|
|
45
|
+
var property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
46
|
+
if (property && property.keyNode.value === '$schema') {
|
|
47
|
+
var node = property.valueNode || property;
|
|
48
|
+
var range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
49
|
+
addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
var range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
53
|
+
addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (schemaValidation) {
|
|
57
|
+
var semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
|
|
58
|
+
if (semanticErrors) {
|
|
59
|
+
semanticErrors.forEach(addProblem);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (schemaAllowsComments(schema.schema)) {
|
|
63
|
+
commentSeverity = undefined;
|
|
64
|
+
}
|
|
65
|
+
if (schemaAllowsTrailingCommas(schema.schema)) {
|
|
66
|
+
trailingCommaSeverity = undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (var _i = 0, _a = jsonDocument.syntaxErrors; _i < _a.length; _i++) {
|
|
70
|
+
var p = _a[_i];
|
|
71
|
+
if (p.code === ErrorCode.TrailingComma) {
|
|
72
|
+
if (typeof trailingCommaSeverity !== 'number') {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
p.severity = trailingCommaSeverity;
|
|
76
|
+
}
|
|
77
|
+
addProblem(p);
|
|
78
|
+
}
|
|
79
|
+
if (typeof commentSeverity === 'number') {
|
|
80
|
+
var message_1 = localize('InvalidCommentToken', 'Comments are not permitted in JSON.');
|
|
81
|
+
jsonDocument.comments.forEach(function (c) {
|
|
82
|
+
addProblem(Diagnostic.create(c, message_1, commentSeverity, ErrorCode.CommentNotPermitted));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return diagnostics;
|
|
86
|
+
};
|
|
87
|
+
if (schema) {
|
|
88
|
+
var id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
|
89
|
+
return this.jsonSchemaService.resolveSchemaContent(new UnresolvedSchema(schema), id, {}).then(function (resolvedSchema) {
|
|
90
|
+
return getDiagnostics(resolvedSchema);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(function (schema) {
|
|
94
|
+
return getDiagnostics(schema);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
return JSONValidation;
|
|
98
|
+
}());
|
|
99
|
+
export { JSONValidation };
|
|
100
|
+
var idCounter = 0;
|
|
101
|
+
function schemaAllowsComments(schemaRef) {
|
|
102
|
+
if (schemaRef && typeof schemaRef === 'object') {
|
|
103
|
+
if (isBoolean(schemaRef.allowComments)) {
|
|
104
|
+
return schemaRef.allowComments;
|
|
105
|
+
}
|
|
106
|
+
if (schemaRef.allOf) {
|
|
107
|
+
for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
|
|
108
|
+
var schema = _a[_i];
|
|
109
|
+
var allow = schemaAllowsComments(schema);
|
|
110
|
+
if (isBoolean(allow)) {
|
|
111
|
+
return allow;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
function schemaAllowsTrailingCommas(schemaRef) {
|
|
119
|
+
if (schemaRef && typeof schemaRef === 'object') {
|
|
120
|
+
if (isBoolean(schemaRef.allowTrailingCommas)) {
|
|
121
|
+
return schemaRef.allowTrailingCommas;
|
|
122
|
+
}
|
|
123
|
+
var deprSchemaRef = schemaRef;
|
|
124
|
+
if (isBoolean(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
|
|
125
|
+
return deprSchemaRef['allowsTrailingCommas'];
|
|
126
|
+
}
|
|
127
|
+
if (schemaRef.allOf) {
|
|
128
|
+
for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
|
|
129
|
+
var schema = _a[_i];
|
|
130
|
+
var allow = schemaAllowsTrailingCommas(schema);
|
|
131
|
+
if (isBoolean(allow)) {
|
|
132
|
+
return allow;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
function toDiagnosticSeverity(severityLevel) {
|
|
140
|
+
switch (severityLevel) {
|
|
141
|
+
case 'error': return DiagnosticSeverity.Error;
|
|
142
|
+
case 'warning': return DiagnosticSeverity.Warning;
|
|
143
|
+
case 'ignore': return undefined;
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
var Digit0 = 48;
|
|
6
|
+
var Digit9 = 57;
|
|
7
|
+
var A = 65;
|
|
8
|
+
var a = 97;
|
|
9
|
+
var f = 102;
|
|
10
|
+
export function hexDigit(charCode) {
|
|
11
|
+
if (charCode < Digit0) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
if (charCode <= Digit9) {
|
|
15
|
+
return charCode - Digit0;
|
|
16
|
+
}
|
|
17
|
+
if (charCode < a) {
|
|
18
|
+
charCode += (a - A);
|
|
19
|
+
}
|
|
20
|
+
if (charCode >= a && charCode <= f) {
|
|
21
|
+
return charCode - a + 10;
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
export function colorFromHex(text) {
|
|
26
|
+
if (text[0] !== '#') {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
switch (text.length) {
|
|
30
|
+
case 4:
|
|
31
|
+
return {
|
|
32
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
|
|
33
|
+
green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
|
|
34
|
+
blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
|
|
35
|
+
alpha: 1
|
|
36
|
+
};
|
|
37
|
+
case 5:
|
|
38
|
+
return {
|
|
39
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
|
|
40
|
+
green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
|
|
41
|
+
blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
|
|
42
|
+
alpha: (hexDigit(text.charCodeAt(4)) * 0x11) / 255.0,
|
|
43
|
+
};
|
|
44
|
+
case 7:
|
|
45
|
+
return {
|
|
46
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
|
|
47
|
+
green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
|
|
48
|
+
blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
|
|
49
|
+
alpha: 1
|
|
50
|
+
};
|
|
51
|
+
case 9:
|
|
52
|
+
return {
|
|
53
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
|
|
54
|
+
green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
|
|
55
|
+
blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
|
|
56
|
+
alpha: (hexDigit(text.charCodeAt(7)) * 0x10 + hexDigit(text.charCodeAt(8))) / 255.0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
export function colorFrom256RGB(red, green, blue, alpha) {
|
|
62
|
+
if (alpha === void 0) { alpha = 1.0; }
|
|
63
|
+
return {
|
|
64
|
+
red: red / 255.0,
|
|
65
|
+
green: green / 255.0,
|
|
66
|
+
blue: blue / 255.0,
|
|
67
|
+
alpha: alpha
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Copyright (c) 2013, Nick Fitzgerald
|
|
4
|
+
* Licensed under the MIT License. See LICENCE.md in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
export function createRegex(glob, opts) {
|
|
7
|
+
if (typeof glob !== 'string') {
|
|
8
|
+
throw new TypeError('Expected a string');
|
|
9
|
+
}
|
|
10
|
+
var str = String(glob);
|
|
11
|
+
// The regexp we are building, as a string.
|
|
12
|
+
var reStr = "";
|
|
13
|
+
// Whether we are matching so called "extended" globs (like bash) and should
|
|
14
|
+
// support single character matching, matching ranges of characters, group
|
|
15
|
+
// matching, etc.
|
|
16
|
+
var extended = opts ? !!opts.extended : false;
|
|
17
|
+
// When globstar is _false_ (default), '/foo/*' is translated a regexp like
|
|
18
|
+
// '^\/foo\/.*$' which will match any string beginning with '/foo/'
|
|
19
|
+
// When globstar is _true_, '/foo/*' is translated to regexp like
|
|
20
|
+
// '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' BUT
|
|
21
|
+
// which does not have a '/' to the right of it.
|
|
22
|
+
// E.g. with '/foo/*' these will match: '/foo/bar', '/foo/bar.txt' but
|
|
23
|
+
// these will not '/foo/bar/baz', '/foo/bar/baz.txt'
|
|
24
|
+
// Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
|
|
25
|
+
// globstar is _false_
|
|
26
|
+
var globstar = opts ? !!opts.globstar : false;
|
|
27
|
+
// If we are doing extended matching, this boolean is true when we are inside
|
|
28
|
+
// a group (eg {*.html,*.js}), and false otherwise.
|
|
29
|
+
var inGroup = false;
|
|
30
|
+
// RegExp flags (eg "i" ) to pass in to RegExp constructor.
|
|
31
|
+
var flags = opts && typeof (opts.flags) === "string" ? opts.flags : "";
|
|
32
|
+
var c;
|
|
33
|
+
for (var i = 0, len = str.length; i < len; i++) {
|
|
34
|
+
c = str[i];
|
|
35
|
+
switch (c) {
|
|
36
|
+
case "/":
|
|
37
|
+
case "$":
|
|
38
|
+
case "^":
|
|
39
|
+
case "+":
|
|
40
|
+
case ".":
|
|
41
|
+
case "(":
|
|
42
|
+
case ")":
|
|
43
|
+
case "=":
|
|
44
|
+
case "!":
|
|
45
|
+
case "|":
|
|
46
|
+
reStr += "\\" + c;
|
|
47
|
+
break;
|
|
48
|
+
case "?":
|
|
49
|
+
if (extended) {
|
|
50
|
+
reStr += ".";
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "[":
|
|
54
|
+
case "]":
|
|
55
|
+
if (extended) {
|
|
56
|
+
reStr += c;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "{":
|
|
60
|
+
if (extended) {
|
|
61
|
+
inGroup = true;
|
|
62
|
+
reStr += "(";
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "}":
|
|
66
|
+
if (extended) {
|
|
67
|
+
inGroup = false;
|
|
68
|
+
reStr += ")";
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case ",":
|
|
72
|
+
if (inGroup) {
|
|
73
|
+
reStr += "|";
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
reStr += "\\" + c;
|
|
77
|
+
break;
|
|
78
|
+
case "*":
|
|
79
|
+
// Move over all consecutive "*"'s.
|
|
80
|
+
// Also store the previous and next characters
|
|
81
|
+
var prevChar = str[i - 1];
|
|
82
|
+
var starCount = 1;
|
|
83
|
+
while (str[i + 1] === "*") {
|
|
84
|
+
starCount++;
|
|
85
|
+
i++;
|
|
86
|
+
}
|
|
87
|
+
var nextChar = str[i + 1];
|
|
88
|
+
if (!globstar) {
|
|
89
|
+
// globstar is disabled, so treat any number of "*" as one
|
|
90
|
+
reStr += ".*";
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// globstar is enabled, so determine if this is a globstar segment
|
|
94
|
+
var isGlobstar = starCount > 1 // multiple "*"'s
|
|
95
|
+
&& (prevChar === "/" || prevChar === undefined || prevChar === '{' || prevChar === ',') // from the start of the segment
|
|
96
|
+
&& (nextChar === "/" || nextChar === undefined || nextChar === ',' || nextChar === '}'); // to the end of the segment
|
|
97
|
+
if (isGlobstar) {
|
|
98
|
+
if (nextChar === "/") {
|
|
99
|
+
i++; // move over the "/"
|
|
100
|
+
}
|
|
101
|
+
else if (prevChar === '/' && reStr.endsWith('\\/')) {
|
|
102
|
+
reStr = reStr.substr(0, reStr.length - 2);
|
|
103
|
+
}
|
|
104
|
+
// it's a globstar, so match zero or more path segments
|
|
105
|
+
reStr += "((?:[^/]*(?:\/|$))*)";
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// it's not a globstar, so only match one path segment
|
|
109
|
+
reStr += "([^/]*)";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
reStr += c;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// When regexp 'g' flag is specified don't
|
|
118
|
+
// constrain the regular expression with ^ & $
|
|
119
|
+
if (!flags || !~flags.indexOf('g')) {
|
|
120
|
+
reStr = "^" + reStr + "$";
|
|
121
|
+
}
|
|
122
|
+
return new RegExp(reStr, flags);
|
|
123
|
+
}
|
|
124
|
+
;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export function stringifyObject(obj, indent, stringifyLiteral) {
|
|
6
|
+
if (obj !== null && typeof obj === 'object') {
|
|
7
|
+
var newIndent = indent + '\t';
|
|
8
|
+
if (Array.isArray(obj)) {
|
|
9
|
+
if (obj.length === 0) {
|
|
10
|
+
return '[]';
|
|
11
|
+
}
|
|
12
|
+
var result = '[\n';
|
|
13
|
+
for (var i = 0; i < obj.length; i++) {
|
|
14
|
+
result += newIndent + stringifyObject(obj[i], newIndent, stringifyLiteral);
|
|
15
|
+
if (i < obj.length - 1) {
|
|
16
|
+
result += ',';
|
|
17
|
+
}
|
|
18
|
+
result += '\n';
|
|
19
|
+
}
|
|
20
|
+
result += indent + ']';
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
var keys = Object.keys(obj);
|
|
25
|
+
if (keys.length === 0) {
|
|
26
|
+
return '{}';
|
|
27
|
+
}
|
|
28
|
+
var result = '{\n';
|
|
29
|
+
for (var i = 0; i < keys.length; i++) {
|
|
30
|
+
var key = keys[i];
|
|
31
|
+
result += newIndent + JSON.stringify(key) + ': ' + stringifyObject(obj[key], newIndent, stringifyLiteral);
|
|
32
|
+
if (i < keys.length - 1) {
|
|
33
|
+
result += ',';
|
|
34
|
+
}
|
|
35
|
+
result += '\n';
|
|
36
|
+
}
|
|
37
|
+
result += indent + '}';
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return stringifyLiteral(obj);
|
|
42
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export function equals(one, other) {
|
|
6
|
+
if (one === other) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (one === null || one === undefined || other === null || other === undefined) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (typeof one !== typeof other) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (typeof one !== 'object') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if ((Array.isArray(one)) !== (Array.isArray(other))) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var i, key;
|
|
22
|
+
if (Array.isArray(one)) {
|
|
23
|
+
if (one.length !== other.length) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
for (i = 0; i < one.length; i++) {
|
|
27
|
+
if (!equals(one[i], other[i])) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
var oneKeys = [];
|
|
34
|
+
for (key in one) {
|
|
35
|
+
oneKeys.push(key);
|
|
36
|
+
}
|
|
37
|
+
oneKeys.sort();
|
|
38
|
+
var otherKeys = [];
|
|
39
|
+
for (key in other) {
|
|
40
|
+
otherKeys.push(key);
|
|
41
|
+
}
|
|
42
|
+
otherKeys.sort();
|
|
43
|
+
if (!equals(oneKeys, otherKeys)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (i = 0; i < oneKeys.length; i++) {
|
|
47
|
+
if (!equals(one[oneKeys[i]], other[oneKeys[i]])) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
export function isNumber(val) {
|
|
55
|
+
return typeof val === 'number';
|
|
56
|
+
}
|
|
57
|
+
export function isDefined(val) {
|
|
58
|
+
return typeof val !== 'undefined';
|
|
59
|
+
}
|
|
60
|
+
export function isBoolean(val) {
|
|
61
|
+
return typeof val === 'boolean';
|
|
62
|
+
}
|
|
63
|
+
export function isString(val) {
|
|
64
|
+
return typeof val === 'string';
|
|
65
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export function startsWith(haystack, needle) {
|
|
6
|
+
if (haystack.length < needle.length) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
for (var i = 0; i < needle.length; i++) {
|
|
10
|
+
if (haystack[i] !== needle[i]) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Determines if haystack ends with needle.
|
|
18
|
+
*/
|
|
19
|
+
export function endsWith(haystack, needle) {
|
|
20
|
+
var diff = haystack.length - needle.length;
|
|
21
|
+
if (diff > 0) {
|
|
22
|
+
return haystack.lastIndexOf(needle) === diff;
|
|
23
|
+
}
|
|
24
|
+
else if (diff === 0) {
|
|
25
|
+
return haystack === needle;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function convertSimple2RegExpPattern(pattern) {
|
|
32
|
+
return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
|
|
33
|
+
}
|
|
34
|
+
export function repeat(value, count) {
|
|
35
|
+
var s = '';
|
|
36
|
+
while (count > 0) {
|
|
37
|
+
if ((count & 1) === 1) {
|
|
38
|
+
s += value;
|
|
39
|
+
}
|
|
40
|
+
value += value;
|
|
41
|
+
count = count >>> 1;
|
|
42
|
+
}
|
|
43
|
+
return s;
|
|
44
|
+
}
|
|
45
|
+
export function extendedRegExp(pattern) {
|
|
46
|
+
if (startsWith(pattern, '(?i)')) {
|
|
47
|
+
return new RegExp(pattern.substring(4), 'i');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return new RegExp(pattern);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Thenable, MarkedString, CompletionItem } from './jsonLanguageService';
|
|
2
|
+
export interface JSONWorkerContribution {
|
|
3
|
+
getInfoContribution(uri: string, location: JSONPath): Thenable<MarkedString[]>;
|
|
4
|
+
collectPropertyCompletions(uri: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any>;
|
|
5
|
+
collectValueCompletions(uri: string, location: JSONPath, propertyKey: string, result: CompletionsCollector): Thenable<any>;
|
|
6
|
+
collectDefaultCompletions(uri: string, result: CompletionsCollector): Thenable<any>;
|
|
7
|
+
resolveCompletion?(item: CompletionItem): Thenable<CompletionItem>;
|
|
8
|
+
}
|
|
9
|
+
export declare type Segment = string | number;
|
|
10
|
+
export declare type JSONPath = Segment[];
|
|
11
|
+
export interface CompletionsCollector {
|
|
12
|
+
add(suggestion: CompletionItem): void;
|
|
13
|
+
error(message: string): void;
|
|
14
|
+
log(message: string): void;
|
|
15
|
+
setAsIncomplete(): void;
|
|
16
|
+
getNumberOfProposals(): number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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';
|
|
3
|
+
export declare type JSONDocument = {
|
|
4
|
+
root: ASTNode | undefined;
|
|
5
|
+
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
|
|
6
|
+
};
|
|
7
|
+
export * from './jsonLanguageTypes';
|
|
8
|
+
export interface LanguageService {
|
|
9
|
+
configure(settings: LanguageSettings): void;
|
|
10
|
+
doValidation(document: TextDocument, jsonDocument: JSONDocument, documentSettings?: DocumentLanguageSettings, schema?: JSONSchema): Thenable<Diagnostic[]>;
|
|
11
|
+
parseJSONDocument(document: TextDocument): JSONDocument;
|
|
12
|
+
newJSONDocument(rootNode: ASTNode, syntaxDiagnostics?: Diagnostic[]): JSONDocument;
|
|
13
|
+
resetSchema(uri: string): boolean;
|
|
14
|
+
getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): Thenable<MatchingSchema[]>;
|
|
15
|
+
doResolve(item: CompletionItem): Thenable<CompletionItem>;
|
|
16
|
+
doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable<CompletionList | null>;
|
|
17
|
+
findDocumentSymbols(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): SymbolInformation[];
|
|
18
|
+
findDocumentSymbols2(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): DocumentSymbol[];
|
|
19
|
+
findDocumentColors(document: TextDocument, doc: JSONDocument, context?: DocumentColorsContext): Thenable<ColorInformation[]>;
|
|
20
|
+
getColorPresentations(document: TextDocument, doc: JSONDocument, color: Color, range: Range): ColorPresentation[];
|
|
21
|
+
doHover(document: TextDocument, position: Position, doc: JSONDocument): Thenable<Hover | null>;
|
|
22
|
+
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[];
|
|
23
|
+
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
24
|
+
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
25
|
+
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
26
|
+
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>;
|
|
27
|
+
}
|
|
28
|
+
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
+
};
|
|
15
|
+
(function (factory) {
|
|
16
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
17
|
+
var v = factory(require, exports);
|
|
18
|
+
if (v !== undefined) module.exports = v;
|
|
19
|
+
}
|
|
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/jsonLinks", "./jsonLanguageTypes"], factory);
|
|
22
|
+
}
|
|
23
|
+
})(function (require, exports) {
|
|
24
|
+
"use strict";
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getLanguageService = void 0;
|
|
27
|
+
var jsonCompletion_1 = require("./services/jsonCompletion");
|
|
28
|
+
var jsonHover_1 = require("./services/jsonHover");
|
|
29
|
+
var jsonValidation_1 = require("./services/jsonValidation");
|
|
30
|
+
var jsonDocumentSymbols_1 = require("./services/jsonDocumentSymbols");
|
|
31
|
+
var jsonParser_1 = require("./parser/jsonParser");
|
|
32
|
+
var configuration_1 = require("./services/configuration");
|
|
33
|
+
var jsonSchemaService_1 = require("./services/jsonSchemaService");
|
|
34
|
+
var jsonFolding_1 = require("./services/jsonFolding");
|
|
35
|
+
var jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
|
|
36
|
+
var jsonc_parser_1 = require("jsonc-parser");
|
|
37
|
+
var jsonLanguageTypes_1 = require("./jsonLanguageTypes");
|
|
38
|
+
var jsonLinks_1 = require("./services/jsonLinks");
|
|
39
|
+
__exportStar(require("./jsonLanguageTypes"), exports);
|
|
40
|
+
function getLanguageService(params) {
|
|
41
|
+
var promise = params.promiseConstructor || Promise;
|
|
42
|
+
var jsonSchemaService = new jsonSchemaService_1.JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
|
|
43
|
+
jsonSchemaService.setSchemaContributions(configuration_1.schemaContributions);
|
|
44
|
+
var jsonCompletion = new jsonCompletion_1.JSONCompletion(jsonSchemaService, params.contributions, promise, params.clientCapabilities);
|
|
45
|
+
var jsonHover = new jsonHover_1.JSONHover(jsonSchemaService, params.contributions, promise);
|
|
46
|
+
var jsonDocumentSymbols = new jsonDocumentSymbols_1.JSONDocumentSymbols(jsonSchemaService);
|
|
47
|
+
var jsonValidation = new jsonValidation_1.JSONValidation(jsonSchemaService, promise);
|
|
48
|
+
return {
|
|
49
|
+
configure: function (settings) {
|
|
50
|
+
jsonSchemaService.clearExternalSchemas();
|
|
51
|
+
if (settings.schemas) {
|
|
52
|
+
settings.schemas.forEach(function (settings) {
|
|
53
|
+
jsonSchemaService.registerExternalSchema(settings.uri, settings.fileMatch, settings.schema);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
jsonValidation.configure(settings);
|
|
57
|
+
},
|
|
58
|
+
resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
|
|
59
|
+
doValidation: jsonValidation.doValidation.bind(jsonValidation),
|
|
60
|
+
parseJSONDocument: function (document) { return jsonParser_1.parse(document, { collectComments: true }); },
|
|
61
|
+
newJSONDocument: function (root, diagnostics) { return jsonParser_1.newJSONDocument(root, diagnostics); },
|
|
62
|
+
getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
|
|
63
|
+
doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
|
|
64
|
+
doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
|
|
65
|
+
findDocumentSymbols: jsonDocumentSymbols.findDocumentSymbols.bind(jsonDocumentSymbols),
|
|
66
|
+
findDocumentSymbols2: jsonDocumentSymbols.findDocumentSymbols2.bind(jsonDocumentSymbols),
|
|
67
|
+
findDocumentColors: jsonDocumentSymbols.findDocumentColors.bind(jsonDocumentSymbols),
|
|
68
|
+
getColorPresentations: jsonDocumentSymbols.getColorPresentations.bind(jsonDocumentSymbols),
|
|
69
|
+
doHover: jsonHover.doHover.bind(jsonHover),
|
|
70
|
+
getFoldingRanges: jsonFolding_1.getFoldingRanges,
|
|
71
|
+
getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
|
|
72
|
+
findDefinition: function () { return Promise.resolve([]); },
|
|
73
|
+
findLinks: jsonLinks_1.findLinks,
|
|
74
|
+
format: function (d, r, o) {
|
|
75
|
+
var range = undefined;
|
|
76
|
+
if (r) {
|
|
77
|
+
var offset = d.offsetAt(r.start);
|
|
78
|
+
var length = d.offsetAt(r.end) - offset;
|
|
79
|
+
range = { offset: offset, length: length };
|
|
80
|
+
}
|
|
81
|
+
var options = { tabSize: o ? o.tabSize : 4, insertSpaces: (o === null || o === void 0 ? void 0 : o.insertSpaces) === true, insertFinalNewline: (o === null || o === void 0 ? void 0 : o.insertFinalNewline) === true, eol: '\n' };
|
|
82
|
+
return jsonc_parser_1.format(d.getText(), range, options).map(function (e) {
|
|
83
|
+
return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
exports.getLanguageService = getLanguageService;
|
|
89
|
+
});
|