volar-service-json 0.0.16 → 0.0.18
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/out/index.d.ts +2 -3
- package/out/index.js +116 -119
- package/package.json +3 -3
package/out/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServicePlugin } from '@volar/language-service';
|
|
2
2
|
import * as json from 'vscode-json-languageservice';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export interface Provide {
|
|
5
5
|
'json/jsonDocument': (document: TextDocument) => json.JSONDocument | undefined;
|
|
6
6
|
'json/languageService': () => json.LanguageService;
|
|
7
7
|
}
|
|
8
|
-
export declare function create(settings?: json.LanguageSettings):
|
|
9
|
-
export default create;
|
|
8
|
+
export declare function create(settings?: json.LanguageSettings): ServicePlugin;
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.js
CHANGED
|
@@ -3,131 +3,128 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.create = void 0;
|
|
4
4
|
const json = require("vscode-json-languageservice");
|
|
5
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
6
|
-
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/json-language-features/server/src/jsonServer.ts#L150
|
|
7
|
-
const triggerCharacters = ['"', ':'];
|
|
8
6
|
function create(settings) {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
21
|
-
return base + ref;
|
|
22
|
-
}
|
|
23
|
-
const baseUri = vscode_uri_1.URI.parse(base);
|
|
24
|
-
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
25
|
-
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
const jsonLs = json.getLanguageService({
|
|
29
|
-
schemaRequestService: async (uri) => await context.env.fs?.readFile(uri) ?? '',
|
|
30
|
-
workspaceContext,
|
|
31
|
-
clientCapabilities: context.env.clientCapabilities,
|
|
32
|
-
});
|
|
33
|
-
if (settings) {
|
|
34
|
-
jsonLs.configure(settings);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
provide: {
|
|
38
|
-
'json/jsonDocument': getJsonDocument,
|
|
39
|
-
'json/languageService': () => jsonLs,
|
|
40
|
-
},
|
|
41
|
-
triggerCharacters,
|
|
42
|
-
provideCompletionItems(document, position) {
|
|
43
|
-
return worker(document, async (jsonDocument) => {
|
|
44
|
-
return await jsonLs.doComplete(document, position, jsonDocument);
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
resolveCompletionItem(item) {
|
|
48
|
-
return jsonLs.doResolve(item);
|
|
49
|
-
},
|
|
50
|
-
provideDefinition(document, position) {
|
|
51
|
-
return worker(document, async (jsonDocument) => {
|
|
52
|
-
return await jsonLs.findDefinition(document, position, jsonDocument);
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
provideDiagnostics(document) {
|
|
56
|
-
return worker(document, async (jsonDocument) => {
|
|
57
|
-
const documentLanguageSettings = undefined; // await getSettings(); // TODO
|
|
58
|
-
return await jsonLs.doValidation(document, jsonDocument, documentLanguageSettings, undefined);
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
provideHover(document, position) {
|
|
62
|
-
return worker(document, async (jsonDocument) => {
|
|
63
|
-
return await jsonLs.doHover(document, position, jsonDocument);
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
provideDocumentLinks(document) {
|
|
67
|
-
return worker(document, async (jsonDocument) => {
|
|
68
|
-
return await jsonLs.findLinks(document, jsonDocument);
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
provideDocumentSymbols(document) {
|
|
72
|
-
return worker(document, async (jsonDocument) => {
|
|
73
|
-
return await jsonLs.findDocumentSymbols2(document, jsonDocument);
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
provideDocumentColors(document) {
|
|
77
|
-
return worker(document, async (jsonDocument) => {
|
|
78
|
-
return await jsonLs.findDocumentColors(document, jsonDocument);
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
provideColorPresentations(document, color, range) {
|
|
82
|
-
return worker(document, async (jsonDocument) => {
|
|
83
|
-
return await jsonLs.getColorPresentations(document, jsonDocument, color, range);
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
provideFoldingRanges(document) {
|
|
87
|
-
return worker(document, async () => {
|
|
88
|
-
return await jsonLs.getFoldingRanges(document);
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
provideSelectionRanges(document, positions) {
|
|
92
|
-
return worker(document, async (jsonDocument) => {
|
|
93
|
-
return await jsonLs.getSelectionRanges(document, positions, jsonDocument);
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
provideDocumentFormattingEdits(document, range, options) {
|
|
97
|
-
return worker(document, async () => {
|
|
98
|
-
const options_2 = await context.env.getConfiguration?.('json.format');
|
|
99
|
-
if (!(options_2?.enable ?? true)) {
|
|
100
|
-
return;
|
|
7
|
+
return {
|
|
8
|
+
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/json-language-features/server/src/jsonServer.ts#L150
|
|
9
|
+
triggerCharacters: ['"', ':'],
|
|
10
|
+
create(context) {
|
|
11
|
+
const jsonDocuments = new WeakMap();
|
|
12
|
+
const workspaceContext = {
|
|
13
|
+
resolveRelativePath: (ref, base) => {
|
|
14
|
+
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
|
15
|
+
// starts with a schema
|
|
16
|
+
return ref;
|
|
101
17
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
18
|
+
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
19
|
+
return base + ref;
|
|
20
|
+
}
|
|
21
|
+
const baseUri = vscode_uri_1.URI.parse(base);
|
|
22
|
+
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
23
|
+
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const jsonLs = json.getLanguageService({
|
|
27
|
+
schemaRequestService: async (uri) => await context.env.fs?.readFile(uri) ?? '',
|
|
28
|
+
workspaceContext,
|
|
29
|
+
clientCapabilities: context.env.clientCapabilities,
|
|
30
|
+
});
|
|
31
|
+
if (settings) {
|
|
32
|
+
jsonLs.configure(settings);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
provide: {
|
|
36
|
+
'json/jsonDocument': getJsonDocument,
|
|
37
|
+
'json/languageService': () => jsonLs,
|
|
38
|
+
},
|
|
39
|
+
provideCompletionItems(document, position) {
|
|
40
|
+
return worker(document, async (jsonDocument) => {
|
|
41
|
+
return await jsonLs.doComplete(document, position, jsonDocument);
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
resolveCompletionItem(item) {
|
|
45
|
+
return jsonLs.doResolve(item);
|
|
46
|
+
},
|
|
47
|
+
provideDefinition(document, position) {
|
|
48
|
+
return worker(document, async (jsonDocument) => {
|
|
49
|
+
return await jsonLs.findDefinition(document, position, jsonDocument);
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
provideDiagnostics(document) {
|
|
53
|
+
return worker(document, async (jsonDocument) => {
|
|
54
|
+
const documentLanguageSettings = undefined; // await getSettings(); // TODO
|
|
55
|
+
return await jsonLs.doValidation(document, jsonDocument, documentLanguageSettings, undefined);
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
provideHover(document, position) {
|
|
59
|
+
return worker(document, async (jsonDocument) => {
|
|
60
|
+
return await jsonLs.doHover(document, position, jsonDocument);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
provideDocumentLinks(document) {
|
|
64
|
+
return worker(document, async (jsonDocument) => {
|
|
65
|
+
return await jsonLs.findLinks(document, jsonDocument);
|
|
105
66
|
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
67
|
+
},
|
|
68
|
+
provideDocumentSymbols(document) {
|
|
69
|
+
return worker(document, async (jsonDocument) => {
|
|
70
|
+
return await jsonLs.findDocumentSymbols2(document, jsonDocument);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
provideDocumentColors(document) {
|
|
74
|
+
return worker(document, async (jsonDocument) => {
|
|
75
|
+
return await jsonLs.findDocumentColors(document, jsonDocument);
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
provideColorPresentations(document, color, range) {
|
|
79
|
+
return worker(document, async (jsonDocument) => {
|
|
80
|
+
return await jsonLs.getColorPresentations(document, jsonDocument, color, range);
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
provideFoldingRanges(document) {
|
|
84
|
+
return worker(document, async () => {
|
|
85
|
+
return await jsonLs.getFoldingRanges(document);
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
provideSelectionRanges(document, positions) {
|
|
89
|
+
return worker(document, async (jsonDocument) => {
|
|
90
|
+
return await jsonLs.getSelectionRanges(document, positions, jsonDocument);
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
provideDocumentFormattingEdits(document, range, options) {
|
|
94
|
+
return worker(document, async () => {
|
|
95
|
+
const options_2 = await context.env.getConfiguration?.('json.format');
|
|
96
|
+
if (!(options_2?.enable ?? true)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return jsonLs.format(document, range, {
|
|
100
|
+
...options_2,
|
|
101
|
+
...options,
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
function worker(document, callback) {
|
|
107
|
+
const jsonDocument = getJsonDocument(document);
|
|
108
|
+
if (!jsonDocument)
|
|
109
|
+
return;
|
|
110
|
+
return callback(jsonDocument);
|
|
111
|
+
}
|
|
112
|
+
function getJsonDocument(textDocument) {
|
|
113
|
+
if (textDocument.languageId !== 'json' && textDocument.languageId !== 'jsonc')
|
|
114
|
+
return;
|
|
115
|
+
const cache = jsonDocuments.get(textDocument);
|
|
116
|
+
if (cache) {
|
|
117
|
+
const [cacheVersion, cacheDoc] = cache;
|
|
118
|
+
if (cacheVersion === textDocument.version) {
|
|
119
|
+
return cacheDoc;
|
|
120
|
+
}
|
|
123
121
|
}
|
|
122
|
+
const doc = jsonLs.parseJSONDocument(textDocument);
|
|
123
|
+
jsonDocuments.set(textDocument, [textDocument.version, doc]);
|
|
124
|
+
return doc;
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
-
jsonDocuments.set(textDocument, [textDocument.version, doc]);
|
|
127
|
-
return doc;
|
|
128
|
-
}
|
|
126
|
+
},
|
|
129
127
|
};
|
|
130
128
|
}
|
|
131
129
|
exports.create = create;
|
|
132
|
-
exports.default = create;
|
|
133
130
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-json",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Integrate vscode-json-languageservice into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/json",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"vscode-languageserver-textdocument": "^1.0.11"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@volar/language-service": "
|
|
35
|
+
"@volar/language-service": "2.0.0-alpha.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@volar/language-service": {
|
|
39
39
|
"optional": true
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "8dedd3c6e73740fc7c1fe06df32b727ca504adc0"
|
|
43
43
|
}
|