vscode-json-languageservice 5.1.4 → 5.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 CHANGED
@@ -1,4 +1,8 @@
1
- 5.2.0 / 2022-08/19
1
+ 5.2.0 / 2023-02-02
2
+ ================
3
+ * Added `SchemaConfiguration.folderUri` for folder-specific schema associations
4
+
5
+ 5.1.1 / 2022-08/19
2
6
  ================
3
7
  * new type `SchemaDraft`, representing the offical JSON schema draft versions
4
8
  * new property `DocumentLanguageSettings.schemaDraft` to specify the schema version to use, if the schema does not contain a `$schema` property
@@ -26,11 +26,7 @@ export function getLanguageService(params) {
26
26
  return {
27
27
  configure: (settings) => {
28
28
  jsonSchemaService.clearExternalSchemas();
29
- if (settings.schemas) {
30
- settings.schemas.forEach(settings => {
31
- jsonSchemaService.registerExternalSchema(settings.uri, settings.fileMatch, settings.schema);
32
- });
33
- }
29
+ settings.schemas?.forEach(jsonSchemaService.registerExternalSchema.bind(jsonSchemaService));
34
30
  jsonValidation.configure(settings);
35
31
  },
36
32
  resetSchema: (uri) => jsonSchemaService.onResourceChange(uri),
@@ -141,6 +141,11 @@ export interface SchemaConfiguration {
141
141
  * If no schema is provided, the schema will be fetched with the schema request service (if available).
142
142
  */
143
143
  schema?: JSONSchema;
144
+ /**
145
+ * A parent folder for folder specifc associations. An association that has a folder URI set is only used
146
+ * if the document that is validated has the folderUri as parent
147
+ */
148
+ folderUri?: string;
144
149
  }
145
150
  export interface WorkspaceContextService {
146
151
  resolveRelativePath(relativePath: string, resource: string): string;
@@ -12,7 +12,9 @@ import { isObject, isString } from '../utils/objects';
12
12
  const BANG = '!';
13
13
  const PATH_SEP = '/';
14
14
  class FilePatternAssociation {
15
- constructor(pattern, uris) {
15
+ constructor(pattern, folderUri, uris) {
16
+ this.folderUri = folderUri;
17
+ this.uris = uris;
16
18
  this.globWrappers = [];
17
19
  try {
18
20
  for (let patternString of pattern) {
@@ -31,7 +33,9 @@ class FilePatternAssociation {
31
33
  }
32
34
  }
33
35
  ;
34
- this.uris = uris;
36
+ if (folderUri && !folderUri.endsWith('/')) {
37
+ this.folderUri = folderUri + '/';
38
+ }
35
39
  }
36
40
  catch (e) {
37
41
  this.globWrappers.length = 0;
@@ -39,6 +43,9 @@ class FilePatternAssociation {
39
43
  }
40
44
  }
41
45
  matchesPattern(fileName) {
46
+ if (this.folderUri && !fileName.startsWith(this.folderUri)) {
47
+ return false;
48
+ }
42
49
  let match = false;
43
50
  for (const { regexp, include } of this.globWrappers) {
44
51
  if (regexp.test(fileName)) {
@@ -199,7 +206,7 @@ export class JSONSchemaService {
199
206
  const schemaAssociations = schemaContributions.schemaAssociations;
200
207
  for (let schemaAssociation of schemaAssociations) {
201
208
  const uris = schemaAssociation.uris.map(normalizeId);
202
- const association = this.addFilePatternAssociation(schemaAssociation.pattern, uris);
209
+ const association = this.addFilePatternAssociation(schemaAssociation.pattern, schemaAssociation.folderUri, uris);
203
210
  this.contributionAssociations.push(association);
204
211
  }
205
212
  }
@@ -212,19 +219,19 @@ export class JSONSchemaService {
212
219
  getOrAddSchemaHandle(id, unresolvedSchemaContent) {
213
220
  return this.schemasById[id] || this.addSchemaHandle(id, unresolvedSchemaContent);
214
221
  }
215
- addFilePatternAssociation(pattern, uris) {
216
- const fpa = new FilePatternAssociation(pattern, uris);
222
+ addFilePatternAssociation(pattern, folderUri, uris) {
223
+ const fpa = new FilePatternAssociation(pattern, folderUri, uris);
217
224
  this.filePatternAssociations.push(fpa);
218
225
  return fpa;
219
226
  }
220
- registerExternalSchema(uri, filePatterns, unresolvedSchemaContent) {
221
- const id = normalizeId(uri);
227
+ registerExternalSchema(config) {
228
+ const id = normalizeId(config.uri);
222
229
  this.registeredSchemasIds[id] = true;
223
230
  this.cachedSchemaForResource = undefined;
224
- if (filePatterns) {
225
- this.addFilePatternAssociation(filePatterns, [id]);
231
+ if (config.fileMatch && config.fileMatch.length) {
232
+ this.addFilePatternAssociation(config.fileMatch, config.folderUri, [id]);
226
233
  }
227
- return unresolvedSchemaContent ? this.addSchemaHandle(id, unresolvedSchemaContent) : this.getOrAddSchemaHandle(id);
234
+ return config.schema ? this.addSchemaHandle(id, config.schema) : this.getOrAddSchemaHandle(id);
228
235
  }
229
236
  clearExternalSchemas() {
230
237
  this.schemasById = {};
@@ -89,8 +89,8 @@ export class JSONValidation {
89
89
  return diagnostics;
90
90
  };
91
91
  if (schema) {
92
- const id = schema.id || ('schemaservice://untitled/' + idCounter++);
93
- const handle = this.jsonSchemaService.registerExternalSchema(id, [], schema);
92
+ const uri = schema.id || ('schemaservice://untitled/' + idCounter++);
93
+ const handle = this.jsonSchemaService.registerExternalSchema({ uri, schema });
94
94
  return handle.getResolvedSchema().then(resolvedSchema => {
95
95
  return getDiagnostics(resolvedSchema);
96
96
  });
@@ -52,11 +52,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
52
52
  return {
53
53
  configure: (settings) => {
54
54
  jsonSchemaService.clearExternalSchemas();
55
- if (settings.schemas) {
56
- settings.schemas.forEach(settings => {
57
- jsonSchemaService.registerExternalSchema(settings.uri, settings.fileMatch, settings.schema);
58
- });
59
- }
55
+ settings.schemas?.forEach(jsonSchemaService.registerExternalSchema.bind(jsonSchemaService));
60
56
  jsonValidation.configure(settings);
61
57
  },
62
58
  resetSchema: (uri) => jsonSchemaService.onResourceChange(uri),
@@ -141,6 +141,11 @@ export interface SchemaConfiguration {
141
141
  * If no schema is provided, the schema will be fetched with the schema request service (if available).
142
142
  */
143
143
  schema?: JSONSchema;
144
+ /**
145
+ * A parent folder for folder specifc associations. An association that has a folder URI set is only used
146
+ * if the document that is validated has the folderUri as parent
147
+ */
148
+ folderUri?: string;
144
149
  }
145
150
  export interface WorkspaceContextService {
146
151
  resolveRelativePath(relativePath: string, resource: string): string;
@@ -24,7 +24,9 @@
24
24
  const BANG = '!';
25
25
  const PATH_SEP = '/';
26
26
  class FilePatternAssociation {
27
- constructor(pattern, uris) {
27
+ constructor(pattern, folderUri, uris) {
28
+ this.folderUri = folderUri;
29
+ this.uris = uris;
28
30
  this.globWrappers = [];
29
31
  try {
30
32
  for (let patternString of pattern) {
@@ -43,7 +45,9 @@
43
45
  }
44
46
  }
45
47
  ;
46
- this.uris = uris;
48
+ if (folderUri && !folderUri.endsWith('/')) {
49
+ this.folderUri = folderUri + '/';
50
+ }
47
51
  }
48
52
  catch (e) {
49
53
  this.globWrappers.length = 0;
@@ -51,6 +55,9 @@
51
55
  }
52
56
  }
53
57
  matchesPattern(fileName) {
58
+ if (this.folderUri && !fileName.startsWith(this.folderUri)) {
59
+ return false;
60
+ }
54
61
  let match = false;
55
62
  for (const { regexp, include } of this.globWrappers) {
56
63
  if (regexp.test(fileName)) {
@@ -213,7 +220,7 @@
213
220
  const schemaAssociations = schemaContributions.schemaAssociations;
214
221
  for (let schemaAssociation of schemaAssociations) {
215
222
  const uris = schemaAssociation.uris.map(normalizeId);
216
- const association = this.addFilePatternAssociation(schemaAssociation.pattern, uris);
223
+ const association = this.addFilePatternAssociation(schemaAssociation.pattern, schemaAssociation.folderUri, uris);
217
224
  this.contributionAssociations.push(association);
218
225
  }
219
226
  }
@@ -226,19 +233,19 @@
226
233
  getOrAddSchemaHandle(id, unresolvedSchemaContent) {
227
234
  return this.schemasById[id] || this.addSchemaHandle(id, unresolvedSchemaContent);
228
235
  }
229
- addFilePatternAssociation(pattern, uris) {
230
- const fpa = new FilePatternAssociation(pattern, uris);
236
+ addFilePatternAssociation(pattern, folderUri, uris) {
237
+ const fpa = new FilePatternAssociation(pattern, folderUri, uris);
231
238
  this.filePatternAssociations.push(fpa);
232
239
  return fpa;
233
240
  }
234
- registerExternalSchema(uri, filePatterns, unresolvedSchemaContent) {
235
- const id = normalizeId(uri);
241
+ registerExternalSchema(config) {
242
+ const id = normalizeId(config.uri);
236
243
  this.registeredSchemasIds[id] = true;
237
244
  this.cachedSchemaForResource = undefined;
238
- if (filePatterns) {
239
- this.addFilePatternAssociation(filePatterns, [id]);
245
+ if (config.fileMatch && config.fileMatch.length) {
246
+ this.addFilePatternAssociation(config.fileMatch, config.folderUri, [id]);
240
247
  }
241
- return unresolvedSchemaContent ? this.addSchemaHandle(id, unresolvedSchemaContent) : this.getOrAddSchemaHandle(id);
248
+ return config.schema ? this.addSchemaHandle(id, config.schema) : this.getOrAddSchemaHandle(id);
242
249
  }
243
250
  clearExternalSchemas() {
244
251
  this.schemasById = {};
@@ -101,8 +101,8 @@
101
101
  return diagnostics;
102
102
  };
103
103
  if (schema) {
104
- const id = schema.id || ('schemaservice://untitled/' + idCounter++);
105
- const handle = this.jsonSchemaService.registerExternalSchema(id, [], schema);
104
+ const uri = schema.id || ('schemaservice://untitled/' + idCounter++);
105
+ const handle = this.jsonSchemaService.registerExternalSchema({ uri, schema });
106
106
  return handle.getResolvedSchema().then(resolvedSchema => {
107
107
  return getDiagnostics(resolvedSchema);
108
108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "5.1.4",
3
+ "version": "5.2.0",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",