vscode-json-languageservice 4.1.10 → 4.2.0-next.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 +5 -0
- package/lib/esm/jsonLanguageService.d.ts +2 -1
- package/lib/esm/jsonLanguageService.js +1 -0
- package/lib/esm/jsonLanguageTypes.d.ts +3 -0
- package/lib/esm/services/jsonSchemaService.js +60 -37
- package/lib/esm/services/jsonValidation.js +4 -1
- package/lib/umd/jsonLanguageService.d.ts +2 -1
- package/lib/umd/jsonLanguageService.js +1 -0
- package/lib/umd/jsonLanguageTypes.d.ts +3 -0
- package/lib/umd/services/jsonSchemaService.js +60 -37
- package/lib/umd/services/jsonValidation.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, JSONLanguageStatus } from './jsonLanguageTypes';
|
|
2
2
|
import { DocumentLink } from 'vscode-languageserver-types';
|
|
3
3
|
export declare type JSONDocument = {
|
|
4
4
|
root: ASTNode | undefined;
|
|
@@ -12,6 +12,7 @@ export interface LanguageService {
|
|
|
12
12
|
newJSONDocument(rootNode: ASTNode, syntaxDiagnostics?: Diagnostic[]): JSONDocument;
|
|
13
13
|
resetSchema(uri: string): boolean;
|
|
14
14
|
getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): Thenable<MatchingSchema[]>;
|
|
15
|
+
getLanguageStatus(document: TextDocument, jsonDocument: JSONDocument): JSONLanguageStatus;
|
|
15
16
|
doResolve(item: CompletionItem): Thenable<CompletionItem>;
|
|
16
17
|
doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable<CompletionList | null>;
|
|
17
18
|
findDocumentSymbols(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): SymbolInformation[];
|
|
@@ -35,6 +35,7 @@ export function getLanguageService(params) {
|
|
|
35
35
|
},
|
|
36
36
|
resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
|
|
37
37
|
doValidation: jsonValidation.doValidation.bind(jsonValidation),
|
|
38
|
+
getLanguageStatus: jsonValidation.getLanguageStatus.bind(jsonValidation),
|
|
38
39
|
parseJSONDocument: function (document) { return parseJSON(document, { collectComments: true }); },
|
|
39
40
|
newJSONDocument: function (root, diagnostics) { return newJSONDocument(root, diagnostics); },
|
|
40
41
|
getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
|
|
@@ -74,6 +74,9 @@ export interface MatchingSchema {
|
|
|
74
74
|
node: ASTNode;
|
|
75
75
|
schema: JSONSchema;
|
|
76
76
|
}
|
|
77
|
+
export interface JSONLanguageStatus {
|
|
78
|
+
schemas: string[];
|
|
79
|
+
}
|
|
77
80
|
export interface LanguageSettings {
|
|
78
81
|
/**
|
|
79
82
|
* If set, the validator will return syntax and semantic errors.
|
|
@@ -55,17 +55,17 @@ var FilePatternAssociation = /** @class */ (function () {
|
|
|
55
55
|
return FilePatternAssociation;
|
|
56
56
|
}());
|
|
57
57
|
var SchemaHandle = /** @class */ (function () {
|
|
58
|
-
function SchemaHandle(service,
|
|
58
|
+
function SchemaHandle(service, uri, unresolvedSchemaContent) {
|
|
59
59
|
this.service = service;
|
|
60
|
-
this.
|
|
61
|
-
this.dependencies =
|
|
60
|
+
this.uri = uri;
|
|
61
|
+
this.dependencies = new Set();
|
|
62
62
|
if (unresolvedSchemaContent) {
|
|
63
63
|
this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
SchemaHandle.prototype.getUnresolvedSchema = function () {
|
|
67
67
|
if (!this.unresolvedSchema) {
|
|
68
|
-
this.unresolvedSchema = this.service.loadSchema(this.
|
|
68
|
+
this.unresolvedSchema = this.service.loadSchema(this.uri);
|
|
69
69
|
}
|
|
70
70
|
return this.unresolvedSchema;
|
|
71
71
|
};
|
|
@@ -73,15 +73,17 @@ var SchemaHandle = /** @class */ (function () {
|
|
|
73
73
|
var _this = this;
|
|
74
74
|
if (!this.resolvedSchema) {
|
|
75
75
|
this.resolvedSchema = this.getUnresolvedSchema().then(function (unresolved) {
|
|
76
|
-
return _this.service.resolveSchemaContent(unresolved, _this.
|
|
76
|
+
return _this.service.resolveSchemaContent(unresolved, _this.uri, _this.dependencies);
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
return this.resolvedSchema;
|
|
80
80
|
};
|
|
81
81
|
SchemaHandle.prototype.clearSchema = function () {
|
|
82
|
+
var hasChanges = !!this.unresolvedSchema;
|
|
82
83
|
this.resolvedSchema = undefined;
|
|
83
84
|
this.unresolvedSchema = undefined;
|
|
84
|
-
this.dependencies
|
|
85
|
+
this.dependencies.clear();
|
|
86
|
+
return hasChanges;
|
|
85
87
|
};
|
|
86
88
|
return SchemaHandle;
|
|
87
89
|
}());
|
|
@@ -185,13 +187,14 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
185
187
|
var curr = toWalk.pop();
|
|
186
188
|
for (var i = 0; i < all.length; i++) {
|
|
187
189
|
var handle = all[i];
|
|
188
|
-
if (handle && (handle.
|
|
189
|
-
if (handle.
|
|
190
|
-
toWalk.push(handle.
|
|
190
|
+
if (handle && (handle.uri === curr || handle.dependencies.has(curr))) {
|
|
191
|
+
if (handle.uri !== curr) {
|
|
192
|
+
toWalk.push(handle.uri);
|
|
193
|
+
}
|
|
194
|
+
if (handle.clearSchema()) {
|
|
195
|
+
hasChanges = true;
|
|
191
196
|
}
|
|
192
|
-
handle.clearSchema();
|
|
193
197
|
all[i] = undefined;
|
|
194
|
-
hasChanges = true;
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
}
|
|
@@ -299,6 +302,9 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
299
302
|
else if (id === 'https://json-schema.org/draft/2019-09/schema') {
|
|
300
303
|
resolveErrors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));
|
|
301
304
|
}
|
|
305
|
+
else if (id === 'https://json-schema.org/draft/2020-12/schema') {
|
|
306
|
+
resolveErrors.push(localize('json.schema.draft202012.notsupported', "Draft 2020-12 schemas are not yet fully supported."));
|
|
307
|
+
}
|
|
302
308
|
}
|
|
303
309
|
var contextService = this.contextService;
|
|
304
310
|
var findSection = function (schema, path) {
|
|
@@ -337,7 +343,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
337
343
|
uri = normalizeId(uri);
|
|
338
344
|
var referencedHandle = _this.getOrAddSchemaHandle(uri);
|
|
339
345
|
return referencedHandle.getUnresolvedSchema().then(function (unresolvedSchema) {
|
|
340
|
-
parentSchemaDependencies
|
|
346
|
+
parentSchemaDependencies.add(uri);
|
|
341
347
|
if (unresolvedSchema.errors.length) {
|
|
342
348
|
var loc = refSegment ? uri + '#' + refSegment : uri;
|
|
343
349
|
resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
|
|
@@ -351,7 +357,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
351
357
|
return Promise.resolve(null);
|
|
352
358
|
}
|
|
353
359
|
var toWalk = [node];
|
|
354
|
-
var seen =
|
|
360
|
+
var seen = new Set();
|
|
355
361
|
var openPromises = [];
|
|
356
362
|
var collectEntries = function () {
|
|
357
363
|
var entries = [];
|
|
@@ -401,7 +407,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
401
407
|
}
|
|
402
408
|
};
|
|
403
409
|
var handleRef = function (next) {
|
|
404
|
-
var seenRefs =
|
|
410
|
+
var seenRefs = new Set();
|
|
405
411
|
while (next.$ref) {
|
|
406
412
|
var ref = next.$ref;
|
|
407
413
|
var segments = ref.split('#', 2);
|
|
@@ -411,9 +417,9 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
411
417
|
return;
|
|
412
418
|
}
|
|
413
419
|
else {
|
|
414
|
-
if (seenRefs.
|
|
420
|
+
if (!seenRefs.has(ref)) {
|
|
415
421
|
merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again, use seenRefs to avoid circle
|
|
416
|
-
seenRefs.
|
|
422
|
+
seenRefs.add(ref);
|
|
417
423
|
}
|
|
418
424
|
}
|
|
419
425
|
}
|
|
@@ -423,37 +429,29 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
423
429
|
};
|
|
424
430
|
while (toWalk.length) {
|
|
425
431
|
var next = toWalk.pop();
|
|
426
|
-
if (seen.
|
|
432
|
+
if (seen.has(next)) {
|
|
427
433
|
continue;
|
|
428
434
|
}
|
|
429
|
-
seen.
|
|
435
|
+
seen.add(next);
|
|
430
436
|
handleRef(next);
|
|
431
437
|
}
|
|
432
438
|
return _this.promise.all(openPromises);
|
|
433
439
|
};
|
|
434
440
|
return resolveRefs(schema, schema, schemaURL, dependencies).then(function (_) { return new ResolvedSchema(schema, resolveErrors); });
|
|
435
441
|
};
|
|
436
|
-
JSONSchemaService.prototype.
|
|
437
|
-
|
|
438
|
-
if (
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
var schemeId = Parser.getNodeValue(valueNode);
|
|
444
|
-
if (schemeId && Strings.startsWith(schemeId, '.') && this.contextService) {
|
|
445
|
-
schemeId = this.contextService.resolveRelativePath(schemeId, resource);
|
|
446
|
-
}
|
|
447
|
-
if (schemeId) {
|
|
448
|
-
var id = normalizeId(schemeId);
|
|
449
|
-
return this.getOrAddSchemaHandle(id).getResolvedSchema();
|
|
450
|
-
}
|
|
442
|
+
JSONSchemaService.prototype.getSchemaProperty = function (document) {
|
|
443
|
+
var _a, _b;
|
|
444
|
+
if (((_a = document.root) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
|
|
445
|
+
for (var _i = 0, _c = document.root.properties; _i < _c.length; _i++) {
|
|
446
|
+
var p = _c[_i];
|
|
447
|
+
if (p.keyNode.value === '$schema' && ((_b = p.valueNode) === null || _b === void 0 ? void 0 : _b.type) === 'string') {
|
|
448
|
+
return p.valueNode.value;
|
|
451
449
|
}
|
|
452
450
|
}
|
|
453
451
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
452
|
+
return undefined;
|
|
453
|
+
};
|
|
454
|
+
JSONSchemaService.prototype.getAssociatedSchemas = function (resource) {
|
|
457
455
|
var seen = Object.create(null);
|
|
458
456
|
var schemas = [];
|
|
459
457
|
var normalizedResource = normalizeResourceForMatching(resource);
|
|
@@ -469,6 +467,31 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
469
467
|
}
|
|
470
468
|
}
|
|
471
469
|
}
|
|
470
|
+
return schemas;
|
|
471
|
+
};
|
|
472
|
+
JSONSchemaService.prototype.getSchemaURIsForResource = function (resource, document) {
|
|
473
|
+
var schemeId = document && this.getSchemaProperty(document);
|
|
474
|
+
if (schemeId) {
|
|
475
|
+
return [schemeId];
|
|
476
|
+
}
|
|
477
|
+
return this.getAssociatedSchemas(resource);
|
|
478
|
+
};
|
|
479
|
+
JSONSchemaService.prototype.getSchemaForResource = function (resource, document) {
|
|
480
|
+
if (document) {
|
|
481
|
+
// first use $schema if present
|
|
482
|
+
var schemeId = this.getSchemaProperty(document);
|
|
483
|
+
if (schemeId && Strings.startsWith(schemeId, '.') && this.contextService) {
|
|
484
|
+
schemeId = this.contextService.resolveRelativePath(schemeId, resource);
|
|
485
|
+
}
|
|
486
|
+
if (schemeId) {
|
|
487
|
+
var id = normalizeId(schemeId);
|
|
488
|
+
return this.getOrAddSchemaHandle(id).getResolvedSchema();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (this.cachedSchemaForResource && this.cachedSchemaForResource.resource === resource) {
|
|
492
|
+
return this.cachedSchemaForResource.resolvedSchema;
|
|
493
|
+
}
|
|
494
|
+
var schemas = this.getAssociatedSchemas(resource);
|
|
472
495
|
var resolvedSchema = schemas.length > 0 ? this.createCombinedSchema(resource, schemas).getResolvedSchema() : this.promise.resolve(undefined);
|
|
473
496
|
this.cachedSchemaForResource = { resource: resource, resolvedSchema: resolvedSchema };
|
|
474
497
|
return resolvedSchema;
|
|
@@ -488,7 +511,7 @@ var JSONSchemaService = /** @class */ (function () {
|
|
|
488
511
|
JSONSchemaService.prototype.getMatchingSchemas = function (document, jsonDocument, schema) {
|
|
489
512
|
if (schema) {
|
|
490
513
|
var id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
|
|
491
|
-
return this.resolveSchemaContent(new UnresolvedSchema(schema), id,
|
|
514
|
+
return this.resolveSchemaContent(new UnresolvedSchema(schema), id, new Set()).then(function (resolvedSchema) {
|
|
492
515
|
return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(function (s) { return !s.inverted; });
|
|
493
516
|
});
|
|
494
517
|
}
|
|
@@ -86,7 +86,7 @@ var JSONValidation = /** @class */ (function () {
|
|
|
86
86
|
};
|
|
87
87
|
if (schema) {
|
|
88
88
|
var id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
|
89
|
-
return this.jsonSchemaService.resolveSchemaContent(new UnresolvedSchema(schema), id,
|
|
89
|
+
return this.jsonSchemaService.resolveSchemaContent(new UnresolvedSchema(schema), id, new Set()).then(function (resolvedSchema) {
|
|
90
90
|
return getDiagnostics(resolvedSchema);
|
|
91
91
|
});
|
|
92
92
|
}
|
|
@@ -94,6 +94,9 @@ var JSONValidation = /** @class */ (function () {
|
|
|
94
94
|
return getDiagnostics(schema);
|
|
95
95
|
});
|
|
96
96
|
};
|
|
97
|
+
JSONValidation.prototype.getLanguageStatus = function (textDocument, jsonDocument) {
|
|
98
|
+
return { schemas: this.jsonSchemaService.getSchemaURIsForResource(textDocument.uri, jsonDocument) };
|
|
99
|
+
};
|
|
97
100
|
return JSONValidation;
|
|
98
101
|
}());
|
|
99
102
|
export { JSONValidation };
|
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, JSONLanguageStatus } from './jsonLanguageTypes';
|
|
2
2
|
import { DocumentLink } from 'vscode-languageserver-types';
|
|
3
3
|
export declare type JSONDocument = {
|
|
4
4
|
root: ASTNode | undefined;
|
|
@@ -12,6 +12,7 @@ export interface LanguageService {
|
|
|
12
12
|
newJSONDocument(rootNode: ASTNode, syntaxDiagnostics?: Diagnostic[]): JSONDocument;
|
|
13
13
|
resetSchema(uri: string): boolean;
|
|
14
14
|
getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): Thenable<MatchingSchema[]>;
|
|
15
|
+
getLanguageStatus(document: TextDocument, jsonDocument: JSONDocument): JSONLanguageStatus;
|
|
15
16
|
doResolve(item: CompletionItem): Thenable<CompletionItem>;
|
|
16
17
|
doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable<CompletionList | null>;
|
|
17
18
|
findDocumentSymbols(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): SymbolInformation[];
|
|
@@ -57,6 +57,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
57
57
|
},
|
|
58
58
|
resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
|
|
59
59
|
doValidation: jsonValidation.doValidation.bind(jsonValidation),
|
|
60
|
+
getLanguageStatus: jsonValidation.getLanguageStatus.bind(jsonValidation),
|
|
60
61
|
parseJSONDocument: function (document) { return jsonParser_1.parse(document, { collectComments: true }); },
|
|
61
62
|
newJSONDocument: function (root, diagnostics) { return jsonParser_1.newJSONDocument(root, diagnostics); },
|
|
62
63
|
getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
|
|
@@ -74,6 +74,9 @@ export interface MatchingSchema {
|
|
|
74
74
|
node: ASTNode;
|
|
75
75
|
schema: JSONSchema;
|
|
76
76
|
}
|
|
77
|
+
export interface JSONLanguageStatus {
|
|
78
|
+
schemas: string[];
|
|
79
|
+
}
|
|
77
80
|
export interface LanguageSettings {
|
|
78
81
|
/**
|
|
79
82
|
* If set, the validator will return syntax and semantic errors.
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
return FilePatternAssociation;
|
|
68
68
|
}());
|
|
69
69
|
var SchemaHandle = /** @class */ (function () {
|
|
70
|
-
function SchemaHandle(service,
|
|
70
|
+
function SchemaHandle(service, uri, unresolvedSchemaContent) {
|
|
71
71
|
this.service = service;
|
|
72
|
-
this.
|
|
73
|
-
this.dependencies =
|
|
72
|
+
this.uri = uri;
|
|
73
|
+
this.dependencies = new Set();
|
|
74
74
|
if (unresolvedSchemaContent) {
|
|
75
75
|
this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
SchemaHandle.prototype.getUnresolvedSchema = function () {
|
|
79
79
|
if (!this.unresolvedSchema) {
|
|
80
|
-
this.unresolvedSchema = this.service.loadSchema(this.
|
|
80
|
+
this.unresolvedSchema = this.service.loadSchema(this.uri);
|
|
81
81
|
}
|
|
82
82
|
return this.unresolvedSchema;
|
|
83
83
|
};
|
|
@@ -85,15 +85,17 @@
|
|
|
85
85
|
var _this = this;
|
|
86
86
|
if (!this.resolvedSchema) {
|
|
87
87
|
this.resolvedSchema = this.getUnresolvedSchema().then(function (unresolved) {
|
|
88
|
-
return _this.service.resolveSchemaContent(unresolved, _this.
|
|
88
|
+
return _this.service.resolveSchemaContent(unresolved, _this.uri, _this.dependencies);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
return this.resolvedSchema;
|
|
92
92
|
};
|
|
93
93
|
SchemaHandle.prototype.clearSchema = function () {
|
|
94
|
+
var hasChanges = !!this.unresolvedSchema;
|
|
94
95
|
this.resolvedSchema = undefined;
|
|
95
96
|
this.unresolvedSchema = undefined;
|
|
96
|
-
this.dependencies
|
|
97
|
+
this.dependencies.clear();
|
|
98
|
+
return hasChanges;
|
|
97
99
|
};
|
|
98
100
|
return SchemaHandle;
|
|
99
101
|
}());
|
|
@@ -197,13 +199,14 @@
|
|
|
197
199
|
var curr = toWalk.pop();
|
|
198
200
|
for (var i = 0; i < all.length; i++) {
|
|
199
201
|
var handle = all[i];
|
|
200
|
-
if (handle && (handle.
|
|
201
|
-
if (handle.
|
|
202
|
-
toWalk.push(handle.
|
|
202
|
+
if (handle && (handle.uri === curr || handle.dependencies.has(curr))) {
|
|
203
|
+
if (handle.uri !== curr) {
|
|
204
|
+
toWalk.push(handle.uri);
|
|
205
|
+
}
|
|
206
|
+
if (handle.clearSchema()) {
|
|
207
|
+
hasChanges = true;
|
|
203
208
|
}
|
|
204
|
-
handle.clearSchema();
|
|
205
209
|
all[i] = undefined;
|
|
206
|
-
hasChanges = true;
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
}
|
|
@@ -311,6 +314,9 @@
|
|
|
311
314
|
else if (id === 'https://json-schema.org/draft/2019-09/schema') {
|
|
312
315
|
resolveErrors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));
|
|
313
316
|
}
|
|
317
|
+
else if (id === 'https://json-schema.org/draft/2020-12/schema') {
|
|
318
|
+
resolveErrors.push(localize('json.schema.draft202012.notsupported', "Draft 2020-12 schemas are not yet fully supported."));
|
|
319
|
+
}
|
|
314
320
|
}
|
|
315
321
|
var contextService = this.contextService;
|
|
316
322
|
var findSection = function (schema, path) {
|
|
@@ -349,7 +355,7 @@
|
|
|
349
355
|
uri = normalizeId(uri);
|
|
350
356
|
var referencedHandle = _this.getOrAddSchemaHandle(uri);
|
|
351
357
|
return referencedHandle.getUnresolvedSchema().then(function (unresolvedSchema) {
|
|
352
|
-
parentSchemaDependencies
|
|
358
|
+
parentSchemaDependencies.add(uri);
|
|
353
359
|
if (unresolvedSchema.errors.length) {
|
|
354
360
|
var loc = refSegment ? uri + '#' + refSegment : uri;
|
|
355
361
|
resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
|
|
@@ -363,7 +369,7 @@
|
|
|
363
369
|
return Promise.resolve(null);
|
|
364
370
|
}
|
|
365
371
|
var toWalk = [node];
|
|
366
|
-
var seen =
|
|
372
|
+
var seen = new Set();
|
|
367
373
|
var openPromises = [];
|
|
368
374
|
var collectEntries = function () {
|
|
369
375
|
var entries = [];
|
|
@@ -413,7 +419,7 @@
|
|
|
413
419
|
}
|
|
414
420
|
};
|
|
415
421
|
var handleRef = function (next) {
|
|
416
|
-
var seenRefs =
|
|
422
|
+
var seenRefs = new Set();
|
|
417
423
|
while (next.$ref) {
|
|
418
424
|
var ref = next.$ref;
|
|
419
425
|
var segments = ref.split('#', 2);
|
|
@@ -423,9 +429,9 @@
|
|
|
423
429
|
return;
|
|
424
430
|
}
|
|
425
431
|
else {
|
|
426
|
-
if (seenRefs.
|
|
432
|
+
if (!seenRefs.has(ref)) {
|
|
427
433
|
merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again, use seenRefs to avoid circle
|
|
428
|
-
seenRefs.
|
|
434
|
+
seenRefs.add(ref);
|
|
429
435
|
}
|
|
430
436
|
}
|
|
431
437
|
}
|
|
@@ -435,37 +441,29 @@
|
|
|
435
441
|
};
|
|
436
442
|
while (toWalk.length) {
|
|
437
443
|
var next = toWalk.pop();
|
|
438
|
-
if (seen.
|
|
444
|
+
if (seen.has(next)) {
|
|
439
445
|
continue;
|
|
440
446
|
}
|
|
441
|
-
seen.
|
|
447
|
+
seen.add(next);
|
|
442
448
|
handleRef(next);
|
|
443
449
|
}
|
|
444
450
|
return _this.promise.all(openPromises);
|
|
445
451
|
};
|
|
446
452
|
return resolveRefs(schema, schema, schemaURL, dependencies).then(function (_) { return new ResolvedSchema(schema, resolveErrors); });
|
|
447
453
|
};
|
|
448
|
-
JSONSchemaService.prototype.
|
|
449
|
-
|
|
450
|
-
if (
|
|
451
|
-
var
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
var schemeId = Parser.getNodeValue(valueNode);
|
|
456
|
-
if (schemeId && Strings.startsWith(schemeId, '.') && this.contextService) {
|
|
457
|
-
schemeId = this.contextService.resolveRelativePath(schemeId, resource);
|
|
458
|
-
}
|
|
459
|
-
if (schemeId) {
|
|
460
|
-
var id = normalizeId(schemeId);
|
|
461
|
-
return this.getOrAddSchemaHandle(id).getResolvedSchema();
|
|
462
|
-
}
|
|
454
|
+
JSONSchemaService.prototype.getSchemaProperty = function (document) {
|
|
455
|
+
var _a, _b;
|
|
456
|
+
if (((_a = document.root) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
|
|
457
|
+
for (var _i = 0, _c = document.root.properties; _i < _c.length; _i++) {
|
|
458
|
+
var p = _c[_i];
|
|
459
|
+
if (p.keyNode.value === '$schema' && ((_b = p.valueNode) === null || _b === void 0 ? void 0 : _b.type) === 'string') {
|
|
460
|
+
return p.valueNode.value;
|
|
463
461
|
}
|
|
464
462
|
}
|
|
465
463
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
464
|
+
return undefined;
|
|
465
|
+
};
|
|
466
|
+
JSONSchemaService.prototype.getAssociatedSchemas = function (resource) {
|
|
469
467
|
var seen = Object.create(null);
|
|
470
468
|
var schemas = [];
|
|
471
469
|
var normalizedResource = normalizeResourceForMatching(resource);
|
|
@@ -481,6 +479,31 @@
|
|
|
481
479
|
}
|
|
482
480
|
}
|
|
483
481
|
}
|
|
482
|
+
return schemas;
|
|
483
|
+
};
|
|
484
|
+
JSONSchemaService.prototype.getSchemaURIsForResource = function (resource, document) {
|
|
485
|
+
var schemeId = document && this.getSchemaProperty(document);
|
|
486
|
+
if (schemeId) {
|
|
487
|
+
return [schemeId];
|
|
488
|
+
}
|
|
489
|
+
return this.getAssociatedSchemas(resource);
|
|
490
|
+
};
|
|
491
|
+
JSONSchemaService.prototype.getSchemaForResource = function (resource, document) {
|
|
492
|
+
if (document) {
|
|
493
|
+
// first use $schema if present
|
|
494
|
+
var schemeId = this.getSchemaProperty(document);
|
|
495
|
+
if (schemeId && Strings.startsWith(schemeId, '.') && this.contextService) {
|
|
496
|
+
schemeId = this.contextService.resolveRelativePath(schemeId, resource);
|
|
497
|
+
}
|
|
498
|
+
if (schemeId) {
|
|
499
|
+
var id = normalizeId(schemeId);
|
|
500
|
+
return this.getOrAddSchemaHandle(id).getResolvedSchema();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (this.cachedSchemaForResource && this.cachedSchemaForResource.resource === resource) {
|
|
504
|
+
return this.cachedSchemaForResource.resolvedSchema;
|
|
505
|
+
}
|
|
506
|
+
var schemas = this.getAssociatedSchemas(resource);
|
|
484
507
|
var resolvedSchema = schemas.length > 0 ? this.createCombinedSchema(resource, schemas).getResolvedSchema() : this.promise.resolve(undefined);
|
|
485
508
|
this.cachedSchemaForResource = { resource: resource, resolvedSchema: resolvedSchema };
|
|
486
509
|
return resolvedSchema;
|
|
@@ -500,7 +523,7 @@
|
|
|
500
523
|
JSONSchemaService.prototype.getMatchingSchemas = function (document, jsonDocument, schema) {
|
|
501
524
|
if (schema) {
|
|
502
525
|
var id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
|
|
503
|
-
return this.resolveSchemaContent(new UnresolvedSchema(schema), id,
|
|
526
|
+
return this.resolveSchemaContent(new UnresolvedSchema(schema), id, new Set()).then(function (resolvedSchema) {
|
|
504
527
|
return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(function (s) { return !s.inverted; });
|
|
505
528
|
});
|
|
506
529
|
}
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
};
|
|
99
99
|
if (schema) {
|
|
100
100
|
var id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
|
101
|
-
return this.jsonSchemaService.resolveSchemaContent(new jsonSchemaService_1.UnresolvedSchema(schema), id,
|
|
101
|
+
return this.jsonSchemaService.resolveSchemaContent(new jsonSchemaService_1.UnresolvedSchema(schema), id, new Set()).then(function (resolvedSchema) {
|
|
102
102
|
return getDiagnostics(resolvedSchema);
|
|
103
103
|
});
|
|
104
104
|
}
|
|
@@ -106,6 +106,9 @@
|
|
|
106
106
|
return getDiagnostics(schema);
|
|
107
107
|
});
|
|
108
108
|
};
|
|
109
|
+
JSONValidation.prototype.getLanguageStatus = function (textDocument, jsonDocument) {
|
|
110
|
+
return { schemas: this.jsonSchemaService.getSchemaURIsForResource(textDocument.uri, jsonDocument) };
|
|
111
|
+
};
|
|
109
112
|
return JSONValidation;
|
|
110
113
|
}());
|
|
111
114
|
exports.JSONValidation = JSONValidation;
|