vscode-json-languageservice 5.7.2 → 6.0.0-next.2

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/lib/esm/jsonContributions.d.ts +1 -1
  3. package/lib/esm/jsonLanguageService.d.ts +2 -2
  4. package/lib/esm/jsonLanguageService.js +13 -13
  5. package/lib/esm/jsonLanguageTypes.d.ts +10 -2
  6. package/lib/esm/jsonSchema.d.ts +71 -2
  7. package/lib/esm/parser/jsonParser.js +224 -93
  8. package/lib/esm/services/configuration.js +2 -2
  9. package/lib/esm/services/jsonCompletion.js +5 -5
  10. package/lib/esm/services/jsonDocumentSymbols.js +4 -4
  11. package/lib/esm/services/jsonFolding.js +1 -1
  12. package/lib/esm/services/jsonHover.js +2 -2
  13. package/lib/esm/services/jsonLinks.js +94 -3
  14. package/lib/esm/services/jsonSchemaService.js +639 -100
  15. package/lib/esm/services/jsonSelectionRanges.js +1 -1
  16. package/lib/esm/services/jsonValidation.js +4 -4
  17. package/lib/esm/services/schemas/draft-2019-09-flat.d.ts +1 -1
  18. package/lib/esm/services/schemas/draft-2020-12-flat.d.ts +1 -1
  19. package/lib/esm/services/vocabularies.js +139 -0
  20. package/lib/esm/utils/format.js +1 -1
  21. package/lib/esm/utils/sort.js +3 -3
  22. package/package.json +23 -20
  23. package/lib/umd/jsonContributions.d.ts +0 -21
  24. package/lib/umd/jsonContributions.js +0 -12
  25. package/lib/umd/jsonLanguageService.d.ts +0 -30
  26. package/lib/umd/jsonLanguageService.js +0 -79
  27. package/lib/umd/jsonLanguageTypes.d.ts +0 -305
  28. package/lib/umd/jsonLanguageTypes.js +0 -109
  29. package/lib/umd/jsonSchema.d.ts +0 -92
  30. package/lib/umd/jsonSchema.js +0 -12
  31. package/lib/umd/parser/jsonParser.js +0 -1365
  32. package/lib/umd/services/configuration.js +0 -536
  33. package/lib/umd/services/jsonCompletion.js +0 -982
  34. package/lib/umd/services/jsonDocumentSymbols.js +0 -285
  35. package/lib/umd/services/jsonFolding.js +0 -133
  36. package/lib/umd/services/jsonHover.js +0 -125
  37. package/lib/umd/services/jsonLinks.js +0 -85
  38. package/lib/umd/services/jsonSchemaService.js +0 -631
  39. package/lib/umd/services/jsonSelectionRanges.js +0 -74
  40. package/lib/umd/services/jsonValidation.js +0 -165
  41. package/lib/umd/services/schemas/draft-2019-09-flat.d.ts +0 -278
  42. package/lib/umd/services/schemas/draft-2019-09-flat.js +0 -314
  43. package/lib/umd/services/schemas/draft-2020-12-flat.d.ts +0 -276
  44. package/lib/umd/services/schemas/draft-2020-12-flat.js +0 -307
  45. package/lib/umd/utils/colors.js +0 -83
  46. package/lib/umd/utils/format.js +0 -33
  47. package/lib/umd/utils/glob.js +0 -137
  48. package/lib/umd/utils/json.js +0 -55
  49. package/lib/umd/utils/objects.js +0 -86
  50. package/lib/umd/utils/propertyTree.js +0 -90
  51. package/lib/umd/utils/sort.js +0 -384
  52. package/lib/umd/utils/strings.js +0 -97
@@ -1,74 +0,0 @@
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", "../jsonLanguageTypes", "jsonc-parser"], factory);
12
- }
13
- })(function (require, exports) {
14
- "use strict";
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.getSelectionRanges = getSelectionRanges;
17
- const jsonLanguageTypes_1 = require("../jsonLanguageTypes");
18
- const jsonc_parser_1 = require("jsonc-parser");
19
- function getSelectionRanges(document, positions, doc) {
20
- function getSelectionRange(position) {
21
- let offset = document.offsetAt(position);
22
- let node = doc.getNodeFromOffset(offset, true);
23
- const result = [];
24
- while (node) {
25
- switch (node.type) {
26
- case 'string':
27
- case 'object':
28
- case 'array':
29
- // range without ", [ or {
30
- const cStart = node.offset + 1, cEnd = node.offset + node.length - 1;
31
- if (cStart < cEnd && offset >= cStart && offset <= cEnd) {
32
- result.push(newRange(cStart, cEnd));
33
- }
34
- result.push(newRange(node.offset, node.offset + node.length));
35
- break;
36
- case 'number':
37
- case 'boolean':
38
- case 'null':
39
- case 'property':
40
- result.push(newRange(node.offset, node.offset + node.length));
41
- break;
42
- }
43
- if (node.type === 'property' || node.parent && node.parent.type === 'array') {
44
- const afterCommaOffset = getOffsetAfterNextToken(node.offset + node.length, 5 /* SyntaxKind.CommaToken */);
45
- if (afterCommaOffset !== -1) {
46
- result.push(newRange(node.offset, afterCommaOffset));
47
- }
48
- }
49
- node = node.parent;
50
- }
51
- let current = undefined;
52
- for (let index = result.length - 1; index >= 0; index--) {
53
- current = jsonLanguageTypes_1.SelectionRange.create(result[index], current);
54
- }
55
- if (!current) {
56
- current = jsonLanguageTypes_1.SelectionRange.create(jsonLanguageTypes_1.Range.create(position, position));
57
- }
58
- return current;
59
- }
60
- function newRange(start, end) {
61
- return jsonLanguageTypes_1.Range.create(document.positionAt(start), document.positionAt(end));
62
- }
63
- const scanner = (0, jsonc_parser_1.createScanner)(document.getText(), true);
64
- function getOffsetAfterNextToken(offset, expectedToken) {
65
- scanner.setPosition(offset);
66
- let token = scanner.scan();
67
- if (token === expectedToken) {
68
- return scanner.getTokenOffset() + scanner.getTokenLength();
69
- }
70
- return -1;
71
- }
72
- return positions.map(getSelectionRange);
73
- }
74
- });
@@ -1,165 +0,0 @@
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", "../jsonLanguageTypes", "@vscode/l10n", "../utils/objects"], factory);
12
- }
13
- })(function (require, exports) {
14
- "use strict";
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.JSONValidation = void 0;
17
- const jsonLanguageTypes_1 = require("../jsonLanguageTypes");
18
- const l10n = require("@vscode/l10n");
19
- const objects_1 = require("../utils/objects");
20
- class JSONValidation {
21
- constructor(jsonSchemaService, promiseConstructor) {
22
- this.jsonSchemaService = jsonSchemaService;
23
- this.promise = promiseConstructor;
24
- this.validationEnabled = true;
25
- }
26
- configure(raw) {
27
- if (raw) {
28
- this.validationEnabled = raw.validate !== false;
29
- this.commentSeverity = raw.allowComments ? undefined : jsonLanguageTypes_1.DiagnosticSeverity.Error;
30
- }
31
- }
32
- doValidation(textDocument, jsonDocument, documentSettings, schema) {
33
- if (!this.validationEnabled) {
34
- return this.promise.resolve([]);
35
- }
36
- const diagnostics = [];
37
- const added = {};
38
- const addProblem = (problem) => {
39
- // remove duplicated messages
40
- const signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
41
- if (!added[signature]) {
42
- added[signature] = true;
43
- diagnostics.push(problem);
44
- }
45
- };
46
- const getDiagnostics = (schema) => {
47
- let trailingCommaSeverity = documentSettings?.trailingCommas ? toDiagnosticSeverity(documentSettings.trailingCommas) : jsonLanguageTypes_1.DiagnosticSeverity.Error;
48
- let commentSeverity = documentSettings?.comments ? toDiagnosticSeverity(documentSettings.comments) : this.commentSeverity;
49
- let schemaValidation = documentSettings?.schemaValidation ? toDiagnosticSeverity(documentSettings.schemaValidation) : jsonLanguageTypes_1.DiagnosticSeverity.Warning;
50
- let schemaRequest = documentSettings?.schemaRequest ? toDiagnosticSeverity(documentSettings.schemaRequest) : jsonLanguageTypes_1.DiagnosticSeverity.Warning;
51
- if (schema) {
52
- const addSchemaProblem = (errorMessage, errorCode, relatedInformation) => {
53
- if (jsonDocument.root && schemaRequest) {
54
- const astRoot = jsonDocument.root;
55
- const property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
56
- if (property && property.keyNode.value === '$schema') {
57
- const node = property.valueNode || property;
58
- const range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
59
- addProblem(jsonLanguageTypes_1.Diagnostic.create(range, errorMessage, schemaRequest, errorCode, 'json', relatedInformation));
60
- }
61
- else {
62
- const range = jsonLanguageTypes_1.Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
63
- addProblem(jsonLanguageTypes_1.Diagnostic.create(range, errorMessage, schemaRequest, errorCode, 'json', relatedInformation));
64
- }
65
- }
66
- };
67
- if (schema.errors.length) {
68
- const error = schema.errors[0];
69
- addSchemaProblem(error.message, error.code, error.relatedInformation);
70
- }
71
- else if (schemaValidation) {
72
- for (const warning of schema.warnings) {
73
- addSchemaProblem(warning.message, warning.code, warning.relatedInformation);
74
- }
75
- const semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation, documentSettings?.schemaDraft);
76
- if (semanticErrors) {
77
- semanticErrors.forEach(addProblem);
78
- }
79
- }
80
- if (schemaAllowsComments(schema.schema)) {
81
- commentSeverity = undefined;
82
- }
83
- if (schemaAllowsTrailingCommas(schema.schema)) {
84
- trailingCommaSeverity = undefined;
85
- }
86
- }
87
- for (const p of jsonDocument.syntaxErrors) {
88
- if (p.code === jsonLanguageTypes_1.ErrorCode.TrailingComma) {
89
- if (typeof trailingCommaSeverity !== 'number') {
90
- continue;
91
- }
92
- p.severity = trailingCommaSeverity;
93
- }
94
- addProblem(p);
95
- }
96
- if (typeof commentSeverity === 'number') {
97
- const message = l10n.t('Comments are not permitted in JSON.');
98
- jsonDocument.comments.forEach(c => {
99
- addProblem(jsonLanguageTypes_1.Diagnostic.create(c, message, commentSeverity, jsonLanguageTypes_1.ErrorCode.CommentNotPermitted));
100
- });
101
- }
102
- return diagnostics;
103
- };
104
- if (schema) {
105
- const uri = schema.id || ('schemaservice://untitled/' + idCounter++);
106
- const handle = this.jsonSchemaService.registerExternalSchema({ uri, schema });
107
- return handle.getResolvedSchema().then(resolvedSchema => {
108
- return getDiagnostics(resolvedSchema);
109
- });
110
- }
111
- return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(schema => {
112
- return getDiagnostics(schema);
113
- });
114
- }
115
- getLanguageStatus(textDocument, jsonDocument) {
116
- return { schemas: this.jsonSchemaService.getSchemaURIsForResource(textDocument.uri, jsonDocument) };
117
- }
118
- }
119
- exports.JSONValidation = JSONValidation;
120
- let idCounter = 0;
121
- function schemaAllowsComments(schemaRef) {
122
- if (schemaRef && typeof schemaRef === 'object') {
123
- if ((0, objects_1.isBoolean)(schemaRef.allowComments)) {
124
- return schemaRef.allowComments;
125
- }
126
- if (schemaRef.allOf) {
127
- for (const schema of schemaRef.allOf) {
128
- const allow = schemaAllowsComments(schema);
129
- if ((0, objects_1.isBoolean)(allow)) {
130
- return allow;
131
- }
132
- }
133
- }
134
- }
135
- return undefined;
136
- }
137
- function schemaAllowsTrailingCommas(schemaRef) {
138
- if (schemaRef && typeof schemaRef === 'object') {
139
- if ((0, objects_1.isBoolean)(schemaRef.allowTrailingCommas)) {
140
- return schemaRef.allowTrailingCommas;
141
- }
142
- const deprSchemaRef = schemaRef;
143
- if ((0, objects_1.isBoolean)(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
144
- return deprSchemaRef['allowsTrailingCommas'];
145
- }
146
- if (schemaRef.allOf) {
147
- for (const schema of schemaRef.allOf) {
148
- const allow = schemaAllowsTrailingCommas(schema);
149
- if ((0, objects_1.isBoolean)(allow)) {
150
- return allow;
151
- }
152
- }
153
- }
154
- }
155
- return undefined;
156
- }
157
- function toDiagnosticSeverity(severityLevel) {
158
- switch (severityLevel) {
159
- case 'error': return jsonLanguageTypes_1.DiagnosticSeverity.Error;
160
- case 'warning': return jsonLanguageTypes_1.DiagnosticSeverity.Warning;
161
- case 'ignore': return undefined;
162
- }
163
- return undefined;
164
- }
165
- });
@@ -1,278 +0,0 @@
1
- declare const _default: {
2
- $id: string;
3
- $schema: string;
4
- title: string;
5
- type: string[];
6
- properties: {
7
- definitions: {
8
- $comment: string;
9
- type: string;
10
- additionalProperties: {
11
- $ref: string;
12
- };
13
- default: {};
14
- };
15
- dependencies: {
16
- $comment: string;
17
- type: string;
18
- additionalProperties: {
19
- anyOf: {
20
- $ref: string;
21
- }[];
22
- };
23
- };
24
- $id: {
25
- type: string;
26
- format: string;
27
- $comment: string;
28
- pattern: string;
29
- };
30
- $schema: {
31
- type: string;
32
- format: string;
33
- };
34
- $anchor: {
35
- type: string;
36
- pattern: string;
37
- };
38
- $ref: {
39
- type: string;
40
- format: string;
41
- };
42
- $recursiveAnchor: {
43
- type: string;
44
- default: boolean;
45
- };
46
- $vocabulary: {
47
- type: string;
48
- propertyNames: {
49
- type: string;
50
- format: string;
51
- };
52
- additionalProperties: {
53
- type: string;
54
- };
55
- };
56
- $comment: {
57
- type: string;
58
- };
59
- $defs: {
60
- type: string;
61
- additionalProperties: {
62
- $ref: string;
63
- };
64
- default: {};
65
- };
66
- additionalItems: {
67
- $ref: string;
68
- };
69
- unevaluatedItems: {
70
- $ref: string;
71
- };
72
- items: {
73
- anyOf: {
74
- $ref: string;
75
- }[];
76
- };
77
- contains: {
78
- $ref: string;
79
- };
80
- additionalProperties: {
81
- $ref: string;
82
- };
83
- unevaluatedProperties: {
84
- $ref: string;
85
- };
86
- properties: {
87
- type: string;
88
- additionalProperties: {
89
- $ref: string;
90
- };
91
- default: {};
92
- };
93
- patternProperties: {
94
- type: string;
95
- additionalProperties: {
96
- $ref: string;
97
- };
98
- propertyNames: {
99
- format: string;
100
- };
101
- default: {};
102
- };
103
- dependentSchemas: {
104
- type: string;
105
- additionalProperties: {
106
- $ref: string;
107
- };
108
- };
109
- propertyNames: {
110
- $ref: string;
111
- };
112
- if: {
113
- $ref: string;
114
- };
115
- then: {
116
- $ref: string;
117
- };
118
- else: {
119
- $ref: string;
120
- };
121
- allOf: {
122
- $ref: string;
123
- };
124
- anyOf: {
125
- $ref: string;
126
- };
127
- oneOf: {
128
- $ref: string;
129
- };
130
- not: {
131
- $ref: string;
132
- };
133
- multipleOf: {
134
- type: string;
135
- exclusiveMinimum: number;
136
- };
137
- maximum: {
138
- type: string;
139
- };
140
- exclusiveMaximum: {
141
- type: string;
142
- };
143
- minimum: {
144
- type: string;
145
- };
146
- exclusiveMinimum: {
147
- type: string;
148
- };
149
- maxLength: {
150
- $ref: string;
151
- };
152
- minLength: {
153
- $ref: string;
154
- };
155
- pattern: {
156
- type: string;
157
- format: string;
158
- };
159
- maxItems: {
160
- $ref: string;
161
- };
162
- minItems: {
163
- $ref: string;
164
- };
165
- uniqueItems: {
166
- type: string;
167
- default: boolean;
168
- };
169
- maxContains: {
170
- $ref: string;
171
- };
172
- minContains: {
173
- $ref: string;
174
- default: number;
175
- };
176
- maxProperties: {
177
- $ref: string;
178
- };
179
- minProperties: {
180
- $ref: string;
181
- };
182
- required: {
183
- $ref: string;
184
- };
185
- dependentRequired: {
186
- type: string;
187
- additionalProperties: {
188
- $ref: string;
189
- };
190
- };
191
- const: boolean;
192
- enum: {
193
- type: string;
194
- items: boolean;
195
- };
196
- type: {
197
- anyOf: ({
198
- $ref: string;
199
- type?: undefined;
200
- items?: undefined;
201
- minItems?: undefined;
202
- uniqueItems?: undefined;
203
- } | {
204
- type: string;
205
- items: {
206
- $ref: string;
207
- };
208
- minItems: number;
209
- uniqueItems: boolean;
210
- $ref?: undefined;
211
- })[];
212
- };
213
- title: {
214
- type: string;
215
- };
216
- description: {
217
- type: string;
218
- };
219
- default: boolean;
220
- deprecated: {
221
- type: string;
222
- default: boolean;
223
- };
224
- readOnly: {
225
- type: string;
226
- default: boolean;
227
- };
228
- writeOnly: {
229
- type: string;
230
- default: boolean;
231
- };
232
- examples: {
233
- type: string;
234
- items: boolean;
235
- };
236
- format: {
237
- type: string;
238
- };
239
- contentMediaType: {
240
- type: string;
241
- };
242
- contentEncoding: {
243
- type: string;
244
- };
245
- contentSchema: {
246
- $ref: string;
247
- };
248
- };
249
- $defs: {
250
- schemaArray: {
251
- type: string;
252
- minItems: number;
253
- items: {
254
- $ref: string;
255
- };
256
- };
257
- nonNegativeInteger: {
258
- type: string;
259
- minimum: number;
260
- };
261
- nonNegativeIntegerDefault0: {
262
- $ref: string;
263
- default: number;
264
- };
265
- simpleTypes: {
266
- enum: string[];
267
- };
268
- stringArray: {
269
- type: string;
270
- items: {
271
- type: string;
272
- };
273
- uniqueItems: boolean;
274
- default: never[];
275
- };
276
- };
277
- };
278
- export default _default;