vscode-json-languageservice 4.2.0 → 5.1.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/jsonLanguageService.js +22 -22
  4. package/lib/esm/jsonLanguageTypes.d.ts +3 -1
  5. package/lib/esm/jsonLanguageTypes.js +3 -2
  6. package/lib/esm/jsonSchema.d.ts +21 -2
  7. package/lib/esm/parser/jsonParser.js +488 -488
  8. package/lib/esm/services/configuration.js +9 -9
  9. package/lib/esm/services/jsonCompletion.js +280 -290
  10. package/lib/esm/services/jsonDocumentSymbols.js +88 -99
  11. package/lib/esm/services/jsonFolding.js +38 -39
  12. package/lib/esm/services/jsonHover.js +40 -43
  13. package/lib/esm/services/jsonLinks.js +12 -13
  14. package/lib/esm/services/jsonSchemaService.js +234 -253
  15. package/lib/esm/services/jsonSelectionRanges.js +9 -9
  16. package/lib/esm/services/jsonValidation.js +53 -51
  17. package/lib/esm/utils/colors.js +7 -8
  18. package/lib/esm/utils/glob.js +12 -12
  19. package/lib/esm/utils/json.js +7 -7
  20. package/lib/esm/utils/objects.js +3 -0
  21. package/lib/esm/utils/strings.js +3 -3
  22. package/lib/umd/jsonLanguageService.js +36 -32
  23. package/lib/umd/jsonLanguageTypes.d.ts +3 -1
  24. package/lib/umd/jsonLanguageTypes.js +5 -3
  25. package/lib/umd/jsonSchema.d.ts +21 -2
  26. package/lib/umd/parser/jsonParser.js +492 -482
  27. package/lib/umd/services/configuration.js +9 -9
  28. package/lib/umd/services/jsonCompletion.js +287 -296
  29. package/lib/umd/services/jsonDocumentSymbols.js +92 -102
  30. package/lib/umd/services/jsonFolding.js +40 -41
  31. package/lib/umd/services/jsonHover.js +42 -44
  32. package/lib/umd/services/jsonLinks.js +13 -14
  33. package/lib/umd/services/jsonSchemaService.js +241 -257
  34. package/lib/umd/services/jsonSelectionRanges.js +11 -11
  35. package/lib/umd/services/jsonValidation.js +56 -53
  36. package/lib/umd/utils/colors.js +7 -8
  37. package/lib/umd/utils/glob.js +12 -12
  38. package/lib/umd/utils/json.js +7 -7
  39. package/lib/umd/utils/objects.js +5 -1
  40. package/lib/umd/utils/strings.js +3 -3
  41. package/package.json +12 -12
@@ -8,28 +8,28 @@
8
8
  if (v !== undefined) module.exports = v;
9
9
  }
10
10
  else if (typeof define === "function" && define.amd) {
11
- define(["require", "exports", "jsonc-parser", "vscode-uri", "../utils/strings", "../parser/jsonParser", "vscode-nls", "../utils/glob"], factory);
11
+ define(["require", "exports", "jsonc-parser", "vscode-uri", "../utils/strings", "../parser/jsonParser", "vscode-nls", "../utils/glob", "../utils/objects"], factory);
12
12
  }
13
13
  })(function (require, exports) {
14
14
  "use strict";
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.JSONSchemaService = exports.ResolvedSchema = exports.UnresolvedSchema = void 0;
17
- var Json = require("jsonc-parser");
18
- var vscode_uri_1 = require("vscode-uri");
19
- var Strings = require("../utils/strings");
20
- var Parser = require("../parser/jsonParser");
21
- var nls = require("vscode-nls");
22
- var glob_1 = require("../utils/glob");
23
- var localize = nls.loadMessageBundle();
24
- var BANG = '!';
25
- var PATH_SEP = '/';
26
- var FilePatternAssociation = /** @class */ (function () {
27
- function FilePatternAssociation(pattern, uris) {
17
+ const Json = require("jsonc-parser");
18
+ const vscode_uri_1 = require("vscode-uri");
19
+ const Strings = require("../utils/strings");
20
+ const Parser = require("../parser/jsonParser");
21
+ const nls = require("vscode-nls");
22
+ const glob_1 = require("../utils/glob");
23
+ const objects_1 = require("../utils/objects");
24
+ const localize = nls.loadMessageBundle();
25
+ const BANG = '!';
26
+ const PATH_SEP = '/';
27
+ class FilePatternAssociation {
28
+ constructor(pattern, uris) {
28
29
  this.globWrappers = [];
29
30
  try {
30
- for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
31
- var patternString = pattern_1[_i];
32
- var include = patternString[0] !== BANG;
31
+ for (let patternString of pattern) {
32
+ const include = patternString[0] !== BANG;
33
33
  if (!include) {
34
34
  patternString = patternString.substring(1);
35
35
  }
@@ -51,23 +51,21 @@
51
51
  this.uris = [];
52
52
  }
53
53
  }
54
- FilePatternAssociation.prototype.matchesPattern = function (fileName) {
55
- var match = false;
56
- for (var _i = 0, _a = this.globWrappers; _i < _a.length; _i++) {
57
- var _b = _a[_i], regexp = _b.regexp, include = _b.include;
54
+ matchesPattern(fileName) {
55
+ let match = false;
56
+ for (const { regexp, include } of this.globWrappers) {
58
57
  if (regexp.test(fileName)) {
59
58
  match = include;
60
59
  }
61
60
  }
62
61
  return match;
63
- };
64
- FilePatternAssociation.prototype.getURIs = function () {
62
+ }
63
+ getURIs() {
65
64
  return this.uris;
66
- };
67
- return FilePatternAssociation;
68
- }());
69
- var SchemaHandle = /** @class */ (function () {
70
- function SchemaHandle(service, uri, unresolvedSchemaContent) {
65
+ }
66
+ }
67
+ class SchemaHandle {
68
+ constructor(service, uri, unresolvedSchemaContent) {
71
69
  this.service = service;
72
70
  this.uri = uri;
73
71
  this.dependencies = new Set();
@@ -76,66 +74,62 @@
76
74
  this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
77
75
  }
78
76
  }
79
- SchemaHandle.prototype.getUnresolvedSchema = function () {
77
+ getUnresolvedSchema() {
80
78
  if (!this.unresolvedSchema) {
81
79
  this.unresolvedSchema = this.service.loadSchema(this.uri);
82
80
  }
83
81
  return this.unresolvedSchema;
84
- };
85
- SchemaHandle.prototype.getResolvedSchema = function () {
86
- var _this = this;
82
+ }
83
+ getResolvedSchema() {
87
84
  if (!this.resolvedSchema) {
88
- this.resolvedSchema = this.getUnresolvedSchema().then(function (unresolved) {
89
- return _this.service.resolveSchemaContent(unresolved, _this);
85
+ this.resolvedSchema = this.getUnresolvedSchema().then(unresolved => {
86
+ return this.service.resolveSchemaContent(unresolved, this);
90
87
  });
91
88
  }
92
89
  return this.resolvedSchema;
93
- };
94
- SchemaHandle.prototype.clearSchema = function () {
95
- var hasChanges = !!this.unresolvedSchema;
90
+ }
91
+ clearSchema() {
92
+ const hasChanges = !!this.unresolvedSchema;
96
93
  this.resolvedSchema = undefined;
97
94
  this.unresolvedSchema = undefined;
98
95
  this.dependencies.clear();
99
96
  this.anchors = undefined;
100
97
  return hasChanges;
101
- };
102
- return SchemaHandle;
103
- }());
104
- var UnresolvedSchema = /** @class */ (function () {
105
- function UnresolvedSchema(schema, errors) {
106
- if (errors === void 0) { errors = []; }
98
+ }
99
+ }
100
+ class UnresolvedSchema {
101
+ constructor(schema, errors = []) {
107
102
  this.schema = schema;
108
103
  this.errors = errors;
109
104
  }
110
- return UnresolvedSchema;
111
- }());
105
+ }
112
106
  exports.UnresolvedSchema = UnresolvedSchema;
113
- var ResolvedSchema = /** @class */ (function () {
114
- function ResolvedSchema(schema, errors) {
115
- if (errors === void 0) { errors = []; }
107
+ class ResolvedSchema {
108
+ constructor(schema, errors = [], warnings = [], schemaDraft) {
116
109
  this.schema = schema;
117
110
  this.errors = errors;
111
+ this.warnings = warnings;
112
+ this.schemaDraft = schemaDraft;
118
113
  }
119
- ResolvedSchema.prototype.getSection = function (path) {
120
- var schemaRef = this.getSectionRecursive(path, this.schema);
114
+ getSection(path) {
115
+ const schemaRef = this.getSectionRecursive(path, this.schema);
121
116
  if (schemaRef) {
122
117
  return Parser.asSchema(schemaRef);
123
118
  }
124
119
  return undefined;
125
- };
126
- ResolvedSchema.prototype.getSectionRecursive = function (path, schema) {
120
+ }
121
+ getSectionRecursive(path, schema) {
127
122
  if (!schema || typeof schema === 'boolean' || path.length === 0) {
128
123
  return schema;
129
124
  }
130
- var next = path.shift();
125
+ const next = path.shift();
131
126
  if (schema.properties && typeof schema.properties[next]) {
132
127
  return this.getSectionRecursive(path, schema.properties[next]);
133
128
  }
134
129
  else if (schema.patternProperties) {
135
- for (var _i = 0, _a = Object.keys(schema.patternProperties); _i < _a.length; _i++) {
136
- var pattern = _a[_i];
137
- var regex = Strings.extendedRegExp(pattern);
138
- if (regex === null || regex === void 0 ? void 0 : regex.test(next)) {
130
+ for (const pattern of Object.keys(schema.patternProperties)) {
131
+ const regex = Strings.extendedRegExp(pattern);
132
+ if (regex?.test(next)) {
139
133
  return this.getSectionRecursive(path, schema.patternProperties[pattern]);
140
134
  }
141
135
  }
@@ -145,7 +139,7 @@
145
139
  }
146
140
  else if (next.match('[0-9]+')) {
147
141
  if (Array.isArray(schema.items)) {
148
- var index = parseInt(next, 10);
142
+ const index = parseInt(next, 10);
149
143
  if (!isNaN(index) && schema.items[index]) {
150
144
  return this.getSectionRecursive(path, schema.items[index]);
151
145
  }
@@ -155,12 +149,11 @@
155
149
  }
156
150
  }
157
151
  return undefined;
158
- };
159
- return ResolvedSchema;
160
- }());
152
+ }
153
+ }
161
154
  exports.ResolvedSchema = ResolvedSchema;
162
- var JSONSchemaService = /** @class */ (function () {
163
- function JSONSchemaService(requestService, contextService, promiseConstructor) {
155
+ class JSONSchemaService {
156
+ constructor(requestService, contextService, promiseConstructor) {
164
157
  this.contextService = contextService;
165
158
  this.requestService = requestService;
166
159
  this.promiseConstructor = promiseConstructor || Promise;
@@ -171,36 +164,31 @@
171
164
  this.filePatternAssociations = [];
172
165
  this.registeredSchemasIds = {};
173
166
  }
174
- JSONSchemaService.prototype.getRegisteredSchemaIds = function (filter) {
175
- return Object.keys(this.registeredSchemasIds).filter(function (id) {
176
- var scheme = vscode_uri_1.URI.parse(id).scheme;
167
+ getRegisteredSchemaIds(filter) {
168
+ return Object.keys(this.registeredSchemasIds).filter(id => {
169
+ const scheme = vscode_uri_1.URI.parse(id).scheme;
177
170
  return scheme !== 'schemaservice' && (!filter || filter(scheme));
178
171
  });
179
- };
180
- Object.defineProperty(JSONSchemaService.prototype, "promise", {
181
- get: function () {
182
- return this.promiseConstructor;
183
- },
184
- enumerable: false,
185
- configurable: true
186
- });
187
- JSONSchemaService.prototype.dispose = function () {
172
+ }
173
+ get promise() {
174
+ return this.promiseConstructor;
175
+ }
176
+ dispose() {
188
177
  while (this.callOnDispose.length > 0) {
189
178
  this.callOnDispose.pop()();
190
179
  }
191
- };
192
- JSONSchemaService.prototype.onResourceChange = function (uri) {
193
- var _this = this;
180
+ }
181
+ onResourceChange(uri) {
194
182
  // always clear this local cache when a resource changes
195
183
  this.cachedSchemaForResource = undefined;
196
- var hasChanges = false;
184
+ let hasChanges = false;
197
185
  uri = normalizeId(uri);
198
- var toWalk = [uri];
199
- var all = Object.keys(this.schemasById).map(function (key) { return _this.schemasById[key]; });
186
+ const toWalk = [uri];
187
+ const all = Object.keys(this.schemasById).map(key => this.schemasById[key]);
200
188
  while (toWalk.length) {
201
- var curr = toWalk.pop();
202
- for (var i = 0; i < all.length; i++) {
203
- var handle = all[i];
189
+ const curr = toWalk.pop();
190
+ for (let i = 0; i < all.length; i++) {
191
+ const handle = all[i];
204
192
  if (handle && (handle.uri === curr || handle.dependencies.has(curr))) {
205
193
  if (handle.uri !== curr) {
206
194
  toWalk.push(handle.uri);
@@ -213,87 +201,85 @@
213
201
  }
214
202
  }
215
203
  return hasChanges;
216
- };
217
- JSONSchemaService.prototype.setSchemaContributions = function (schemaContributions) {
204
+ }
205
+ setSchemaContributions(schemaContributions) {
218
206
  if (schemaContributions.schemas) {
219
- var schemas = schemaContributions.schemas;
220
- for (var id in schemas) {
221
- var normalizedId = normalizeId(id);
207
+ const schemas = schemaContributions.schemas;
208
+ for (const id in schemas) {
209
+ const normalizedId = normalizeId(id);
222
210
  this.contributionSchemas[normalizedId] = this.addSchemaHandle(normalizedId, schemas[id]);
223
211
  }
224
212
  }
225
213
  if (Array.isArray(schemaContributions.schemaAssociations)) {
226
- var schemaAssociations = schemaContributions.schemaAssociations;
227
- for (var _i = 0, schemaAssociations_1 = schemaAssociations; _i < schemaAssociations_1.length; _i++) {
228
- var schemaAssociation = schemaAssociations_1[_i];
229
- var uris = schemaAssociation.uris.map(normalizeId);
230
- var association = this.addFilePatternAssociation(schemaAssociation.pattern, uris);
214
+ const schemaAssociations = schemaContributions.schemaAssociations;
215
+ for (let schemaAssociation of schemaAssociations) {
216
+ const uris = schemaAssociation.uris.map(normalizeId);
217
+ const association = this.addFilePatternAssociation(schemaAssociation.pattern, uris);
231
218
  this.contributionAssociations.push(association);
232
219
  }
233
220
  }
234
- };
235
- JSONSchemaService.prototype.addSchemaHandle = function (id, unresolvedSchemaContent) {
236
- var schemaHandle = new SchemaHandle(this, id, unresolvedSchemaContent);
221
+ }
222
+ addSchemaHandle(id, unresolvedSchemaContent) {
223
+ const schemaHandle = new SchemaHandle(this, id, unresolvedSchemaContent);
237
224
  this.schemasById[id] = schemaHandle;
238
225
  return schemaHandle;
239
- };
240
- JSONSchemaService.prototype.getOrAddSchemaHandle = function (id, unresolvedSchemaContent) {
226
+ }
227
+ getOrAddSchemaHandle(id, unresolvedSchemaContent) {
241
228
  return this.schemasById[id] || this.addSchemaHandle(id, unresolvedSchemaContent);
242
- };
243
- JSONSchemaService.prototype.addFilePatternAssociation = function (pattern, uris) {
244
- var fpa = new FilePatternAssociation(pattern, uris);
229
+ }
230
+ addFilePatternAssociation(pattern, uris) {
231
+ const fpa = new FilePatternAssociation(pattern, uris);
245
232
  this.filePatternAssociations.push(fpa);
246
233
  return fpa;
247
- };
248
- JSONSchemaService.prototype.registerExternalSchema = function (uri, filePatterns, unresolvedSchemaContent) {
249
- var id = normalizeId(uri);
234
+ }
235
+ registerExternalSchema(uri, filePatterns, unresolvedSchemaContent) {
236
+ const id = normalizeId(uri);
250
237
  this.registeredSchemasIds[id] = true;
251
238
  this.cachedSchemaForResource = undefined;
252
239
  if (filePatterns) {
253
240
  this.addFilePatternAssociation(filePatterns, [id]);
254
241
  }
255
242
  return unresolvedSchemaContent ? this.addSchemaHandle(id, unresolvedSchemaContent) : this.getOrAddSchemaHandle(id);
256
- };
257
- JSONSchemaService.prototype.clearExternalSchemas = function () {
243
+ }
244
+ clearExternalSchemas() {
258
245
  this.schemasById = {};
259
246
  this.filePatternAssociations = [];
260
247
  this.registeredSchemasIds = {};
261
248
  this.cachedSchemaForResource = undefined;
262
- for (var id in this.contributionSchemas) {
249
+ for (const id in this.contributionSchemas) {
263
250
  this.schemasById[id] = this.contributionSchemas[id];
264
251
  this.registeredSchemasIds[id] = true;
265
252
  }
266
- for (var _i = 0, _a = this.contributionAssociations; _i < _a.length; _i++) {
267
- var contributionAssociation = _a[_i];
253
+ for (const contributionAssociation of this.contributionAssociations) {
268
254
  this.filePatternAssociations.push(contributionAssociation);
269
255
  }
270
- };
271
- JSONSchemaService.prototype.getResolvedSchema = function (schemaId) {
272
- var id = normalizeId(schemaId);
273
- var schemaHandle = this.schemasById[id];
256
+ }
257
+ getResolvedSchema(schemaId) {
258
+ const id = normalizeId(schemaId);
259
+ const schemaHandle = this.schemasById[id];
274
260
  if (schemaHandle) {
275
261
  return schemaHandle.getResolvedSchema();
276
262
  }
277
263
  return this.promise.resolve(undefined);
278
- };
279
- JSONSchemaService.prototype.loadSchema = function (url) {
264
+ }
265
+ loadSchema(url) {
280
266
  if (!this.requestService) {
281
- var errorMessage = localize('json.schema.norequestservice', 'Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
267
+ const errorMessage = localize('json.schema.norequestservice', 'Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
282
268
  return this.promise.resolve(new UnresolvedSchema({}, [errorMessage]));
283
269
  }
284
- return this.requestService(url).then(function (content) {
270
+ return this.requestService(url).then(content => {
285
271
  if (!content) {
286
- var errorMessage = localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': No content.', toDisplayString(url));
272
+ const errorMessage = localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': No content.', toDisplayString(url));
287
273
  return new UnresolvedSchema({}, [errorMessage]);
288
274
  }
289
- var schemaContent = {};
290
- var jsonErrors = [];
275
+ let schemaContent = {};
276
+ const jsonErrors = [];
291
277
  schemaContent = Json.parse(content, jsonErrors);
292
- var errors = jsonErrors.length ? [localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset)] : [];
278
+ const errors = jsonErrors.length ? [localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset)] : [];
293
279
  return new UnresolvedSchema(schemaContent, errors);
294
- }, function (error) {
295
- var errorMessage = error.toString();
296
- var errorSplit = error.toString().split('Error: ');
280
+ }, (error) => {
281
+ let errorMessage = error.toString();
282
+ const errorSplit = error.toString().split('Error: ');
297
283
  if (errorSplit.length > 1) {
298
284
  // more concise error message, URL and context are attached by caller anyways
299
285
  errorMessage = errorSplit[1];
@@ -303,52 +289,44 @@
303
289
  }
304
290
  return new UnresolvedSchema({}, [localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': {1}.', toDisplayString(url), errorMessage)]);
305
291
  });
306
- };
307
- JSONSchemaService.prototype.resolveSchemaContent = function (schemaToResolve, handle) {
308
- var _this = this;
309
- var resolveErrors = schemaToResolve.errors.slice(0);
310
- var schema = schemaToResolve.schema;
311
- if (schema.$schema) {
312
- var id = normalizeId(schema.$schema);
313
- if (id === 'http://json-schema.org/draft-03/schema') {
314
- return this.promise.resolve(new ResolvedSchema({}, [localize('json.schema.draft03.notsupported', "Draft-03 schemas are not supported.")]));
315
- }
316
- else if (id === 'https://json-schema.org/draft/2019-09/schema') {
317
- resolveErrors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));
318
- }
319
- else if (id === 'https://json-schema.org/draft/2020-12/schema') {
320
- resolveErrors.push(localize('json.schema.draft202012.notsupported', "Draft 2020-12 schemas are not yet fully supported."));
321
- }
322
- }
323
- var contextService = this.contextService;
324
- var findSectionByJSONPointer = function (schema, path) {
292
+ }
293
+ resolveSchemaContent(schemaToResolve, handle) {
294
+ const resolveErrors = schemaToResolve.errors.slice(0);
295
+ const schema = schemaToResolve.schema;
296
+ let schemaDraft = schema.$schema ? normalizeId(schema.$schema) : undefined;
297
+ if (schemaDraft === 'http://json-schema.org/draft-03/schema') {
298
+ return this.promise.resolve(new ResolvedSchema({}, [localize('json.schema.draft03.notsupported', "Draft-03 schemas are not supported.")], [], schemaDraft));
299
+ }
300
+ let usesUnsupportedFeatures = new Set();
301
+ const contextService = this.contextService;
302
+ const findSectionByJSONPointer = (schema, path) => {
325
303
  path = decodeURIComponent(path);
326
- var current = schema;
304
+ let current = schema;
327
305
  if (path[0] === '/') {
328
306
  path = path.substring(1);
329
307
  }
330
- path.split('/').some(function (part) {
308
+ path.split('/').some((part) => {
331
309
  part = part.replace(/~1/g, '/').replace(/~0/g, '~');
332
310
  current = current[part];
333
311
  return !current;
334
312
  });
335
313
  return current;
336
314
  };
337
- var findSchemaById = function (schema, handle, id) {
315
+ const findSchemaById = (schema, handle, id) => {
338
316
  if (!handle.anchors) {
339
317
  handle.anchors = collectAnchors(schema);
340
318
  }
341
319
  return handle.anchors.get(id);
342
320
  };
343
- var merge = function (target, section) {
344
- for (var key in section) {
321
+ const merge = (target, section) => {
322
+ for (const key in section) {
345
323
  if (section.hasOwnProperty(key) && !target.hasOwnProperty(key) && key !== 'id' && key !== '$id') {
346
324
  target[key] = section[key];
347
325
  }
348
326
  }
349
327
  };
350
- var mergeRef = function (target, sourceRoot, sourceHandle, refSegment) {
351
- var section;
328
+ const mergeRef = (target, sourceRoot, sourceHandle, refSegment) => {
329
+ let section;
352
330
  if (refSegment === undefined || refSegment.length === 0) {
353
331
  section = sourceRoot;
354
332
  }
@@ -367,29 +345,29 @@
367
345
  resolveErrors.push(localize('json.schema.invalidid', '$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment, sourceHandle.uri));
368
346
  }
369
347
  };
370
- var resolveExternalLink = function (node, uri, refSegment, parentHandle) {
348
+ const resolveExternalLink = (node, uri, refSegment, parentHandle) => {
371
349
  if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
372
350
  uri = contextService.resolveRelativePath(uri, parentHandle.uri);
373
351
  }
374
352
  uri = normalizeId(uri);
375
- var referencedHandle = _this.getOrAddSchemaHandle(uri);
376
- return referencedHandle.getUnresolvedSchema().then(function (unresolvedSchema) {
353
+ const referencedHandle = this.getOrAddSchemaHandle(uri);
354
+ return referencedHandle.getUnresolvedSchema().then(unresolvedSchema => {
377
355
  parentHandle.dependencies.add(uri);
378
356
  if (unresolvedSchema.errors.length) {
379
- var loc = refSegment ? uri + '#' + refSegment : uri;
357
+ const loc = refSegment ? uri + '#' + refSegment : uri;
380
358
  resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
381
359
  }
382
360
  mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
383
361
  return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
384
362
  });
385
363
  };
386
- var resolveRefs = function (node, parentSchema, parentHandle) {
387
- var openPromises = [];
388
- _this.traverseNodes(node, function (next) {
389
- var seenRefs = new Set();
364
+ const resolveRefs = (node, parentSchema, parentHandle) => {
365
+ const openPromises = [];
366
+ this.traverseNodes(node, next => {
367
+ const seenRefs = new Set();
390
368
  while (next.$ref) {
391
- var ref = next.$ref;
392
- var segments = ref.split('#', 2);
369
+ const ref = next.$ref;
370
+ const segments = ref.split('#', 2);
393
371
  delete next.$ref;
394
372
  if (segments[0].length > 0) {
395
373
  // This is a reference to an external schema
@@ -399,110 +377,119 @@
399
377
  else {
400
378
  // This is a reference inside the current schema
401
379
  if (!seenRefs.has(ref)) {
402
- var id = segments[1];
380
+ const id = segments[1];
403
381
  mergeRef(next, parentSchema, parentHandle, id);
404
382
  seenRefs.add(ref);
405
383
  }
406
384
  }
407
385
  }
386
+ if (next.$recursiveRef) {
387
+ usesUnsupportedFeatures.add('$recursiveRef');
388
+ }
389
+ if (next.$dynamicRef) {
390
+ usesUnsupportedFeatures.add('$dynamicRef');
391
+ }
408
392
  });
409
- return _this.promise.all(openPromises);
393
+ return this.promise.all(openPromises);
410
394
  };
411
- var collectAnchors = function (root) {
412
- var result = new Map();
413
- _this.traverseNodes(root, function (next) {
414
- var id = next.$id || next.id;
415
- if (typeof id === 'string' && id.charAt(0) === '#') {
416
- // delete next.$id;
417
- // delete next.id;
418
- var anchor = id.substring(1);
395
+ const collectAnchors = (root) => {
396
+ const result = new Map();
397
+ this.traverseNodes(root, next => {
398
+ const id = next.$id || next.id;
399
+ const anchor = (0, objects_1.isString)(id) && id.charAt(0) === '#' ? id.substring(1) : next.$anchor;
400
+ if (anchor) {
419
401
  if (result.has(anchor)) {
420
- resolveErrors.push(localize('json.schema.duplicateid', 'Duplicate id declaration: \'{0}\'', id));
402
+ resolveErrors.push(localize('json.schema.duplicateid', 'Duplicate anchor declaration: \'{0}\'', anchor));
421
403
  }
422
404
  else {
423
405
  result.set(anchor, next);
424
406
  }
425
407
  }
408
+ if (next.$recursiveAnchor) {
409
+ usesUnsupportedFeatures.add('$recursiveAnchor');
410
+ }
411
+ if (next.$dynamicAnchor) {
412
+ usesUnsupportedFeatures.add('$dynamicAnchor');
413
+ }
426
414
  });
427
415
  return result;
428
416
  };
429
- return resolveRefs(schema, schema, handle).then(function (_) {
430
- return new ResolvedSchema(schema, resolveErrors);
417
+ return resolveRefs(schema, schema, handle).then(_ => {
418
+ let resolveWarnings = [];
419
+ if (usesUnsupportedFeatures.size) {
420
+ resolveWarnings.push(localize('json.schema.warnings', 'The schema uses meta-schema features ({0}) that are not yet supported by the validator.', Array.from(usesUnsupportedFeatures.keys()).join(', ')));
421
+ }
422
+ return new ResolvedSchema(schema, resolveErrors, resolveWarnings, schemaDraft);
431
423
  });
432
- };
433
- JSONSchemaService.prototype.traverseNodes = function (root, handle) {
424
+ }
425
+ traverseNodes(root, handle) {
434
426
  if (!root || typeof root !== 'object') {
435
427
  return Promise.resolve(null);
436
428
  }
437
- var seen = new Set();
438
- var collectEntries = function () {
439
- var entries = [];
440
- for (var _i = 0; _i < arguments.length; _i++) {
441
- entries[_i] = arguments[_i];
442
- }
443
- for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
444
- var entry = entries_1[_a];
445
- if (typeof entry === 'object') {
429
+ const seen = new Set();
430
+ const collectEntries = (...entries) => {
431
+ for (const entry of entries) {
432
+ if ((0, objects_1.isObject)(entry)) {
446
433
  toWalk.push(entry);
447
434
  }
448
435
  }
449
436
  };
450
- var collectMapEntries = function () {
451
- var maps = [];
452
- for (var _i = 0; _i < arguments.length; _i++) {
453
- maps[_i] = arguments[_i];
454
- }
455
- for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
456
- var map = maps_1[_a];
457
- if (typeof map === 'object') {
458
- for (var k in map) {
459
- var key = k;
460
- var entry = map[key];
461
- if (typeof entry === 'object') {
437
+ const collectMapEntries = (...maps) => {
438
+ for (const map of maps) {
439
+ if ((0, objects_1.isObject)(map)) {
440
+ for (const k in map) {
441
+ const key = k;
442
+ const entry = map[key];
443
+ if ((0, objects_1.isObject)(entry)) {
462
444
  toWalk.push(entry);
463
445
  }
464
446
  }
465
447
  }
466
448
  }
467
449
  };
468
- var collectArrayEntries = function () {
469
- var arrays = [];
470
- for (var _i = 0; _i < arguments.length; _i++) {
471
- arrays[_i] = arguments[_i];
472
- }
473
- for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
474
- var array = arrays_1[_a];
450
+ const collectArrayEntries = (...arrays) => {
451
+ for (const array of arrays) {
475
452
  if (Array.isArray(array)) {
476
- for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
477
- var entry = array_1[_b];
478
- if (typeof entry === 'object') {
453
+ for (const entry of array) {
454
+ if ((0, objects_1.isObject)(entry)) {
479
455
  toWalk.push(entry);
480
456
  }
481
457
  }
482
458
  }
483
459
  }
484
460
  };
485
- var toWalk = [root];
486
- var next = toWalk.pop();
461
+ const collectEntryOrArrayEntries = (items) => {
462
+ if (Array.isArray(items)) {
463
+ for (const entry of items) {
464
+ if ((0, objects_1.isObject)(entry)) {
465
+ toWalk.push(entry);
466
+ }
467
+ }
468
+ }
469
+ else if ((0, objects_1.isObject)(items)) {
470
+ toWalk.push(items);
471
+ }
472
+ };
473
+ const toWalk = [root];
474
+ let next = toWalk.pop();
487
475
  while (next) {
488
476
  if (!seen.has(next)) {
489
477
  seen.add(next);
490
478
  handle(next);
491
- collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
492
- collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
493
- collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
479
+ collectEntries(next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else, next.unevaluatedItems, next.unevaluatedProperties);
480
+ collectMapEntries(next.definitions, next.$defs, next.properties, next.patternProperties, next.dependencies, next.dependentSchemas);
481
+ collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.prefixItems);
482
+ collectEntryOrArrayEntries(next.items);
494
483
  }
495
484
  next = toWalk.pop();
496
485
  }
497
- };
486
+ }
498
487
  ;
499
- JSONSchemaService.prototype.getSchemaFromProperty = function (resource, document) {
500
- var _a, _b;
501
- if (((_a = document.root) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
502
- for (var _i = 0, _c = document.root.properties; _i < _c.length; _i++) {
503
- var p = _c[_i];
504
- if (p.keyNode.value === '$schema' && ((_b = p.valueNode) === null || _b === void 0 ? void 0 : _b.type) === 'string') {
505
- var schemaId = p.valueNode.value;
488
+ getSchemaFromProperty(resource, document) {
489
+ if (document.root?.type === 'object') {
490
+ for (const p of document.root.properties) {
491
+ if (p.keyNode.value === '$schema' && p.valueNode?.type === 'string') {
492
+ let schemaId = p.valueNode.value;
506
493
  if (this.contextService && !/^\w[\w\d+.-]*:/.test(schemaId)) { // has scheme
507
494
  schemaId = this.contextService.resolveRelativePath(schemaId, resource);
508
495
  }
@@ -511,16 +498,14 @@
511
498
  }
512
499
  }
513
500
  return undefined;
514
- };
515
- JSONSchemaService.prototype.getAssociatedSchemas = function (resource) {
516
- var seen = Object.create(null);
517
- var schemas = [];
518
- var normalizedResource = normalizeResourceForMatching(resource);
519
- for (var _i = 0, _a = this.filePatternAssociations; _i < _a.length; _i++) {
520
- var entry = _a[_i];
501
+ }
502
+ getAssociatedSchemas(resource) {
503
+ const seen = Object.create(null);
504
+ const schemas = [];
505
+ const normalizedResource = normalizeResourceForMatching(resource);
506
+ for (const entry of this.filePatternAssociations) {
521
507
  if (entry.matchesPattern(normalizedResource)) {
522
- for (var _b = 0, _c = entry.getURIs(); _b < _c.length; _b++) {
523
- var schemaId = _c[_b];
508
+ for (const schemaId of entry.getURIs()) {
524
509
  if (!seen[schemaId]) {
525
510
  schemas.push(schemaId);
526
511
  seen[schemaId] = true;
@@ -529,66 +514,65 @@
529
514
  }
530
515
  }
531
516
  return schemas;
532
- };
533
- JSONSchemaService.prototype.getSchemaURIsForResource = function (resource, document) {
534
- var schemeId = document && this.getSchemaFromProperty(resource, document);
517
+ }
518
+ getSchemaURIsForResource(resource, document) {
519
+ let schemeId = document && this.getSchemaFromProperty(resource, document);
535
520
  if (schemeId) {
536
521
  return [schemeId];
537
522
  }
538
523
  return this.getAssociatedSchemas(resource);
539
- };
540
- JSONSchemaService.prototype.getSchemaForResource = function (resource, document) {
524
+ }
525
+ getSchemaForResource(resource, document) {
541
526
  if (document) {
542
527
  // first use $schema if present
543
- var schemeId = this.getSchemaFromProperty(resource, document);
528
+ let schemeId = this.getSchemaFromProperty(resource, document);
544
529
  if (schemeId) {
545
- var id = normalizeId(schemeId);
530
+ const id = normalizeId(schemeId);
546
531
  return this.getOrAddSchemaHandle(id).getResolvedSchema();
547
532
  }
548
533
  }
549
534
  if (this.cachedSchemaForResource && this.cachedSchemaForResource.resource === resource) {
550
535
  return this.cachedSchemaForResource.resolvedSchema;
551
536
  }
552
- var schemas = this.getAssociatedSchemas(resource);
553
- var resolvedSchema = schemas.length > 0 ? this.createCombinedSchema(resource, schemas).getResolvedSchema() : this.promise.resolve(undefined);
554
- this.cachedSchemaForResource = { resource: resource, resolvedSchema: resolvedSchema };
537
+ const schemas = this.getAssociatedSchemas(resource);
538
+ const resolvedSchema = schemas.length > 0 ? this.createCombinedSchema(resource, schemas).getResolvedSchema() : this.promise.resolve(undefined);
539
+ this.cachedSchemaForResource = { resource, resolvedSchema };
555
540
  return resolvedSchema;
556
- };
557
- JSONSchemaService.prototype.createCombinedSchema = function (resource, schemaIds) {
541
+ }
542
+ createCombinedSchema(resource, schemaIds) {
558
543
  if (schemaIds.length === 1) {
559
544
  return this.getOrAddSchemaHandle(schemaIds[0]);
560
545
  }
561
546
  else {
562
- var combinedSchemaId = 'schemaservice://combinedSchema/' + encodeURIComponent(resource);
563
- var combinedSchema = {
564
- allOf: schemaIds.map(function (schemaId) { return ({ $ref: schemaId }); })
547
+ const combinedSchemaId = 'schemaservice://combinedSchema/' + encodeURIComponent(resource);
548
+ const combinedSchema = {
549
+ allOf: schemaIds.map(schemaId => ({ $ref: schemaId }))
565
550
  };
566
551
  return this.addSchemaHandle(combinedSchemaId, combinedSchema);
567
552
  }
568
- };
569
- JSONSchemaService.prototype.getMatchingSchemas = function (document, jsonDocument, schema) {
553
+ }
554
+ getMatchingSchemas(document, jsonDocument, schema) {
570
555
  if (schema) {
571
- var id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
572
- var handle = this.addSchemaHandle(id, schema);
573
- return handle.getResolvedSchema().then(function (resolvedSchema) {
574
- return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(function (s) { return !s.inverted; });
556
+ const id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
557
+ const handle = this.addSchemaHandle(id, schema);
558
+ return handle.getResolvedSchema().then(resolvedSchema => {
559
+ return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(s => !s.inverted);
575
560
  });
576
561
  }
577
- return this.getSchemaForResource(document.uri, jsonDocument).then(function (schema) {
562
+ return this.getSchemaForResource(document.uri, jsonDocument).then(schema => {
578
563
  if (schema) {
579
- return jsonDocument.getMatchingSchemas(schema.schema).filter(function (s) { return !s.inverted; });
564
+ return jsonDocument.getMatchingSchemas(schema.schema).filter(s => !s.inverted);
580
565
  }
581
566
  return [];
582
567
  });
583
- };
584
- return JSONSchemaService;
585
- }());
568
+ }
569
+ }
586
570
  exports.JSONSchemaService = JSONSchemaService;
587
- var idCounter = 0;
571
+ let idCounter = 0;
588
572
  function normalizeId(id) {
589
573
  // remove trailing '#', normalize drive capitalization
590
574
  try {
591
- return vscode_uri_1.URI.parse(id).toString();
575
+ return vscode_uri_1.URI.parse(id).toString(true);
592
576
  }
593
577
  catch (e) {
594
578
  return id;
@@ -597,7 +581,7 @@
597
581
  function normalizeResourceForMatching(resource) {
598
582
  // remove queries and fragments, normalize drive capitalization
599
583
  try {
600
- return vscode_uri_1.URI.parse(resource).with({ fragment: null, query: null }).toString();
584
+ return vscode_uri_1.URI.parse(resource).with({ fragment: null, query: null }).toString(true);
601
585
  }
602
586
  catch (e) {
603
587
  return resource;
@@ -605,7 +589,7 @@
605
589
  }
606
590
  function toDisplayString(url) {
607
591
  try {
608
- var uri = vscode_uri_1.URI.parse(url);
592
+ const uri = vscode_uri_1.URI.parse(url);
609
593
  if (uri.scheme === 'file') {
610
594
  return uri.fsPath;
611
595
  }