@volar/language-service 1.0.16 → 1.0.17
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/baseDocumentService.js +13 -28
- package/out/baseLanguageService.d.ts +2 -2
- package/out/baseLanguageService.js +4 -4
- package/out/documentFeatures/autoInsert.js +2 -2
- package/out/documentFeatures/colorPresentations.js +4 -4
- package/out/documentFeatures/documentColors.js +3 -3
- package/out/documentFeatures/documentSymbols.js +4 -4
- package/out/documentFeatures/foldingRanges.js +1 -1
- package/out/documentFeatures/format.js +37 -35
- package/out/documentFeatures/linkedEditingRanges.js +2 -2
- package/out/documentFeatures/selectionRanges.js +3 -3
- package/out/documents.d.ts +26 -56
- package/out/documents.js +102 -144
- package/out/languageFeatures/autoInsert.js +7 -7
- package/out/languageFeatures/callHierarchy.d.ts +1 -1
- package/out/languageFeatures/callHierarchy.js +33 -34
- package/out/languageFeatures/codeActionResolve.js +2 -3
- package/out/languageFeatures/codeActions.d.ts +1 -1
- package/out/languageFeatures/codeActions.js +10 -10
- package/out/languageFeatures/codeLens.js +3 -3
- package/out/languageFeatures/complete.d.ts +1 -1
- package/out/languageFeatures/complete.js +32 -33
- package/out/languageFeatures/completeResolve.js +3 -4
- package/out/languageFeatures/definition.d.ts +2 -2
- package/out/languageFeatures/definition.js +24 -20
- package/out/languageFeatures/documentHighlights.js +15 -15
- package/out/languageFeatures/documentLinks.js +8 -9
- package/out/languageFeatures/documentSemanticTokens.js +5 -5
- package/out/languageFeatures/executeCommand.d.ts +1 -1
- package/out/languageFeatures/executeCommand.js +2 -1
- package/out/languageFeatures/fileReferences.js +3 -4
- package/out/languageFeatures/fileRename.js +4 -4
- package/out/languageFeatures/hover.js +3 -3
- package/out/languageFeatures/inlayHints.js +10 -10
- package/out/languageFeatures/references.js +21 -20
- package/out/languageFeatures/rename.d.ts +2 -2
- package/out/languageFeatures/rename.js +99 -80
- package/out/languageFeatures/renamePrepare.js +3 -3
- package/out/languageFeatures/signatureHelp.js +1 -1
- package/out/languageFeatures/validation.js +19 -18
- package/out/languageFeatures/workspaceSymbols.js +6 -5
- package/out/types.d.ts +9 -8
- package/out/utils/definePlugin.d.ts +3 -2
- package/out/utils/definePlugin.js +9 -6
- package/out/utils/featureWorkers.d.ts +5 -5
- package/out/utils/featureWorkers.js +15 -14
- package/package.json +7 -7
|
@@ -15,8 +15,8 @@ const dedupe = require("../utils/dedupe");
|
|
|
15
15
|
function register(context) {
|
|
16
16
|
return (uri, position, newName) => {
|
|
17
17
|
let _data;
|
|
18
|
-
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, newName }, function* (arg,
|
|
19
|
-
for (const mapped of
|
|
18
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, newName }, function* (arg, map) {
|
|
19
|
+
for (const mapped of map.toGeneratedPositions(arg.position, data => {
|
|
20
20
|
_data = data;
|
|
21
21
|
return typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename;
|
|
22
22
|
})) {
|
|
@@ -30,10 +30,10 @@ function register(context) {
|
|
|
30
30
|
}, (plugin, document, arg) => __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
const recursiveChecker = dedupe.createLocationSet();
|
|
32
32
|
let result;
|
|
33
|
-
yield
|
|
33
|
+
yield withMirrors(document, arg.position, arg.newName);
|
|
34
34
|
return result;
|
|
35
|
-
function
|
|
36
|
-
var _a;
|
|
35
|
+
function withMirrors(document, position, newName) {
|
|
36
|
+
var _a, _b;
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
if (!((_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.on))
|
|
39
39
|
return;
|
|
@@ -49,20 +49,20 @@ function register(context) {
|
|
|
49
49
|
for (const editUri in workspaceEdit.changes) {
|
|
50
50
|
const textEdits = workspaceEdit.changes[editUri];
|
|
51
51
|
for (const textEdit of textEdits) {
|
|
52
|
-
let
|
|
52
|
+
let foundMirrorPosition = false;
|
|
53
53
|
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
for (const mapped of
|
|
54
|
+
const mirrorMap = (_b = context.documents.getMirrorMapByUri(editUri)) === null || _b === void 0 ? void 0 : _b[1];
|
|
55
|
+
if (mirrorMap) {
|
|
56
|
+
for (const mapped of mirrorMap.findMirrorPositions(textEdit.range.start)) {
|
|
57
57
|
if (!mapped[1].rename)
|
|
58
58
|
continue;
|
|
59
|
-
if (recursiveChecker.has({ uri:
|
|
59
|
+
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
|
|
60
60
|
continue;
|
|
61
|
-
|
|
62
|
-
yield
|
|
61
|
+
foundMirrorPosition = true;
|
|
62
|
+
yield withMirrors(mirrorMap.document, mapped[0], newName);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
if (!
|
|
65
|
+
if (!foundMirrorPosition) {
|
|
66
66
|
if (!result.changes)
|
|
67
67
|
result.changes = {};
|
|
68
68
|
if (!result.changes[editUri])
|
|
@@ -132,106 +132,125 @@ function mergeWorkspaceEdits(original, ...others) {
|
|
|
132
132
|
}
|
|
133
133
|
exports.mergeWorkspaceEdits = mergeWorkspaceEdits;
|
|
134
134
|
function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
135
|
-
var _a, _b, _c
|
|
136
|
-
const
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
const sourceResult = {};
|
|
137
137
|
let hasResult = false;
|
|
138
138
|
for (const tsUri in tsResult.changeAnnotations) {
|
|
139
|
-
|
|
140
|
-
vueResult.changeAnnotations = {};
|
|
139
|
+
(_a = sourceResult.changeAnnotations) !== null && _a !== void 0 ? _a : (sourceResult.changeAnnotations = {});
|
|
141
140
|
const tsAnno = tsResult.changeAnnotations[tsUri];
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
if (!vueDocuments.getVirtualFileByUri(tsUri)) {
|
|
142
|
+
sourceResult.changeAnnotations[tsUri] = tsAnno;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsUri)) {
|
|
146
|
+
// TODO: check capability?
|
|
147
|
+
const uri = map.sourceFileDocument.uri;
|
|
148
|
+
sourceResult.changeAnnotations[uri] = tsAnno;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
144
151
|
}
|
|
145
152
|
for (const tsUri in tsResult.changes) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const map = vueDocuments.sourceMapFromEmbeddedDocumentUri(tsUri);
|
|
150
|
-
if (!map) {
|
|
151
|
-
vueResult.changes[tsUri] = tsResult.changes[tsUri];
|
|
153
|
+
(_b = sourceResult.changes) !== null && _b !== void 0 ? _b : (sourceResult.changes = {});
|
|
154
|
+
if (!vueDocuments.getVirtualFileByUri(tsUri)) {
|
|
155
|
+
sourceResult.changes[tsUri] = tsResult.changes[tsUri];
|
|
152
156
|
hasResult = true;
|
|
153
157
|
continue;
|
|
154
158
|
}
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsUri)) {
|
|
160
|
+
const tsEdits = tsResult.changes[tsUri];
|
|
161
|
+
for (const tsEdit of tsEdits) {
|
|
162
|
+
let _data;
|
|
163
|
+
const range = map.toSourceRange(tsEdit.range, data => {
|
|
164
|
+
_data = data;
|
|
165
|
+
return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
|
|
166
|
+
});
|
|
167
|
+
if (range) {
|
|
168
|
+
let newText = tsEdit.newText;
|
|
169
|
+
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
170
|
+
newText = _data.rename.apply(tsEdit.newText);
|
|
171
|
+
}
|
|
172
|
+
if (!sourceResult.changes[map.sourceFileDocument.uri]) {
|
|
173
|
+
sourceResult.changes[map.sourceFileDocument.uri] = [];
|
|
174
|
+
}
|
|
175
|
+
sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range });
|
|
176
|
+
hasResult = true;
|
|
169
177
|
}
|
|
170
|
-
vueResult.changes[map.sourceDocument.uri].push({ newText, range });
|
|
171
|
-
hasResult = true;
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
}
|
|
175
181
|
if (tsResult.documentChanges) {
|
|
176
182
|
for (const tsDocEdit of tsResult.documentChanges) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
let vueDocEdit;
|
|
183
|
+
(_c = sourceResult.documentChanges) !== null && _c !== void 0 ? _c : (sourceResult.documentChanges = []);
|
|
184
|
+
let sourceEdit;
|
|
181
185
|
if (vscode.TextDocumentEdit.is(tsDocEdit)) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
if (range) {
|
|
197
|
-
let newText = tsEdit.newText;
|
|
198
|
-
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
199
|
-
newText = _data.rename.apply(tsEdit.newText);
|
|
200
|
-
}
|
|
201
|
-
vueDocEdit.edits.push({
|
|
202
|
-
annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
|
|
203
|
-
newText,
|
|
204
|
-
range,
|
|
186
|
+
if (vueDocuments.getVirtualFileByUri(tsDocEdit.textDocument.uri)) {
|
|
187
|
+
for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.textDocument.uri)) {
|
|
188
|
+
sourceEdit = vscode.TextDocumentEdit.create({
|
|
189
|
+
uri: map.sourceFileDocument.uri,
|
|
190
|
+
// version: map.sourceDocument.version,
|
|
191
|
+
version: null, // fix https://github.com/johnsoncodehk/volar/issues/1490
|
|
192
|
+
}, []);
|
|
193
|
+
for (const tsEdit of tsDocEdit.edits) {
|
|
194
|
+
let _data;
|
|
195
|
+
const range = map.toSourceRange(tsEdit.range, data => {
|
|
196
|
+
_data = data;
|
|
197
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1091
|
|
198
|
+
return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
|
|
205
199
|
});
|
|
200
|
+
if (range) {
|
|
201
|
+
let newText = tsEdit.newText;
|
|
202
|
+
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
203
|
+
newText = _data.rename.apply(tsEdit.newText);
|
|
204
|
+
}
|
|
205
|
+
sourceEdit.edits.push({
|
|
206
|
+
annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
|
|
207
|
+
newText,
|
|
208
|
+
range,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!sourceEdit.edits.length) {
|
|
213
|
+
sourceEdit = undefined;
|
|
206
214
|
}
|
|
207
|
-
}
|
|
208
|
-
if (!vueDocEdit.edits.length) {
|
|
209
|
-
vueDocEdit = undefined;
|
|
210
215
|
}
|
|
211
216
|
}
|
|
212
217
|
else {
|
|
213
|
-
|
|
218
|
+
sourceEdit = tsDocEdit;
|
|
214
219
|
}
|
|
215
220
|
}
|
|
216
221
|
else if (vscode.CreateFile.is(tsDocEdit)) {
|
|
217
|
-
|
|
222
|
+
sourceEdit = tsDocEdit; // TODO: remove .ts?
|
|
218
223
|
}
|
|
219
224
|
else if (vscode.RenameFile.is(tsDocEdit)) {
|
|
220
|
-
|
|
221
|
-
|
|
225
|
+
if (!vueDocuments.getVirtualFileByUri(tsDocEdit.oldUri)) {
|
|
226
|
+
sourceEdit = tsDocEdit;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.oldUri)) {
|
|
230
|
+
// TODO: check capability?
|
|
231
|
+
sourceEdit = vscode.RenameFile.create(map.sourceFileDocument.uri, tsDocEdit.newUri /* TODO: remove .ts? */, tsDocEdit.options, tsDocEdit.annotationId);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
222
234
|
}
|
|
223
235
|
else if (vscode.DeleteFile.is(tsDocEdit)) {
|
|
224
|
-
|
|
225
|
-
|
|
236
|
+
if (!vueDocuments.getVirtualFileByUri(tsDocEdit.uri)) {
|
|
237
|
+
sourceEdit = tsDocEdit;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.uri)) {
|
|
241
|
+
// TODO: check capability?
|
|
242
|
+
sourceEdit = vscode.DeleteFile.create(map.sourceFileDocument.uri, tsDocEdit.options, tsDocEdit.annotationId);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
226
245
|
}
|
|
227
|
-
if (
|
|
228
|
-
|
|
246
|
+
if (sourceEdit) {
|
|
247
|
+
sourceResult.documentChanges.push(sourceEdit);
|
|
229
248
|
hasResult = true;
|
|
230
249
|
}
|
|
231
250
|
}
|
|
232
251
|
}
|
|
233
252
|
if (hasResult) {
|
|
234
|
-
return
|
|
253
|
+
return sourceResult;
|
|
235
254
|
}
|
|
236
255
|
}
|
|
237
256
|
exports.embeddedEditToSourceEdit = embeddedEditToSourceEdit;
|
|
@@ -17,12 +17,12 @@ const htmlWordPatterns = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|
|
|
|
17
17
|
function register(context) {
|
|
18
18
|
return (uri, position) => __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
const document = context.getTextDocument(uri);
|
|
20
|
-
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position,
|
|
21
|
-
if (!
|
|
20
|
+
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => {
|
|
21
|
+
if (!map) {
|
|
22
22
|
return item;
|
|
23
23
|
}
|
|
24
24
|
if (vscode.Range.is(item)) {
|
|
25
|
-
return
|
|
25
|
+
return map.toSourceRange(item);
|
|
26
26
|
}
|
|
27
27
|
}, prepares => {
|
|
28
28
|
for (const prepare of prepares) {
|
|
@@ -3,7 +3,7 @@ exports.register = void 0;
|
|
|
3
3
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
4
4
|
function register(context) {
|
|
5
5
|
return (uri, position, signatureHelpContext) => {
|
|
6
|
-
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position,
|
|
6
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { var _a; return (_a = plugin.getSignatureHelp) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, signatureHelpContext); }, (data) => data);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
exports.register = register;
|
|
@@ -146,8 +146,8 @@ function register(context) {
|
|
|
146
146
|
}
|
|
147
147
|
function worker(mode, cacheMap, cache) {
|
|
148
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg,
|
|
150
|
-
if (
|
|
149
|
+
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
150
|
+
if (file.capabilities.diagnostic) {
|
|
151
151
|
yield arg;
|
|
152
152
|
}
|
|
153
153
|
}, (plugin, document) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -163,7 +163,7 @@ function register(context) {
|
|
|
163
163
|
const pluginId = context.plugins.indexOf(plugin);
|
|
164
164
|
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
165
165
|
const cache = pluginCache.get(document.uri);
|
|
166
|
-
const tsProjectVersion = (mode === 'onDeclaration' || mode === 'onSemantic') ? (_c = (_b = context.core.
|
|
166
|
+
const tsProjectVersion = (mode === 'onDeclaration' || mode === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
167
167
|
if (mode === 'onDeclaration' || mode === 'onSemantic') {
|
|
168
168
|
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
169
169
|
return cache.errors;
|
|
@@ -182,7 +182,7 @@ function register(context) {
|
|
|
182
182
|
tsProjectVersion,
|
|
183
183
|
});
|
|
184
184
|
return errors;
|
|
185
|
-
}), (errors,
|
|
185
|
+
}), (errors, map) => transformErrorRange(map, errors), arr => dedupe.withDiagnostics(arr.flat()));
|
|
186
186
|
if (result) {
|
|
187
187
|
cache.errors = result;
|
|
188
188
|
cache.snapshot = newSnapshot;
|
|
@@ -190,13 +190,13 @@ function register(context) {
|
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
|
-
function transformErrorRange(
|
|
193
|
+
function transformErrorRange(map, errors) {
|
|
194
194
|
const result = [];
|
|
195
195
|
for (const error of errors) {
|
|
196
196
|
// clone it to avoid modify cache
|
|
197
197
|
let _error = Object.assign({}, error);
|
|
198
|
-
if (
|
|
199
|
-
const range =
|
|
198
|
+
if (map) {
|
|
199
|
+
const range = map.toSourceRange(error.range, data => !!data.diagnostic);
|
|
200
200
|
if (!range) {
|
|
201
201
|
continue;
|
|
202
202
|
}
|
|
@@ -205,17 +205,18 @@ function register(context) {
|
|
|
205
205
|
if (_error.relatedInformation) {
|
|
206
206
|
const relatedInfos = [];
|
|
207
207
|
for (const info of _error.relatedInformation) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
208
|
+
if (context.documents.getVirtualFileByUri(info.location.uri)) {
|
|
209
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(info.location.uri)) {
|
|
210
|
+
const range = map.toSourceRange(info.location.range, data => !!data.diagnostic);
|
|
211
|
+
if (range) {
|
|
212
|
+
relatedInfos.push({
|
|
213
|
+
location: {
|
|
214
|
+
uri: map.sourceFileDocument.uri,
|
|
215
|
+
range,
|
|
216
|
+
},
|
|
217
|
+
message: info.message,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
else {
|
|
@@ -21,11 +21,12 @@ function register(context) {
|
|
|
21
21
|
if (!embeddedSymbols)
|
|
22
22
|
continue;
|
|
23
23
|
const symbols = (0, transforms_1.transformSymbolInformations)(embeddedSymbols, loc => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (context.documents.getVirtualFileByUri(loc.uri)) {
|
|
25
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(loc.uri)) {
|
|
26
|
+
const range = map.toSourceRange(loc.range);
|
|
27
|
+
if (range) {
|
|
28
|
+
return vscode.Location.create(map.sourceFileDocument.uri, range);
|
|
29
|
+
}
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
else {
|
package/out/types.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageContext, LanguageServiceHost } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
import { SourceFileDocument, SourceFileDocuments } from './documents';
|
|
5
3
|
import type { DocumentContext, FileSystemProvider } from 'vscode-html-languageservice';
|
|
6
4
|
import type { SchemaRequestService } from 'vscode-json-languageservice';
|
|
7
|
-
import { URI } from 'vscode-uri';
|
|
8
5
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
6
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
7
|
+
import { URI } from 'vscode-uri';
|
|
8
|
+
import { DocumentsAndSourceMaps } from './documents';
|
|
9
9
|
export * from 'vscode-languageserver-protocol';
|
|
10
10
|
export interface DocumentServiceRuntimeContext {
|
|
11
11
|
typescript: typeof import('typescript/lib/tsserverlibrary');
|
|
12
12
|
plugins: LanguageServicePlugin[];
|
|
13
13
|
pluginContext: LanguageServicePluginContext;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
documents: DocumentsAndSourceMaps;
|
|
15
|
+
update(document: TextDocument): void;
|
|
16
|
+
updateVirtualFile(fileName: string, snapshot: ts.IScriptSnapshot): void;
|
|
16
17
|
prepareLanguageServices(document: TextDocument): void;
|
|
17
18
|
}
|
|
18
19
|
export interface LanguageServiceRuntimeContext {
|
|
19
20
|
host: LanguageServiceHost;
|
|
20
|
-
core:
|
|
21
|
+
core: LanguageContext;
|
|
21
22
|
typescriptLanguageService: ts.LanguageService;
|
|
22
|
-
documents:
|
|
23
|
+
documents: DocumentsAndSourceMaps;
|
|
23
24
|
plugins: LanguageServicePlugin[];
|
|
24
25
|
pluginContext: LanguageServicePluginContext;
|
|
25
26
|
getTextDocument(uri: string): TextDocument | undefined;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DocumentsAndSourceMaps, SourceMapWithDocuments } from '../documents';
|
|
2
|
+
import { FileRangeCapabilities, VirtualFile } from '@volar/language-core';
|
|
3
|
+
export declare function visitEmbedded(documents: DocumentsAndSourceMaps, current: VirtualFile, cb: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => Promise<boolean>, rootFile?: VirtualFile): Promise<boolean>;
|
|
@@ -9,16 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.visitEmbedded = void 0;
|
|
12
|
-
function visitEmbedded(
|
|
12
|
+
function visitEmbedded(documents, current, cb, rootFile = current) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
for (const embedded of current.
|
|
15
|
-
if (!(yield visitEmbedded(
|
|
14
|
+
for (const embedded of current.embeddedFiles) {
|
|
15
|
+
if (!(yield visitEmbedded(documents, embedded, cb, rootFile))) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
for (const [_, map] of documents.getMapsByVirtualFileName(current.fileName)) {
|
|
20
|
+
if (documents.getRootFileBySourceFileUri(map.sourceFileDocument.uri) === rootFile) {
|
|
21
|
+
if (!(yield cb(current, map))) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
return true;
|
|
24
27
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
2
|
import type { DocumentServiceRuntimeContext, LanguageServiceRuntimeContext } from '../types';
|
|
3
|
-
import { LanguageServicePlugin } from '@volar/language-service';
|
|
4
|
-
import {
|
|
5
|
-
export declare function documentFeatureWorker<T>(context: DocumentServiceRuntimeContext, document: TextDocument, isValidSourceMap: (sourceMap:
|
|
6
|
-
export declare function documentArgFeatureWorker<T, K>(context: DocumentServiceRuntimeContext, document: TextDocument, arg: K, isValidSourceMap: (sourceMap:
|
|
7
|
-
export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, uri: string, arg: K, transformArg: (arg: K, sourceMap:
|
|
3
|
+
import { LanguageServicePlugin, FileRangeCapabilities, VirtualFile } from '@volar/language-service';
|
|
4
|
+
import { SourceMapWithDocuments } from '../documents';
|
|
5
|
+
export declare function documentFeatureWorker<T>(context: DocumentServiceRuntimeContext, document: TextDocument, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (plugin: LanguageServicePlugin, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
6
|
+
export declare function documentArgFeatureWorker<T, K>(context: DocumentServiceRuntimeContext, document: TextDocument, arg: K, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => Generator<K> | K[], worker: (plugin: LanguageServicePlugin, document: TextDocument, arg: K) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
7
|
+
export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (plugin: LanguageServicePlugin, document: TextDocument, arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined, file: VirtualFile | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
@@ -18,19 +18,20 @@ function documentFeatureWorker(context, document, isValidSourceMap, worker, tran
|
|
|
18
18
|
exports.documentFeatureWorker = documentFeatureWorker;
|
|
19
19
|
function documentArgFeatureWorker(context, document, arg, isValidSourceMap, transformArg, worker, transform, combineResult) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
|
|
21
|
+
context.update(document);
|
|
22
|
+
const virtualFile = context.documents.getRootFileBySourceFileUri(document.uri);
|
|
22
23
|
let results = [];
|
|
23
|
-
if (
|
|
24
|
-
yield (0, definePlugin_1.visitEmbedded)(
|
|
25
|
-
if (!isValidSourceMap(
|
|
24
|
+
if (virtualFile) {
|
|
25
|
+
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!isValidSourceMap(file, map))
|
|
26
27
|
return true;
|
|
27
|
-
context.prepareLanguageServices(
|
|
28
|
-
for (const mappedArg of transformArg(arg,
|
|
28
|
+
context.prepareLanguageServices(map.virtualFileDocument);
|
|
29
|
+
for (const mappedArg of transformArg(arg, map)) {
|
|
29
30
|
for (const plugin of context.plugins) {
|
|
30
|
-
const embeddedResult = yield worker(plugin,
|
|
31
|
+
const embeddedResult = yield worker(plugin, map.virtualFileDocument, mappedArg);
|
|
31
32
|
if (!embeddedResult)
|
|
32
33
|
continue;
|
|
33
|
-
const result = yield transform(embeddedResult,
|
|
34
|
+
const result = yield transform(embeddedResult, map);
|
|
34
35
|
if (!result)
|
|
35
36
|
continue;
|
|
36
37
|
results.push(result);
|
|
@@ -64,16 +65,16 @@ exports.documentArgFeatureWorker = documentArgFeatureWorker;
|
|
|
64
65
|
function languageFeatureWorker(context, uri, arg, transformArg, worker, transform, combineResult, reportProgress) {
|
|
65
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
67
|
const document = context.getTextDocument(uri);
|
|
67
|
-
const
|
|
68
|
+
const virtualFile = context.documents.getRootFileBySourceFileUri(uri);
|
|
68
69
|
let results = [];
|
|
69
|
-
if (
|
|
70
|
-
yield (0, definePlugin_1.visitEmbedded)(
|
|
71
|
-
for (const mappedArg of transformArg(arg,
|
|
70
|
+
if (virtualFile) {
|
|
71
|
+
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
for (const mappedArg of transformArg(arg, map, file)) {
|
|
72
73
|
for (const plugin of context.plugins) {
|
|
73
|
-
const embeddedResult = yield worker(plugin,
|
|
74
|
+
const embeddedResult = yield worker(plugin, map.virtualFileDocument, mappedArg, map, file);
|
|
74
75
|
if (!embeddedResult)
|
|
75
76
|
continue;
|
|
76
|
-
const result = transform(embeddedResult,
|
|
77
|
+
const result = transform(embeddedResult, map);
|
|
77
78
|
if (!result)
|
|
78
79
|
continue;
|
|
79
80
|
results.push(result);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"directory": "packages/language-service"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.0.
|
|
17
|
-
"@volar/shared": "1.0.
|
|
18
|
-
"@volar/source-map": "1.0.
|
|
19
|
-
"@volar/transforms": "1.0.
|
|
20
|
-
"@volar/typescript-faster": "1.0.
|
|
16
|
+
"@volar/language-core": "1.0.17",
|
|
17
|
+
"@volar/shared": "1.0.17",
|
|
18
|
+
"@volar/source-map": "1.0.17",
|
|
19
|
+
"@volar/transforms": "1.0.17",
|
|
20
|
+
"@volar/typescript-faster": "1.0.17",
|
|
21
21
|
"@vue/reactivity": "^3.2.45",
|
|
22
22
|
"vscode-html-languageservice": "^5.0.3",
|
|
23
23
|
"vscode-json-languageservice": "^5.1.3",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"vscode-languageserver-textdocument": "^1.0.8",
|
|
26
26
|
"vscode-uri": "^3.0.7"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "b66b64f579b5cafee9b8d70aa9f9303f39b6df49"
|
|
29
29
|
}
|