vscode-json-languageservice 4.2.0-next.0 → 4.2.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 +1 -0
- package/lib/esm/parser/jsonParser.js +7 -1
- package/lib/esm/services/configuration.js +1 -1
- package/lib/esm/services/jsonCompletion.js +2 -2
- package/lib/esm/services/jsonDocumentSymbols.js +3 -3
- package/lib/esm/services/jsonHover.js +1 -1
- package/lib/esm/services/jsonLinks.js +1 -1
- package/lib/esm/services/jsonSchemaService.js +143 -96
- package/lib/esm/services/jsonValidation.js +2 -2
- package/lib/umd/jsonLanguageService.js +3 -3
- package/lib/umd/parser/jsonParser.js +31 -25
- package/lib/umd/services/configuration.js +1 -1
- package/lib/umd/services/jsonCompletion.js +12 -12
- package/lib/umd/services/jsonDocumentSymbols.js +4 -4
- package/lib/umd/services/jsonFolding.js +1 -1
- package/lib/umd/services/jsonHover.js +1 -1
- package/lib/umd/services/jsonLinks.js +1 -1
- package/lib/umd/services/jsonSchemaService.js +144 -97
- package/lib/umd/services/jsonSelectionRanges.js +1 -1
- package/lib/umd/services/jsonValidation.js +8 -8
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -28,7 +28,10 @@ var formats = {
|
|
|
28
28
|
'date-time': { errorMessage: localize('dateTimeFormatWarning', 'String is not a RFC3339 date-time.'), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
|
|
29
29
|
'date': { errorMessage: localize('dateFormatWarning', 'String is not a RFC3339 date.'), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/i },
|
|
30
30
|
'time': { errorMessage: localize('timeFormatWarning', 'String is not a RFC3339 time.'), pattern: /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
|
|
31
|
-
'email': { errorMessage: localize('emailFormatWarning', 'String is not an e-mail address.'), pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-
|
|
31
|
+
'email': { errorMessage: localize('emailFormatWarning', 'String is not an e-mail address.'), pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/ },
|
|
32
|
+
'hostname': { errorMessage: localize('hostnameFormatWarning', 'String is not a hostname.'), pattern: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i },
|
|
33
|
+
'ipv4': { errorMessage: localize('ipv4FormatWarning', 'String is not an IPv4 address.'), pattern: /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/ },
|
|
34
|
+
'ipv6': { errorMessage: localize('ipv6FormatWarning', 'String is not an IPv6 address.'), pattern: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i },
|
|
32
35
|
};
|
|
33
36
|
var ASTNodeImpl = /** @class */ (function () {
|
|
34
37
|
function ASTNodeImpl(parent, offset, length) {
|
|
@@ -655,6 +658,9 @@ function validate(n, schema, validationResult, matchingSchemas) {
|
|
|
655
658
|
case 'date':
|
|
656
659
|
case 'time':
|
|
657
660
|
case 'email':
|
|
661
|
+
case 'hostname':
|
|
662
|
+
case 'ipv4':
|
|
663
|
+
case 'ipv6':
|
|
658
664
|
var format = formats[schema.format];
|
|
659
665
|
if (!node.value || !format.pattern.exec(node.value)) {
|
|
660
666
|
validationResult.problems.push({
|
|
@@ -522,7 +522,7 @@ for (var schemaName in schemaContributions.schemas) {
|
|
|
522
522
|
propertyObject['description'] = description;
|
|
523
523
|
}
|
|
524
524
|
else {
|
|
525
|
-
console.log(property
|
|
525
|
+
console.log("".concat(property, ": localize('schema.json.").concat(property, "', \"\")"));
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
528
|
}
|
|
@@ -218,7 +218,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
218
218
|
if (propertySchema.suggestSortText !== undefined) {
|
|
219
219
|
proposal.sortText = propertySchema.suggestSortText;
|
|
220
220
|
}
|
|
221
|
-
if (proposal.insertText && endsWith(proposal.insertText, "$1"
|
|
221
|
+
if (proposal.insertText && endsWith(proposal.insertText, "$1".concat(separatorAfter))) {
|
|
222
222
|
proposal.command = {
|
|
223
223
|
title: 'Suggest',
|
|
224
224
|
command: 'editor.action.triggerSuggest'
|
|
@@ -243,7 +243,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
243
243
|
if (schemaPropertyNames_1.suggestSortText !== undefined) {
|
|
244
244
|
proposal.sortText = schemaPropertyNames_1.suggestSortText;
|
|
245
245
|
}
|
|
246
|
-
if (proposal.insertText && endsWith(proposal.insertText, "$1"
|
|
246
|
+
if (proposal.insertText && endsWith(proposal.insertText, "$1".concat(separatorAfter))) {
|
|
247
247
|
proposal.command = {
|
|
248
248
|
title: 'Suggest',
|
|
249
249
|
command: 'editor.action.triggerSuggest'
|
|
@@ -202,7 +202,7 @@ var JSONDocumentSymbols = /** @class */ (function () {
|
|
|
202
202
|
if (name && name.trim()) {
|
|
203
203
|
return name;
|
|
204
204
|
}
|
|
205
|
-
return "\""
|
|
205
|
+
return "\"".concat(name, "\"");
|
|
206
206
|
};
|
|
207
207
|
JSONDocumentSymbols.prototype.getDetail = function (node) {
|
|
208
208
|
if (!node) {
|
|
@@ -262,10 +262,10 @@ var JSONDocumentSymbols = /** @class */ (function () {
|
|
|
262
262
|
}
|
|
263
263
|
var label;
|
|
264
264
|
if (color.alpha === 1) {
|
|
265
|
-
label = "#"
|
|
265
|
+
label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256));
|
|
266
266
|
}
|
|
267
267
|
else {
|
|
268
|
-
label = "#"
|
|
268
|
+
label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256)).concat(toTwoDigitHex(Math.round(color.alpha * 255)));
|
|
269
269
|
}
|
|
270
270
|
result.push({ label: label, textEdit: TextEdit.replace(range, JSON.stringify(label)) });
|
|
271
271
|
return result;
|
|
@@ -86,7 +86,7 @@ var JSONHover = /** @class */ (function () {
|
|
|
86
86
|
if (result.length > 0) {
|
|
87
87
|
result += "\n\n";
|
|
88
88
|
}
|
|
89
|
-
result += "`"
|
|
89
|
+
result += "`".concat(toMarkdownCodeBlock(enumValue_1), "`: ").concat(markdownEnumValueDescription_1);
|
|
90
90
|
}
|
|
91
91
|
return createHover([result]);
|
|
92
92
|
}
|
|
@@ -13,7 +13,7 @@ export function findLinks(document, doc) {
|
|
|
13
13
|
if (targetNode) {
|
|
14
14
|
var targetPos = document.positionAt(targetNode.offset);
|
|
15
15
|
links.push({
|
|
16
|
-
target: document.uri
|
|
16
|
+
target: "".concat(document.uri, "#").concat(targetPos.line + 1, ",").concat(targetPos.character + 1),
|
|
17
17
|
range: createRange(document, node.valueNode)
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -59,6 +59,7 @@ var SchemaHandle = /** @class */ (function () {
|
|
|
59
59
|
this.service = service;
|
|
60
60
|
this.uri = uri;
|
|
61
61
|
this.dependencies = new Set();
|
|
62
|
+
this.anchors = undefined;
|
|
62
63
|
if (unresolvedSchemaContent) {
|
|
63
64
|
this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
|
|
64
65
|
}
|
|
@@ -73,7 +74,7 @@ var SchemaHandle = /** @class */ (function () {
|
|
|
73
74
|
var _this = this;
|
|
74
75
|
if (!this.resolvedSchema) {
|
|
75
76
|
this.resolvedSchema = this.getUnresolvedSchema().then(function (unresolved) {
|
|
76
|
-
return _this.service.resolveSchemaContent(unresolved, _this
|
|
77
|
+
return _this.service.resolveSchemaContent(unresolved, _this);
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
return this.resolvedSchema;
|
|
@@ -83,6 +84,7 @@ var SchemaHandle = /** @class */ (function () {
|
|
|
83
84
|
this.resolvedSchema = undefined;
|
|
84
85
|
this.unresolvedSchema = undefined;
|
|
85
86
|
this.dependencies.clear();
|
|
87
|
+
this.anchors = undefined;
|
|
86
88
|
return hasChanges;
|
|
87
89
|
};
|
|
88
90
|
return SchemaHandle;
|
|
@@ -290,7 +292,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
290
292
|
return new UnresolvedSchema({}, [localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': {1}.', toDisplayString(url), errorMessage)]);
|
|
291
293
|
});
|
|
292
294
|
};
|
|
293
|
-
JSONSchemaService.prototype.resolveSchemaContent = function (schemaToResolve,
|
|
295
|
+
JSONSchemaService.prototype.resolveSchemaContent = function (schemaToResolve, handle) {
|
|
294
296
|
var _this = this;
|
|
295
297
|
var resolveErrors = schemaToResolve.errors.slice(0);
|
|
296
298
|
var schema = schemaToResolve.schema;
|
|
@@ -307,13 +309,11 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
307
309
|
}
|
|
308
310
|
}
|
|
309
311
|
var contextService = this.contextService;
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
return schema;
|
|
313
|
-
}
|
|
312
|
+
var findSectionByJSONPointer = function (schema, path) {
|
|
313
|
+
path = decodeURIComponent(path);
|
|
314
314
|
var current = schema;
|
|
315
315
|
if (path[0] === '/') {
|
|
316
|
-
path = path.
|
|
316
|
+
path = path.substring(1);
|
|
317
317
|
}
|
|
318
318
|
path.split('/').some(function (part) {
|
|
319
319
|
part = part.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
@@ -322,130 +322,179 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
322
322
|
});
|
|
323
323
|
return current;
|
|
324
324
|
};
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
325
|
+
var findSchemaById = function (schema, handle, id) {
|
|
326
|
+
if (!handle.anchors) {
|
|
327
|
+
handle.anchors = collectAnchors(schema);
|
|
328
|
+
}
|
|
329
|
+
return handle.anchors.get(id);
|
|
330
|
+
};
|
|
331
|
+
var merge = function (target, section) {
|
|
332
|
+
for (var key in section) {
|
|
333
|
+
if (section.hasOwnProperty(key) && !target.hasOwnProperty(key) && key !== 'id' && key !== '$id') {
|
|
334
|
+
target[key] = section[key];
|
|
333
335
|
}
|
|
334
336
|
}
|
|
337
|
+
};
|
|
338
|
+
var mergeRef = function (target, sourceRoot, sourceHandle, refSegment) {
|
|
339
|
+
var section;
|
|
340
|
+
if (refSegment === undefined || refSegment.length === 0) {
|
|
341
|
+
section = sourceRoot;
|
|
342
|
+
}
|
|
343
|
+
else if (refSegment.charAt(0) === '/') {
|
|
344
|
+
// A $ref to a JSON Pointer (i.e #/definitions/foo)
|
|
345
|
+
section = findSectionByJSONPointer(sourceRoot, refSegment);
|
|
346
|
+
}
|
|
335
347
|
else {
|
|
336
|
-
|
|
348
|
+
// A $ref to a sub-schema with an $id (i.e #hello)
|
|
349
|
+
section = findSchemaById(sourceRoot, sourceHandle, refSegment);
|
|
350
|
+
}
|
|
351
|
+
if (section) {
|
|
352
|
+
merge(target, section);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
resolveErrors.push(localize('json.schema.invalidid', '$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment, sourceHandle.uri));
|
|
337
356
|
}
|
|
338
357
|
};
|
|
339
|
-
var resolveExternalLink = function (node, uri, refSegment,
|
|
358
|
+
var resolveExternalLink = function (node, uri, refSegment, parentHandle) {
|
|
340
359
|
if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
|
|
341
|
-
uri = contextService.resolveRelativePath(uri,
|
|
360
|
+
uri = contextService.resolveRelativePath(uri, parentHandle.uri);
|
|
342
361
|
}
|
|
343
362
|
uri = normalizeId(uri);
|
|
344
363
|
var referencedHandle = _this.getOrAddSchemaHandle(uri);
|
|
345
364
|
return referencedHandle.getUnresolvedSchema().then(function (unresolvedSchema) {
|
|
346
|
-
|
|
365
|
+
parentHandle.dependencies.add(uri);
|
|
347
366
|
if (unresolvedSchema.errors.length) {
|
|
348
367
|
var loc = refSegment ? uri + '#' + refSegment : uri;
|
|
349
368
|
resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
|
|
350
369
|
}
|
|
351
|
-
|
|
352
|
-
return resolveRefs(node, unresolvedSchema.schema,
|
|
370
|
+
mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
|
|
371
|
+
return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
|
|
353
372
|
});
|
|
354
373
|
};
|
|
355
|
-
var resolveRefs = function (node, parentSchema,
|
|
356
|
-
if (!node || typeof node !== 'object') {
|
|
357
|
-
return Promise.resolve(null);
|
|
358
|
-
}
|
|
359
|
-
var toWalk = [node];
|
|
360
|
-
var seen = new Set();
|
|
374
|
+
var resolveRefs = function (node, parentSchema, parentHandle) {
|
|
361
375
|
var openPromises = [];
|
|
362
|
-
|
|
363
|
-
var entries = [];
|
|
364
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
365
|
-
entries[_i] = arguments[_i];
|
|
366
|
-
}
|
|
367
|
-
for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
|
|
368
|
-
var entry = entries_1[_a];
|
|
369
|
-
if (typeof entry === 'object') {
|
|
370
|
-
toWalk.push(entry);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
var collectMapEntries = function () {
|
|
375
|
-
var maps = [];
|
|
376
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
377
|
-
maps[_i] = arguments[_i];
|
|
378
|
-
}
|
|
379
|
-
for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
|
|
380
|
-
var map = maps_1[_a];
|
|
381
|
-
if (typeof map === 'object') {
|
|
382
|
-
for (var k in map) {
|
|
383
|
-
var key = k;
|
|
384
|
-
var entry = map[key];
|
|
385
|
-
if (typeof entry === 'object') {
|
|
386
|
-
toWalk.push(entry);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
var collectArrayEntries = function () {
|
|
393
|
-
var arrays = [];
|
|
394
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
395
|
-
arrays[_i] = arguments[_i];
|
|
396
|
-
}
|
|
397
|
-
for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
|
|
398
|
-
var array = arrays_1[_a];
|
|
399
|
-
if (Array.isArray(array)) {
|
|
400
|
-
for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
|
|
401
|
-
var entry = array_1[_b];
|
|
402
|
-
if (typeof entry === 'object') {
|
|
403
|
-
toWalk.push(entry);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
var handleRef = function (next) {
|
|
376
|
+
_this.traverseNodes(node, function (next) {
|
|
410
377
|
var seenRefs = new Set();
|
|
411
378
|
while (next.$ref) {
|
|
412
379
|
var ref = next.$ref;
|
|
413
380
|
var segments = ref.split('#', 2);
|
|
414
381
|
delete next.$ref;
|
|
415
382
|
if (segments[0].length > 0) {
|
|
416
|
-
|
|
383
|
+
// This is a reference to an external schema
|
|
384
|
+
openPromises.push(resolveExternalLink(next, segments[0], segments[1], parentHandle));
|
|
417
385
|
return;
|
|
418
386
|
}
|
|
419
387
|
else {
|
|
388
|
+
// This is a reference inside the current schema
|
|
420
389
|
if (!seenRefs.has(ref)) {
|
|
421
|
-
|
|
390
|
+
var id = segments[1];
|
|
391
|
+
mergeRef(next, parentSchema, parentHandle, id);
|
|
422
392
|
seenRefs.add(ref);
|
|
423
393
|
}
|
|
424
394
|
}
|
|
425
395
|
}
|
|
396
|
+
});
|
|
397
|
+
return _this.promise.all(openPromises);
|
|
398
|
+
};
|
|
399
|
+
var collectAnchors = function (root) {
|
|
400
|
+
var result = new Map();
|
|
401
|
+
_this.traverseNodes(root, function (next) {
|
|
402
|
+
var id = next.$id || next.id;
|
|
403
|
+
if (typeof id === 'string' && id.charAt(0) === '#') {
|
|
404
|
+
// delete next.$id;
|
|
405
|
+
// delete next.id;
|
|
406
|
+
var anchor = id.substring(1);
|
|
407
|
+
if (result.has(anchor)) {
|
|
408
|
+
resolveErrors.push(localize('json.schema.duplicateid', 'Duplicate id declaration: \'{0}\'', id));
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
result.set(anchor, next);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
return result;
|
|
416
|
+
};
|
|
417
|
+
return resolveRefs(schema, schema, handle).then(function (_) {
|
|
418
|
+
return new ResolvedSchema(schema, resolveErrors);
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
JSONSchemaService.prototype.traverseNodes = function (root, handle) {
|
|
422
|
+
if (!root || typeof root !== 'object') {
|
|
423
|
+
return Promise.resolve(null);
|
|
424
|
+
}
|
|
425
|
+
var seen = new Set();
|
|
426
|
+
var collectEntries = function () {
|
|
427
|
+
var entries = [];
|
|
428
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
429
|
+
entries[_i] = arguments[_i];
|
|
430
|
+
}
|
|
431
|
+
for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
|
|
432
|
+
var entry = entries_1[_a];
|
|
433
|
+
if (typeof entry === 'object') {
|
|
434
|
+
toWalk.push(entry);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
var collectMapEntries = function () {
|
|
439
|
+
var maps = [];
|
|
440
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
441
|
+
maps[_i] = arguments[_i];
|
|
442
|
+
}
|
|
443
|
+
for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
|
|
444
|
+
var map = maps_1[_a];
|
|
445
|
+
if (typeof map === 'object') {
|
|
446
|
+
for (var k in map) {
|
|
447
|
+
var key = k;
|
|
448
|
+
var entry = map[key];
|
|
449
|
+
if (typeof entry === 'object') {
|
|
450
|
+
toWalk.push(entry);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var collectArrayEntries = function () {
|
|
457
|
+
var arrays = [];
|
|
458
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
459
|
+
arrays[_i] = arguments[_i];
|
|
460
|
+
}
|
|
461
|
+
for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
|
|
462
|
+
var array = arrays_1[_a];
|
|
463
|
+
if (Array.isArray(array)) {
|
|
464
|
+
for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
|
|
465
|
+
var entry = array_1[_b];
|
|
466
|
+
if (typeof entry === 'object') {
|
|
467
|
+
toWalk.push(entry);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
var toWalk = [root];
|
|
474
|
+
var next = toWalk.pop();
|
|
475
|
+
while (next) {
|
|
476
|
+
if (!seen.has(next)) {
|
|
477
|
+
seen.add(next);
|
|
478
|
+
handle(next);
|
|
426
479
|
collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
|
|
427
480
|
collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
|
|
428
481
|
collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
|
|
429
|
-
};
|
|
430
|
-
while (toWalk.length) {
|
|
431
|
-
var next = toWalk.pop();
|
|
432
|
-
if (seen.has(next)) {
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
seen.add(next);
|
|
436
|
-
handleRef(next);
|
|
437
482
|
}
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
return resolveRefs(schema, schema, schemaURL, dependencies).then(function (_) { return new ResolvedSchema(schema, resolveErrors); });
|
|
483
|
+
next = toWalk.pop();
|
|
484
|
+
}
|
|
441
485
|
};
|
|
442
|
-
|
|
486
|
+
;
|
|
487
|
+
JSONSchemaService.prototype.getSchemaFromProperty = function (resource, document) {
|
|
443
488
|
var _a, _b;
|
|
444
489
|
if (((_a = document.root) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
|
|
445
490
|
for (var _i = 0, _c = document.root.properties; _i < _c.length; _i++) {
|
|
446
491
|
var p = _c[_i];
|
|
447
492
|
if (p.keyNode.value === '$schema' && ((_b = p.valueNode) === null || _b === void 0 ? void 0 : _b.type) === 'string') {
|
|
448
|
-
|
|
493
|
+
var schemaId = p.valueNode.value;
|
|
494
|
+
if (this.contextService && !/^\w[\w\d+.-]*:/.test(schemaId)) { // has scheme
|
|
495
|
+
schemaId = this.contextService.resolveRelativePath(schemaId, resource);
|
|
496
|
+
}
|
|
497
|
+
return schemaId;
|
|
449
498
|
}
|
|
450
499
|
}
|
|
451
500
|
}
|
|
@@ -470,7 +519,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
470
519
|
return schemas;
|
|
471
520
|
};
|
|
472
521
|
JSONSchemaService.prototype.getSchemaURIsForResource = function (resource, document) {
|
|
473
|
-
var schemeId = document && this.
|
|
522
|
+
var schemeId = document && this.getSchemaFromProperty(resource, document);
|
|
474
523
|
if (schemeId) {
|
|
475
524
|
return [schemeId];
|
|
476
525
|
}
|
|
@@ -479,10 +528,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
479
528
|
JSONSchemaService.prototype.getSchemaForResource = function (resource, document) {
|
|
480
529
|
if (document) {
|
|
481
530
|
// first use $schema if present
|
|
482
|
-
var schemeId = this.
|
|
483
|
-
if (schemeId && Strings.startsWith(schemeId, '.') && this.contextService) {
|
|
484
|
-
schemeId = this.contextService.resolveRelativePath(schemeId, resource);
|
|
485
|
-
}
|
|
531
|
+
var schemeId = this.getSchemaFromProperty(resource, document);
|
|
486
532
|
if (schemeId) {
|
|
487
533
|
var id = normalizeId(schemeId);
|
|
488
534
|
return this.getOrAddSchemaHandle(id).getResolvedSchema();
|
|
@@ -511,7 +557,8 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
511
557
|
JSONSchemaService.prototype.getMatchingSchemas = function (document, jsonDocument, schema) {
|
|
512
558
|
if (schema) {
|
|
513
559
|
var id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
|
|
514
|
-
|
|
560
|
+
var handle = this.addSchemaHandle(id, schema);
|
|
561
|
+
return handle.getResolvedSchema().then(function (resolvedSchema) {
|
|
515
562
|
return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(function (s) { return !s.inverted; });
|
|
516
563
|
});
|
|
517
564
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
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
|
-
import { UnresolvedSchema } from './jsonSchemaService';
|
|
6
5
|
import { ErrorCode, Diagnostic, DiagnosticSeverity, Range } from '../jsonLanguageTypes';
|
|
7
6
|
import * as nls from 'vscode-nls';
|
|
8
7
|
import { isBoolean } from '../utils/objects';
|
|
@@ -86,7 +85,8 @@ var JSONValidation = /** @class */ (function () {
|
|
|
86
85
|
};
|
|
87
86
|
if (schema) {
|
|
88
87
|
var id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
|
89
|
-
|
|
88
|
+
var handle = this.jsonSchemaService.registerExternalSchema(id, [], schema);
|
|
89
|
+
return handle.getResolvedSchema().then(function (resolvedSchema) {
|
|
90
90
|
return getDiagnostics(resolvedSchema);
|
|
91
91
|
});
|
|
92
92
|
}
|
|
@@ -58,8 +58,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
58
58
|
resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
|
|
59
59
|
doValidation: jsonValidation.doValidation.bind(jsonValidation),
|
|
60
60
|
getLanguageStatus: jsonValidation.getLanguageStatus.bind(jsonValidation),
|
|
61
|
-
parseJSONDocument: function (document) { return jsonParser_1.parse(document, { collectComments: true }); },
|
|
62
|
-
newJSONDocument: function (root, diagnostics) { return jsonParser_1.newJSONDocument(root, diagnostics); },
|
|
61
|
+
parseJSONDocument: function (document) { return (0, jsonParser_1.parse)(document, { collectComments: true }); },
|
|
62
|
+
newJSONDocument: function (root, diagnostics) { return (0, jsonParser_1.newJSONDocument)(root, diagnostics); },
|
|
63
63
|
getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
|
|
64
64
|
doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
|
|
65
65
|
doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
|
|
@@ -80,7 +80,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
80
80
|
range = { offset: offset, length: length };
|
|
81
81
|
}
|
|
82
82
|
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' };
|
|
83
|
-
return jsonc_parser_1.format(d.getText(), range, options).map(function (e) {
|
|
83
|
+
return (0, jsonc_parser_1.format)(d.getText(), range, options).map(function (e) {
|
|
84
84
|
return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
|
|
85
85
|
});
|
|
86
86
|
}
|