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,159 @@
|
|
|
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
|
+
(function (factory) {
|
|
6
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
+
var v = factory(require, exports);
|
|
8
|
+
if (v !== undefined) module.exports = v;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof define === "function" && define.amd) {
|
|
11
|
+
define(["require", "exports", "./jsonSchemaService", "../jsonLanguageTypes", "vscode-nls", "../utils/objects"], factory);
|
|
12
|
+
}
|
|
13
|
+
})(function (require, exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.JSONValidation = void 0;
|
|
17
|
+
var jsonSchemaService_1 = require("./jsonSchemaService");
|
|
18
|
+
var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
|
|
19
|
+
var nls = require("vscode-nls");
|
|
20
|
+
var objects_1 = require("../utils/objects");
|
|
21
|
+
var localize = nls.loadMessageBundle();
|
|
22
|
+
var JSONValidation = /** @class */ (function () {
|
|
23
|
+
function JSONValidation(jsonSchemaService, promiseConstructor) {
|
|
24
|
+
this.jsonSchemaService = jsonSchemaService;
|
|
25
|
+
this.promise = promiseConstructor;
|
|
26
|
+
this.validationEnabled = true;
|
|
27
|
+
}
|
|
28
|
+
JSONValidation.prototype.configure = function (raw) {
|
|
29
|
+
if (raw) {
|
|
30
|
+
this.validationEnabled = raw.validate !== false;
|
|
31
|
+
this.commentSeverity = raw.allowComments ? undefined : jsonLanguageTypes_1.DiagnosticSeverity.Error;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
JSONValidation.prototype.doValidation = function (textDocument, jsonDocument, documentSettings, schema) {
|
|
35
|
+
var _this = this;
|
|
36
|
+
if (!this.validationEnabled) {
|
|
37
|
+
return this.promise.resolve([]);
|
|
38
|
+
}
|
|
39
|
+
var diagnostics = [];
|
|
40
|
+
var added = {};
|
|
41
|
+
var addProblem = function (problem) {
|
|
42
|
+
// remove duplicated messages
|
|
43
|
+
var signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
|
|
44
|
+
if (!added[signature]) {
|
|
45
|
+
added[signature] = true;
|
|
46
|
+
diagnostics.push(problem);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var getDiagnostics = function (schema) {
|
|
50
|
+
var trailingCommaSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.trailingCommas) ? toDiagnosticSeverity(documentSettings.trailingCommas) : jsonLanguageTypes_1.DiagnosticSeverity.Error;
|
|
51
|
+
var commentSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.comments) ? 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;
|
|
54
|
+
if (schema) {
|
|
55
|
+
if (schema.errors.length && jsonDocument.root && schemaRequest) {
|
|
56
|
+
var astRoot = jsonDocument.root;
|
|
57
|
+
var property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
|
58
|
+
if (property && property.keyNode.value === '$schema') {
|
|
59
|
+
var node = property.valueNode || property;
|
|
60
|
+
var range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
|
61
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, schema.errors[0], schemaRequest, jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
var range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
|
65
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(range, schema.errors[0], schemaRequest, jsonLanguageTypes_1.ErrorCode.SchemaResolveError));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (schemaValidation) {
|
|
69
|
+
var semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
|
|
70
|
+
if (semanticErrors) {
|
|
71
|
+
semanticErrors.forEach(addProblem);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (schemaAllowsComments(schema.schema)) {
|
|
75
|
+
commentSeverity = undefined;
|
|
76
|
+
}
|
|
77
|
+
if (schemaAllowsTrailingCommas(schema.schema)) {
|
|
78
|
+
trailingCommaSeverity = undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (var _i = 0, _a = jsonDocument.syntaxErrors; _i < _a.length; _i++) {
|
|
82
|
+
var p = _a[_i];
|
|
83
|
+
if (p.code === jsonLanguageTypes_1.ErrorCode.TrailingComma) {
|
|
84
|
+
if (typeof trailingCommaSeverity !== 'number') {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
p.severity = trailingCommaSeverity;
|
|
88
|
+
}
|
|
89
|
+
addProblem(p);
|
|
90
|
+
}
|
|
91
|
+
if (typeof commentSeverity === 'number') {
|
|
92
|
+
var message_1 = localize('InvalidCommentToken', 'Comments are not permitted in JSON.');
|
|
93
|
+
jsonDocument.comments.forEach(function (c) {
|
|
94
|
+
addProblem(jsonLanguageTypes_1.Diagnostic.create(c, message_1, commentSeverity, jsonLanguageTypes_1.ErrorCode.CommentNotPermitted));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return diagnostics;
|
|
98
|
+
};
|
|
99
|
+
if (schema) {
|
|
100
|
+
var id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
|
101
|
+
return this.jsonSchemaService.resolveSchemaContent(new jsonSchemaService_1.UnresolvedSchema(schema), id, {}).then(function (resolvedSchema) {
|
|
102
|
+
return getDiagnostics(resolvedSchema);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(function (schema) {
|
|
106
|
+
return getDiagnostics(schema);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return JSONValidation;
|
|
110
|
+
}());
|
|
111
|
+
exports.JSONValidation = JSONValidation;
|
|
112
|
+
var idCounter = 0;
|
|
113
|
+
function schemaAllowsComments(schemaRef) {
|
|
114
|
+
if (schemaRef && typeof schemaRef === 'object') {
|
|
115
|
+
if (objects_1.isBoolean(schemaRef.allowComments)) {
|
|
116
|
+
return schemaRef.allowComments;
|
|
117
|
+
}
|
|
118
|
+
if (schemaRef.allOf) {
|
|
119
|
+
for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
|
|
120
|
+
var schema = _a[_i];
|
|
121
|
+
var allow = schemaAllowsComments(schema);
|
|
122
|
+
if (objects_1.isBoolean(allow)) {
|
|
123
|
+
return allow;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
function schemaAllowsTrailingCommas(schemaRef) {
|
|
131
|
+
if (schemaRef && typeof schemaRef === 'object') {
|
|
132
|
+
if (objects_1.isBoolean(schemaRef.allowTrailingCommas)) {
|
|
133
|
+
return schemaRef.allowTrailingCommas;
|
|
134
|
+
}
|
|
135
|
+
var deprSchemaRef = schemaRef;
|
|
136
|
+
if (objects_1.isBoolean(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
|
|
137
|
+
return deprSchemaRef['allowsTrailingCommas'];
|
|
138
|
+
}
|
|
139
|
+
if (schemaRef.allOf) {
|
|
140
|
+
for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
|
|
141
|
+
var schema = _a[_i];
|
|
142
|
+
var allow = schemaAllowsTrailingCommas(schema);
|
|
143
|
+
if (objects_1.isBoolean(allow)) {
|
|
144
|
+
return allow;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
function toDiagnosticSeverity(severityLevel) {
|
|
152
|
+
switch (severityLevel) {
|
|
153
|
+
case 'error': return jsonLanguageTypes_1.DiagnosticSeverity.Error;
|
|
154
|
+
case 'warning': return jsonLanguageTypes_1.DiagnosticSeverity.Warning;
|
|
155
|
+
case 'ignore': return undefined;
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
(function (factory) {
|
|
6
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
+
var v = factory(require, exports);
|
|
8
|
+
if (v !== undefined) module.exports = v;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof define === "function" && define.amd) {
|
|
11
|
+
define(["require", "exports"], factory);
|
|
12
|
+
}
|
|
13
|
+
})(function (require, exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.colorFrom256RGB = exports.colorFromHex = exports.hexDigit = void 0;
|
|
17
|
+
var Digit0 = 48;
|
|
18
|
+
var Digit9 = 57;
|
|
19
|
+
var A = 65;
|
|
20
|
+
var a = 97;
|
|
21
|
+
var f = 102;
|
|
22
|
+
function hexDigit(charCode) {
|
|
23
|
+
if (charCode < Digit0) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
if (charCode <= Digit9) {
|
|
27
|
+
return charCode - Digit0;
|
|
28
|
+
}
|
|
29
|
+
if (charCode < a) {
|
|
30
|
+
charCode += (a - A);
|
|
31
|
+
}
|
|
32
|
+
if (charCode >= a && charCode <= f) {
|
|
33
|
+
return charCode - a + 10;
|
|
34
|
+
}
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
exports.hexDigit = hexDigit;
|
|
38
|
+
function colorFromHex(text) {
|
|
39
|
+
if (text[0] !== '#') {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
switch (text.length) {
|
|
43
|
+
case 4:
|
|
44
|
+
return {
|
|
45
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
|
|
46
|
+
green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
|
|
47
|
+
blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
|
|
48
|
+
alpha: 1
|
|
49
|
+
};
|
|
50
|
+
case 5:
|
|
51
|
+
return {
|
|
52
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
|
|
53
|
+
green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
|
|
54
|
+
blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
|
|
55
|
+
alpha: (hexDigit(text.charCodeAt(4)) * 0x11) / 255.0,
|
|
56
|
+
};
|
|
57
|
+
case 7:
|
|
58
|
+
return {
|
|
59
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
|
|
60
|
+
green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
|
|
61
|
+
blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
|
|
62
|
+
alpha: 1
|
|
63
|
+
};
|
|
64
|
+
case 9:
|
|
65
|
+
return {
|
|
66
|
+
red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
|
|
67
|
+
green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
|
|
68
|
+
blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
|
|
69
|
+
alpha: (hexDigit(text.charCodeAt(7)) * 0x10 + hexDigit(text.charCodeAt(8))) / 255.0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
exports.colorFromHex = colorFromHex;
|
|
75
|
+
function colorFrom256RGB(red, green, blue, alpha) {
|
|
76
|
+
if (alpha === void 0) { alpha = 1.0; }
|
|
77
|
+
return {
|
|
78
|
+
red: red / 255.0,
|
|
79
|
+
green: green / 255.0,
|
|
80
|
+
blue: blue / 255.0,
|
|
81
|
+
alpha: alpha
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.colorFrom256RGB = colorFrom256RGB;
|
|
85
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
exports.createRegex = void 0;
|
|
13
|
+
/*---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
15
|
+
* Copyright (c) 2013, Nick Fitzgerald
|
|
16
|
+
* Licensed under the MIT License. See LICENCE.md in the project root for license information.
|
|
17
|
+
*--------------------------------------------------------------------------------------------*/
|
|
18
|
+
function createRegex(glob, opts) {
|
|
19
|
+
if (typeof glob !== 'string') {
|
|
20
|
+
throw new TypeError('Expected a string');
|
|
21
|
+
}
|
|
22
|
+
var str = String(glob);
|
|
23
|
+
// The regexp we are building, as a string.
|
|
24
|
+
var reStr = "";
|
|
25
|
+
// Whether we are matching so called "extended" globs (like bash) and should
|
|
26
|
+
// support single character matching, matching ranges of characters, group
|
|
27
|
+
// matching, etc.
|
|
28
|
+
var extended = opts ? !!opts.extended : false;
|
|
29
|
+
// When globstar is _false_ (default), '/foo/*' is translated a regexp like
|
|
30
|
+
// '^\/foo\/.*$' which will match any string beginning with '/foo/'
|
|
31
|
+
// When globstar is _true_, '/foo/*' is translated to regexp like
|
|
32
|
+
// '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' BUT
|
|
33
|
+
// which does not have a '/' to the right of it.
|
|
34
|
+
// E.g. with '/foo/*' these will match: '/foo/bar', '/foo/bar.txt' but
|
|
35
|
+
// these will not '/foo/bar/baz', '/foo/bar/baz.txt'
|
|
36
|
+
// Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
|
|
37
|
+
// globstar is _false_
|
|
38
|
+
var globstar = opts ? !!opts.globstar : false;
|
|
39
|
+
// If we are doing extended matching, this boolean is true when we are inside
|
|
40
|
+
// a group (eg {*.html,*.js}), and false otherwise.
|
|
41
|
+
var inGroup = false;
|
|
42
|
+
// RegExp flags (eg "i" ) to pass in to RegExp constructor.
|
|
43
|
+
var flags = opts && typeof (opts.flags) === "string" ? opts.flags : "";
|
|
44
|
+
var c;
|
|
45
|
+
for (var i = 0, len = str.length; i < len; i++) {
|
|
46
|
+
c = str[i];
|
|
47
|
+
switch (c) {
|
|
48
|
+
case "/":
|
|
49
|
+
case "$":
|
|
50
|
+
case "^":
|
|
51
|
+
case "+":
|
|
52
|
+
case ".":
|
|
53
|
+
case "(":
|
|
54
|
+
case ")":
|
|
55
|
+
case "=":
|
|
56
|
+
case "!":
|
|
57
|
+
case "|":
|
|
58
|
+
reStr += "\\" + c;
|
|
59
|
+
break;
|
|
60
|
+
case "?":
|
|
61
|
+
if (extended) {
|
|
62
|
+
reStr += ".";
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "[":
|
|
66
|
+
case "]":
|
|
67
|
+
if (extended) {
|
|
68
|
+
reStr += c;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case "{":
|
|
72
|
+
if (extended) {
|
|
73
|
+
inGroup = true;
|
|
74
|
+
reStr += "(";
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case "}":
|
|
78
|
+
if (extended) {
|
|
79
|
+
inGroup = false;
|
|
80
|
+
reStr += ")";
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case ",":
|
|
84
|
+
if (inGroup) {
|
|
85
|
+
reStr += "|";
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
reStr += "\\" + c;
|
|
89
|
+
break;
|
|
90
|
+
case "*":
|
|
91
|
+
// Move over all consecutive "*"'s.
|
|
92
|
+
// Also store the previous and next characters
|
|
93
|
+
var prevChar = str[i - 1];
|
|
94
|
+
var starCount = 1;
|
|
95
|
+
while (str[i + 1] === "*") {
|
|
96
|
+
starCount++;
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
var nextChar = str[i + 1];
|
|
100
|
+
if (!globstar) {
|
|
101
|
+
// globstar is disabled, so treat any number of "*" as one
|
|
102
|
+
reStr += ".*";
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
// globstar is enabled, so determine if this is a globstar segment
|
|
106
|
+
var isGlobstar = starCount > 1 // multiple "*"'s
|
|
107
|
+
&& (prevChar === "/" || prevChar === undefined || prevChar === '{' || prevChar === ',') // from the start of the segment
|
|
108
|
+
&& (nextChar === "/" || nextChar === undefined || nextChar === ',' || nextChar === '}'); // to the end of the segment
|
|
109
|
+
if (isGlobstar) {
|
|
110
|
+
if (nextChar === "/") {
|
|
111
|
+
i++; // move over the "/"
|
|
112
|
+
}
|
|
113
|
+
else if (prevChar === '/' && reStr.endsWith('\\/')) {
|
|
114
|
+
reStr = reStr.substr(0, reStr.length - 2);
|
|
115
|
+
}
|
|
116
|
+
// it's a globstar, so match zero or more path segments
|
|
117
|
+
reStr += "((?:[^/]*(?:\/|$))*)";
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// it's not a globstar, so only match one path segment
|
|
121
|
+
reStr += "([^/]*)";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
reStr += c;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// When regexp 'g' flag is specified don't
|
|
130
|
+
// constrain the regular expression with ^ & $
|
|
131
|
+
if (!flags || !~flags.indexOf('g')) {
|
|
132
|
+
reStr = "^" + reStr + "$";
|
|
133
|
+
}
|
|
134
|
+
return new RegExp(reStr, flags);
|
|
135
|
+
}
|
|
136
|
+
exports.createRegex = createRegex;
|
|
137
|
+
;
|
|
138
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
(function (factory) {
|
|
6
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
+
var v = factory(require, exports);
|
|
8
|
+
if (v !== undefined) module.exports = v;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof define === "function" && define.amd) {
|
|
11
|
+
define(["require", "exports"], factory);
|
|
12
|
+
}
|
|
13
|
+
})(function (require, exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.stringifyObject = void 0;
|
|
17
|
+
function stringifyObject(obj, indent, stringifyLiteral) {
|
|
18
|
+
if (obj !== null && typeof obj === 'object') {
|
|
19
|
+
var newIndent = indent + '\t';
|
|
20
|
+
if (Array.isArray(obj)) {
|
|
21
|
+
if (obj.length === 0) {
|
|
22
|
+
return '[]';
|
|
23
|
+
}
|
|
24
|
+
var result = '[\n';
|
|
25
|
+
for (var i = 0; i < obj.length; i++) {
|
|
26
|
+
result += newIndent + stringifyObject(obj[i], newIndent, stringifyLiteral);
|
|
27
|
+
if (i < obj.length - 1) {
|
|
28
|
+
result += ',';
|
|
29
|
+
}
|
|
30
|
+
result += '\n';
|
|
31
|
+
}
|
|
32
|
+
result += indent + ']';
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
var keys = Object.keys(obj);
|
|
37
|
+
if (keys.length === 0) {
|
|
38
|
+
return '{}';
|
|
39
|
+
}
|
|
40
|
+
var result = '{\n';
|
|
41
|
+
for (var i = 0; i < keys.length; i++) {
|
|
42
|
+
var key = keys[i];
|
|
43
|
+
result += newIndent + JSON.stringify(key) + ': ' + stringifyObject(obj[key], newIndent, stringifyLiteral);
|
|
44
|
+
if (i < keys.length - 1) {
|
|
45
|
+
result += ',';
|
|
46
|
+
}
|
|
47
|
+
result += '\n';
|
|
48
|
+
}
|
|
49
|
+
result += indent + '}';
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return stringifyLiteral(obj);
|
|
54
|
+
}
|
|
55
|
+
exports.stringifyObject = stringifyObject;
|
|
56
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
(function (factory) {
|
|
6
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
+
var v = factory(require, exports);
|
|
8
|
+
if (v !== undefined) module.exports = v;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof define === "function" && define.amd) {
|
|
11
|
+
define(["require", "exports"], factory);
|
|
12
|
+
}
|
|
13
|
+
})(function (require, exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.isString = exports.isBoolean = exports.isDefined = exports.isNumber = exports.equals = void 0;
|
|
17
|
+
function equals(one, other) {
|
|
18
|
+
if (one === other) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (one === null || one === undefined || other === null || other === undefined) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (typeof one !== typeof other) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (typeof one !== 'object') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if ((Array.isArray(one)) !== (Array.isArray(other))) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
var i, key;
|
|
34
|
+
if (Array.isArray(one)) {
|
|
35
|
+
if (one.length !== other.length) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
for (i = 0; i < one.length; i++) {
|
|
39
|
+
if (!equals(one[i], other[i])) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
var oneKeys = [];
|
|
46
|
+
for (key in one) {
|
|
47
|
+
oneKeys.push(key);
|
|
48
|
+
}
|
|
49
|
+
oneKeys.sort();
|
|
50
|
+
var otherKeys = [];
|
|
51
|
+
for (key in other) {
|
|
52
|
+
otherKeys.push(key);
|
|
53
|
+
}
|
|
54
|
+
otherKeys.sort();
|
|
55
|
+
if (!equals(oneKeys, otherKeys)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
for (i = 0; i < oneKeys.length; i++) {
|
|
59
|
+
if (!equals(one[oneKeys[i]], other[oneKeys[i]])) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
exports.equals = equals;
|
|
67
|
+
function isNumber(val) {
|
|
68
|
+
return typeof val === 'number';
|
|
69
|
+
}
|
|
70
|
+
exports.isNumber = isNumber;
|
|
71
|
+
function isDefined(val) {
|
|
72
|
+
return typeof val !== 'undefined';
|
|
73
|
+
}
|
|
74
|
+
exports.isDefined = isDefined;
|
|
75
|
+
function isBoolean(val) {
|
|
76
|
+
return typeof val === 'boolean';
|
|
77
|
+
}
|
|
78
|
+
exports.isBoolean = isBoolean;
|
|
79
|
+
function isString(val) {
|
|
80
|
+
return typeof val === 'string';
|
|
81
|
+
}
|
|
82
|
+
exports.isString = isString;
|
|
83
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
(function (factory) {
|
|
6
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
+
var v = factory(require, exports);
|
|
8
|
+
if (v !== undefined) module.exports = v;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof define === "function" && define.amd) {
|
|
11
|
+
define(["require", "exports"], factory);
|
|
12
|
+
}
|
|
13
|
+
})(function (require, exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.extendedRegExp = exports.repeat = exports.convertSimple2RegExpPattern = exports.endsWith = exports.startsWith = void 0;
|
|
17
|
+
function startsWith(haystack, needle) {
|
|
18
|
+
if (haystack.length < needle.length) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
for (var i = 0; i < needle.length; i++) {
|
|
22
|
+
if (haystack[i] !== needle[i]) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
exports.startsWith = startsWith;
|
|
29
|
+
/**
|
|
30
|
+
* Determines if haystack ends with needle.
|
|
31
|
+
*/
|
|
32
|
+
function endsWith(haystack, needle) {
|
|
33
|
+
var diff = haystack.length - needle.length;
|
|
34
|
+
if (diff > 0) {
|
|
35
|
+
return haystack.lastIndexOf(needle) === diff;
|
|
36
|
+
}
|
|
37
|
+
else if (diff === 0) {
|
|
38
|
+
return haystack === needle;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.endsWith = endsWith;
|
|
45
|
+
function convertSimple2RegExpPattern(pattern) {
|
|
46
|
+
return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
|
|
47
|
+
}
|
|
48
|
+
exports.convertSimple2RegExpPattern = convertSimple2RegExpPattern;
|
|
49
|
+
function repeat(value, count) {
|
|
50
|
+
var s = '';
|
|
51
|
+
while (count > 0) {
|
|
52
|
+
if ((count & 1) === 1) {
|
|
53
|
+
s += value;
|
|
54
|
+
}
|
|
55
|
+
value += value;
|
|
56
|
+
count = count >>> 1;
|
|
57
|
+
}
|
|
58
|
+
return s;
|
|
59
|
+
}
|
|
60
|
+
exports.repeat = repeat;
|
|
61
|
+
function extendedRegExp(pattern) {
|
|
62
|
+
if (startsWith(pattern, '(?i)')) {
|
|
63
|
+
return new RegExp(pattern.substring(4), 'i');
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return new RegExp(pattern);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.extendedRegExp = extendedRegExp;
|
|
70
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vscode-json-languageservice",
|
|
3
|
+
"version": "4.1.8",
|
|
4
|
+
"description": "Language service for JSON",
|
|
5
|
+
"main": "./lib/umd/jsonLanguageService.js",
|
|
6
|
+
"typings": "./lib/umd/jsonLanguageService",
|
|
7
|
+
"module": "./lib/esm/jsonLanguageService.js",
|
|
8
|
+
"author": "Microsoft Corporation",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Microsoft/vscode-json-languageservice"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Microsoft/vscode-json-languageservice"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"npm": ">=7.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/mocha": "^8.2.0",
|
|
22
|
+
"@types/node": "^10.12.21",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^4.14.0",
|
|
24
|
+
"@typescript-eslint/parser": "^4.14.0",
|
|
25
|
+
"eslint": "^7.18.0",
|
|
26
|
+
"mocha": "^8.2.1",
|
|
27
|
+
"rimraf": "^3.0.2",
|
|
28
|
+
"typescript": "^4.1.3"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"jsonc-parser": "^3.0.0",
|
|
32
|
+
"vscode-languageserver-textdocument": "^1.0.1",
|
|
33
|
+
"vscode-languageserver-types": "^3.16.0",
|
|
34
|
+
"vscode-nls": "^5.0.0",
|
|
35
|
+
"vscode-uri": "^3.0.2"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"prepublishOnly": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
|
|
39
|
+
"postpublish": "node ./build/post-publish.js",
|
|
40
|
+
"compile": "tsc -p ./src",
|
|
41
|
+
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
|
|
42
|
+
"clean": "rimraf lib",
|
|
43
|
+
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
|
|
44
|
+
"watch": "tsc -w -p ./src",
|
|
45
|
+
"pretest": "npm run compile",
|
|
46
|
+
"test": "mocha",
|
|
47
|
+
"posttest": "npm run lint",
|
|
48
|
+
"coverage": "npx nyc -r lcov npm run test",
|
|
49
|
+
"lint": "eslint src/**/*.ts",
|
|
50
|
+
"install-types-next": "npm install vscode-languageserver-types@next -f -S && npm install vscode-languageserver-textdocument@next -f -S",
|
|
51
|
+
"preversion": "npm test",
|
|
52
|
+
"postversion": "git push && git push --tags",
|
|
53
|
+
"sample": "npm run compile && node ./lib/umd/example/sample.js"
|
|
54
|
+
}
|
|
55
|
+
}
|