vscode-json-languageservice 5.1.3 → 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 +5 -1
- package/lib/esm/jsonLanguageService.js +1 -5
- package/lib/esm/jsonLanguageTypes.d.ts +5 -0
- package/lib/esm/parser/jsonParser.js +1 -1
- package/lib/esm/services/jsonSchemaService.js +17 -10
- package/lib/esm/services/jsonValidation.js +2 -2
- package/lib/umd/jsonLanguageService.js +1 -5
- package/lib/umd/jsonLanguageTypes.d.ts +5 -0
- package/lib/umd/parser/jsonParser.js +1 -1
- package/lib/umd/services/jsonSchemaService.js +17 -10
- package/lib/umd/services/jsonValidation.js +2 -2
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
5.2.0 /
|
|
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
|
-
|
|
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;
|
|
@@ -330,7 +330,7 @@ function validate(n, schema, validationResult, matchingSchemas, context) {
|
|
|
330
330
|
if (!subValidationResult.hasProblems()) {
|
|
331
331
|
validationResult.problems.push({
|
|
332
332
|
location: { offset: node.offset, length: node.length },
|
|
333
|
-
message: l10n.t("Matches a schema that is not allowed.")
|
|
333
|
+
message: schema.errorMessage || l10n.t("Matches a schema that is not allowed.")
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
336
|
for (const ms of subMatchingSchemas.schemas) {
|
|
@@ -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
|
-
|
|
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(
|
|
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 (
|
|
225
|
-
this.addFilePatternAssociation(
|
|
231
|
+
if (config.fileMatch && config.fileMatch.length) {
|
|
232
|
+
this.addFilePatternAssociation(config.fileMatch, config.folderUri, [id]);
|
|
226
233
|
}
|
|
227
|
-
return
|
|
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
|
|
93
|
-
const handle = this.jsonSchemaService.registerExternalSchema(
|
|
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
|
-
|
|
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;
|
|
@@ -357,7 +357,7 @@
|
|
|
357
357
|
if (!subValidationResult.hasProblems()) {
|
|
358
358
|
validationResult.problems.push({
|
|
359
359
|
location: { offset: node.offset, length: node.length },
|
|
360
|
-
message: l10n.t("Matches a schema that is not allowed.")
|
|
360
|
+
message: schema.errorMessage || l10n.t("Matches a schema that is not allowed.")
|
|
361
361
|
});
|
|
362
362
|
}
|
|
363
363
|
for (const ms of subMatchingSchemas.schemas) {
|
|
@@ -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
|
-
|
|
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(
|
|
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 (
|
|
239
|
-
this.addFilePatternAssociation(
|
|
245
|
+
if (config.fileMatch && config.fileMatch.length) {
|
|
246
|
+
this.addFilePatternAssociation(config.fileMatch, config.folderUri, [id]);
|
|
240
247
|
}
|
|
241
|
-
return
|
|
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
|
|
105
|
-
const handle = this.jsonSchemaService.registerExternalSchema(
|
|
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.
|
|
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",
|
|
@@ -15,22 +15,22 @@
|
|
|
15
15
|
"url": "https://github.com/Microsoft/vscode-json-languageservice"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@types/mocha": "^10.0.
|
|
18
|
+
"@types/mocha": "^10.0.1",
|
|
19
19
|
"@types/node": "16.x",
|
|
20
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
21
|
-
"@typescript-eslint/parser": "^5.
|
|
22
|
-
"eslint": "^8.
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^5.48.2",
|
|
21
|
+
"@typescript-eslint/parser": "^5.48.2",
|
|
22
|
+
"eslint": "^8.32.0",
|
|
23
23
|
"json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite.git#69acf52990b004240839ae19b4bec8fb01d50876",
|
|
24
|
-
"mocha": "^10.
|
|
25
|
-
"rimraf": "^
|
|
26
|
-
"typescript": "^4.9.
|
|
24
|
+
"mocha": "^10.2.0",
|
|
25
|
+
"rimraf": "^4.1.1",
|
|
26
|
+
"typescript": "^4.9.4"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"jsonc-parser": "^3.2.0",
|
|
30
|
-
"vscode-languageserver-textdocument": "^1.0.
|
|
30
|
+
"vscode-languageserver-textdocument": "^1.0.8",
|
|
31
31
|
"vscode-languageserver-types": "^3.17.2",
|
|
32
|
-
"vscode-uri": "^3.0.
|
|
33
|
-
"@vscode/l10n": "^0.0.
|
|
32
|
+
"vscode-uri": "^3.0.7",
|
|
33
|
+
"@vscode/l10n": "^0.0.11"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
|