@volar/language-service 2.0.0-alpha.12 → 2.0.0-alpha.14
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/lib/documents.d.ts +6 -6
- package/lib/documents.js +18 -23
- package/lib/features/provideCallHierarchyItems.js +22 -15
- package/lib/features/provideCodeActions.js +5 -3
- package/lib/features/provideColorPresentations.js +4 -2
- package/lib/features/provideCompletionItems.js +40 -22
- package/lib/features/provideDefinition.js +13 -8
- package/lib/features/provideDiagnostics.js +6 -5
- package/lib/features/provideDocumentDropEdits.js +1 -1
- package/lib/features/provideDocumentFormattingEdits.js +49 -37
- package/lib/features/provideDocumentHighlights.js +10 -6
- package/lib/features/provideDocumentSemanticTokens.js +5 -3
- package/lib/features/provideDocumentSymbols.js +2 -1
- package/lib/features/provideFileReferences.js +4 -4
- package/lib/features/provideFileRenameEdits.js +4 -17
- package/lib/features/provideInlayHints.js +3 -2
- package/lib/features/provideLinkedEditingRanges.js +2 -1
- package/lib/features/provideReferences.js +14 -10
- package/lib/features/provideRenameEdits.js +22 -13
- package/lib/features/provideSelectionRanges.js +2 -1
- package/lib/features/provideSignatureHelp.js +1 -1
- package/lib/features/provideWorkspaceSymbols.js +3 -3
- package/lib/features/resolveCodeAction.js +2 -1
- package/lib/features/resolveCodeLens.js +2 -1
- package/lib/features/resolveCompletionItem.js +5 -4
- package/lib/features/resolveDocumentLink.js +5 -4
- package/lib/features/resolveInlayHint.js +2 -1
- package/lib/languageService.d.ts +2 -2
- package/lib/languageService.js +5 -6
- package/lib/types.d.ts +15 -16
- package/lib/utils/common.js +10 -5
- package/lib/utils/featureWorkers.d.ts +3 -3
- package/lib/utils/featureWorkers.js +25 -17
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.js +26 -21
- package/package.json +3 -3
|
@@ -10,42 +10,47 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
10
10
|
function register(context) {
|
|
11
11
|
let fakeVersion = 0;
|
|
12
12
|
return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
|
|
13
|
-
const sourceFile = context.
|
|
14
|
-
if (!sourceFile)
|
|
13
|
+
const sourceFile = context.files.get(uri);
|
|
14
|
+
if (!sourceFile) {
|
|
15
15
|
return;
|
|
16
|
+
}
|
|
16
17
|
let document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
17
18
|
range ??= {
|
|
18
19
|
start: document.positionAt(0),
|
|
19
20
|
end: document.positionAt(document.getText().length),
|
|
20
21
|
};
|
|
21
|
-
if (!sourceFile.
|
|
22
|
+
if (!sourceFile.generated) {
|
|
22
23
|
return onTypeParams
|
|
23
24
|
? (await tryFormat(document, onTypeParams.position, onTypeParams.ch))?.edits
|
|
24
25
|
: (await tryFormat(document, range, undefined))?.edits;
|
|
25
26
|
}
|
|
26
27
|
const initialIndentLanguageId = await context.env.getConfiguration?.('volar.format.initialIndent') ?? { html: true };
|
|
27
28
|
let tempSourceSnapshot = sourceFile.snapshot;
|
|
28
|
-
|
|
29
|
+
let tempVirtualFile = sourceFile.generated.languagePlugin.createVirtualCode(uri, sourceFile.languageId, sourceFile.snapshot, context.files);
|
|
29
30
|
const originalDocument = document;
|
|
30
31
|
let level = 0;
|
|
31
32
|
while (true) {
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
33
|
+
const embeddedCodes = (0, featureWorkers_1.getEmbeddedFilesByLevel)(context, sourceFile.id, tempVirtualFile, level++);
|
|
34
|
+
if (embeddedCodes.length === 0) {
|
|
34
35
|
break;
|
|
36
|
+
}
|
|
35
37
|
let edits = [];
|
|
36
38
|
const toPatchIndent = [];
|
|
37
|
-
for (const
|
|
38
|
-
if (!
|
|
39
|
+
for (const code of embeddedCodes) {
|
|
40
|
+
if (!code.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data))) {
|
|
39
41
|
continue;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
&&
|
|
43
|
-
&&
|
|
44
|
-
|
|
42
|
+
}
|
|
43
|
+
const isCodeBlock = code.mappings.length === 1
|
|
44
|
+
&& code.mappings[0].sourceOffsets.length === 1
|
|
45
|
+
&& code.mappings[0].generatedOffsets[0] === 0
|
|
46
|
+
&& code.mappings[0].lengths[0] === code.snapshot.getLength();
|
|
47
|
+
if (onTypeParams && !isCodeBlock) {
|
|
45
48
|
continue;
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
}
|
|
50
|
+
const docMap = createDocMap(code, uri, sourceFile.languageId, tempSourceSnapshot);
|
|
51
|
+
if (!docMap) {
|
|
48
52
|
continue;
|
|
53
|
+
}
|
|
49
54
|
let embeddedCodeResult;
|
|
50
55
|
if (onTypeParams) {
|
|
51
56
|
const embeddedPosition = docMap.getGeneratedPosition(onTypeParams.position);
|
|
@@ -59,10 +64,11 @@ function register(context) {
|
|
|
59
64
|
end: docMap.virtualFileDocument.positionAt(docMap.virtualFileDocument.getText().length),
|
|
60
65
|
});
|
|
61
66
|
}
|
|
62
|
-
if (!embeddedCodeResult)
|
|
67
|
+
if (!embeddedCodeResult) {
|
|
63
68
|
continue;
|
|
69
|
+
}
|
|
64
70
|
toPatchIndent.push({
|
|
65
|
-
|
|
71
|
+
virtualCodeId: code.id,
|
|
66
72
|
isCodeBlock,
|
|
67
73
|
service: embeddedCodeResult.service[1],
|
|
68
74
|
});
|
|
@@ -81,7 +87,7 @@ function register(context) {
|
|
|
81
87
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
82
88
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
83
89
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
84
|
-
sourceFile.
|
|
90
|
+
tempVirtualFile = sourceFile.generated.languagePlugin.updateVirtualCode(uri, tempVirtualFile, tempSourceSnapshot, context.files);
|
|
85
91
|
}
|
|
86
92
|
if (level > 1) {
|
|
87
93
|
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
@@ -94,20 +100,22 @@ function register(context) {
|
|
|
94
100
|
}
|
|
95
101
|
}
|
|
96
102
|
for (const item of toPatchIndent) {
|
|
97
|
-
let
|
|
98
|
-
for (const file of (0, language_core_1.
|
|
99
|
-
if (file.
|
|
100
|
-
|
|
103
|
+
let virtualCode;
|
|
104
|
+
for (const file of (0, language_core_1.forEachEmbeddedCode)(tempVirtualFile)) {
|
|
105
|
+
if (file.id === item.virtualCodeId) {
|
|
106
|
+
virtualCode = file;
|
|
101
107
|
break;
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
|
-
const docMap = createDocMap(
|
|
105
|
-
if (!docMap)
|
|
110
|
+
const docMap = createDocMap(virtualCode, uri, sourceFile.languageId, tempSourceSnapshot);
|
|
111
|
+
if (!docMap) {
|
|
106
112
|
continue;
|
|
113
|
+
}
|
|
107
114
|
const indentSensitiveLines = new Set();
|
|
108
115
|
for (const service of item.service.provideFormattingIndentSensitiveLines ? [item.service] : context.services.map(service => service[1])) {
|
|
109
|
-
if (token.isCancellationRequested)
|
|
116
|
+
if (token.isCancellationRequested) {
|
|
110
117
|
break;
|
|
118
|
+
}
|
|
111
119
|
if (service.provideFormattingIndentSensitiveLines) {
|
|
112
120
|
const lines = await service.provideFormattingIndentSensitiveLines(docMap.virtualFileDocument, token);
|
|
113
121
|
if (lines) {
|
|
@@ -139,13 +147,14 @@ function register(context) {
|
|
|
139
147
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
140
148
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
141
149
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
142
|
-
sourceFile.
|
|
150
|
+
tempVirtualFile = sourceFile.generated.languagePlugin.updateVirtualCode(uri, tempVirtualFile, tempSourceSnapshot, context.files);
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
}
|
|
147
|
-
if (document.getText() === originalDocument.getText())
|
|
155
|
+
if (document.getText() === originalDocument.getText()) {
|
|
148
156
|
return;
|
|
157
|
+
}
|
|
149
158
|
const editRange = {
|
|
150
159
|
start: originalDocument.positionAt(0),
|
|
151
160
|
end: originalDocument.positionAt(originalDocument.getText().length),
|
|
@@ -161,8 +170,9 @@ function register(context) {
|
|
|
161
170
|
if (context.disabledServicePlugins.has(service[1])) {
|
|
162
171
|
continue;
|
|
163
172
|
}
|
|
164
|
-
if (token.isCancellationRequested)
|
|
173
|
+
if (token.isCancellationRequested) {
|
|
165
174
|
break;
|
|
175
|
+
}
|
|
166
176
|
let edits;
|
|
167
177
|
try {
|
|
168
178
|
if (ch !== undefined && 'line' in formatRange && 'character' in formatRange) {
|
|
@@ -177,8 +187,9 @@ function register(context) {
|
|
|
177
187
|
catch (err) {
|
|
178
188
|
console.warn(err);
|
|
179
189
|
}
|
|
180
|
-
if (!edits)
|
|
190
|
+
if (!edits) {
|
|
181
191
|
continue;
|
|
192
|
+
}
|
|
182
193
|
return {
|
|
183
194
|
service,
|
|
184
195
|
edits,
|
|
@@ -186,16 +197,16 @@ function register(context) {
|
|
|
186
197
|
}
|
|
187
198
|
}
|
|
188
199
|
};
|
|
189
|
-
function createDocMap(file,
|
|
190
|
-
const maps = (0, language_core_1.
|
|
191
|
-
if (!
|
|
192
|
-
return [
|
|
200
|
+
function createDocMap(file, sourceFileUri, sourceLanguageId, _sourceSnapshot) {
|
|
201
|
+
const maps = (0, language_core_1.updateVirtualCodeMaps)(file, sourceFileUri2 => {
|
|
202
|
+
if (!sourceFileUri2) {
|
|
203
|
+
return [sourceFileUri, _sourceSnapshot];
|
|
193
204
|
}
|
|
194
205
|
});
|
|
195
|
-
if (maps.has(
|
|
196
|
-
const map = maps.get(
|
|
206
|
+
if (maps.has(sourceFileUri) && maps.get(sourceFileUri)[0] === _sourceSnapshot) {
|
|
207
|
+
const map = maps.get(sourceFileUri);
|
|
197
208
|
const version = fakeVersion++;
|
|
198
|
-
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(
|
|
209
|
+
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(sourceFileUri, sourceLanguageId ?? (0, language_core_1.resolveCommonLanguageId)(sourceFileUri), version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.documents.getVirtualCodeUri(sourceFileUri, file.id), file.languageId, version, file.snapshot.getText(0, file.snapshot.getLength())), map[1]);
|
|
199
210
|
}
|
|
200
211
|
}
|
|
201
212
|
}
|
|
@@ -214,8 +225,9 @@ function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
|
214
225
|
const baseIndent = firstLineIndent + initialIndent;
|
|
215
226
|
let lineOffset = lines[0].length + 1;
|
|
216
227
|
let insertedFinalNewLine = false;
|
|
217
|
-
if (!text.trim())
|
|
228
|
+
if (!text.trim()) {
|
|
218
229
|
continue;
|
|
230
|
+
}
|
|
219
231
|
if (isCodeBlock && text.trimStart().length === text.length) {
|
|
220
232
|
indentTextEdits.push({
|
|
221
233
|
newText: '\n' + baseIndent,
|
|
@@ -17,21 +17,24 @@ function register(context) {
|
|
|
17
17
|
await withMirrors(document, position);
|
|
18
18
|
return result;
|
|
19
19
|
async function withMirrors(document, position) {
|
|
20
|
-
if (!service[1].provideDocumentHighlights)
|
|
20
|
+
if (!service[1].provideDocumentHighlights) {
|
|
21
21
|
return;
|
|
22
|
-
|
|
22
|
+
}
|
|
23
|
+
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) {
|
|
23
24
|
return;
|
|
25
|
+
}
|
|
24
26
|
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
|
25
27
|
const references = await service[1].provideDocumentHighlights(document, position, token) ?? [];
|
|
26
28
|
for (const reference of references) {
|
|
27
29
|
let foundMirrorPosition = false;
|
|
28
30
|
recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
|
|
29
|
-
const [
|
|
30
|
-
const mirrorMap =
|
|
31
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(document.uri);
|
|
32
|
+
const mirrorMap = virtualCode ? context.documents.getLinkedCodeMap(virtualCode) : undefined;
|
|
31
33
|
if (mirrorMap) {
|
|
32
34
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(reference.range.start)) {
|
|
33
|
-
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } }))
|
|
35
|
+
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
34
36
|
continue;
|
|
37
|
+
}
|
|
35
38
|
foundMirrorPosition = true;
|
|
36
39
|
await withMirrors(mirrorMap.document, linkedPos);
|
|
37
40
|
}
|
|
@@ -43,8 +46,9 @@ function register(context) {
|
|
|
43
46
|
}
|
|
44
47
|
}, (data, map) => data
|
|
45
48
|
.map(highlight => {
|
|
46
|
-
if (!map)
|
|
49
|
+
if (!map) {
|
|
47
50
|
return highlight;
|
|
51
|
+
}
|
|
48
52
|
const range = map.getSourceRange(highlight.range, language_core_1.isHighlightEnabled);
|
|
49
53
|
if (range) {
|
|
50
54
|
return {
|
|
@@ -8,9 +8,10 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
8
8
|
const language_core_1 = require("@volar/language-core");
|
|
9
9
|
function register(context) {
|
|
10
10
|
return async (uri, range, legend, token = cancellation_1.NoneCancellationToken, _reportProgress) => {
|
|
11
|
-
const sourceFile = context.
|
|
12
|
-
if (!sourceFile)
|
|
11
|
+
const sourceFile = context.files.get(uri);
|
|
12
|
+
if (!sourceFile) {
|
|
13
13
|
return;
|
|
14
|
+
}
|
|
14
15
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
15
16
|
if (!range) {
|
|
16
17
|
range = {
|
|
@@ -48,8 +49,9 @@ function register(context) {
|
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
}, (service, document, range) => {
|
|
51
|
-
if (token?.isCancellationRequested)
|
|
52
|
+
if (token?.isCancellationRequested) {
|
|
52
53
|
return;
|
|
54
|
+
}
|
|
53
55
|
return service[1].provideDocumentSemanticTokens?.(document, range, legend, token);
|
|
54
56
|
}, (tokens, map) => {
|
|
55
57
|
if (!map) {
|
|
@@ -23,8 +23,9 @@ function register(context) {
|
|
|
23
23
|
}, results => {
|
|
24
24
|
for (let i = 0; i < results.length; i++) {
|
|
25
25
|
for (let j = 0; j < results.length; j++) {
|
|
26
|
-
if (i === j)
|
|
26
|
+
if (i === j) {
|
|
27
27
|
continue;
|
|
28
|
+
}
|
|
28
29
|
results[i] = results[i].filter(child => {
|
|
29
30
|
for (const parent of results[j]) {
|
|
30
31
|
if ((0, common_1.isInsideRange)(parent.range, child.range)) {
|
|
@@ -13,13 +13,13 @@ function register(context) {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
return await service[1].provideFileReferences?.(document, token) ?? [];
|
|
16
|
-
},
|
|
16
|
+
}, data => data
|
|
17
17
|
.map(reference => {
|
|
18
|
-
const [
|
|
19
|
-
if (!
|
|
18
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(reference.uri);
|
|
19
|
+
if (!virtualCode) {
|
|
20
20
|
return reference;
|
|
21
21
|
}
|
|
22
|
-
for (const map of context.documents.getMaps(
|
|
22
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
23
23
|
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
|
|
24
24
|
if (range) {
|
|
25
25
|
reference.uri = map.sourceFileDocument.uri;
|
|
@@ -3,32 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.register = void 0;
|
|
4
4
|
const transform_1 = require("../utils/transform");
|
|
5
5
|
const dedupe = require("../utils/dedupe");
|
|
6
|
-
const language_core_1 = require("@volar/language-core");
|
|
7
6
|
const cancellation_1 = require("../utils/cancellation");
|
|
8
7
|
function register(context) {
|
|
9
8
|
return async (oldUri, newUri, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
-
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(oldUri));
|
|
11
|
-
if (sourceFile?.virtualFile) {
|
|
12
|
-
let tsExt;
|
|
13
|
-
for (const virtualFile of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
14
|
-
if (virtualFile.typescript && virtualFile.fileName.substring(sourceFile.fileName.length).match(/^\.(js|ts)x?$/)) {
|
|
15
|
-
tsExt = virtualFile.fileName.substring(virtualFile.fileName.lastIndexOf('.'));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (!tsExt) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
oldUri += tsExt;
|
|
22
|
-
newUri += tsExt;
|
|
23
|
-
}
|
|
24
9
|
for (const service of context.services) {
|
|
25
10
|
if (context.disabledServicePlugins.has(service[1])) {
|
|
26
11
|
continue;
|
|
27
12
|
}
|
|
28
|
-
if (token.isCancellationRequested)
|
|
13
|
+
if (token.isCancellationRequested) {
|
|
29
14
|
break;
|
|
30
|
-
|
|
15
|
+
}
|
|
16
|
+
if (!service[1].provideFileRenameEdits) {
|
|
31
17
|
continue;
|
|
18
|
+
}
|
|
32
19
|
const workspaceEdit = await service[1].provideFileRenameEdits(oldUri, newUri, token);
|
|
33
20
|
if (workspaceEdit) {
|
|
34
21
|
const result = (0, transform_1.transformWorkspaceEdit)(workspaceEdit, context, 'fileName');
|
|
@@ -8,9 +8,10 @@ const transform_1 = require("../utils/transform");
|
|
|
8
8
|
const language_core_1 = require("@volar/language-core");
|
|
9
9
|
function register(context) {
|
|
10
10
|
return async (uri, range, token = cancellation_1.NoneCancellationToken) => {
|
|
11
|
-
const sourceFile = context.
|
|
12
|
-
if (!sourceFile)
|
|
11
|
+
const sourceFile = context.files.get(uri);
|
|
12
|
+
if (!sourceFile) {
|
|
13
13
|
return;
|
|
14
|
+
}
|
|
14
15
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
15
16
|
const offsetRange = {
|
|
16
17
|
start: document.offsetAt(range.start),
|
|
@@ -12,8 +12,9 @@ function register(context) {
|
|
|
12
12
|
yield pos;
|
|
13
13
|
}
|
|
14
14
|
}, (service, document, position) => {
|
|
15
|
-
if (token.isCancellationRequested)
|
|
15
|
+
if (token.isCancellationRequested) {
|
|
16
16
|
return;
|
|
17
|
+
}
|
|
17
18
|
return service[1].provideLinkedEditingRanges?.(document, position, token);
|
|
18
19
|
}, (ranges, map) => {
|
|
19
20
|
if (!map) {
|
|
@@ -8,28 +8,32 @@ const language_core_1 = require("@volar/language-core");
|
|
|
8
8
|
function register(context) {
|
|
9
9
|
return (uri, position, referenceContext, token = cancellation_1.NoneCancellationToken) => {
|
|
10
10
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, map => map.getGeneratedPositions(position, language_core_1.isReferencesEnabled), async (service, document, position) => {
|
|
11
|
-
if (token.isCancellationRequested)
|
|
11
|
+
if (token.isCancellationRequested) {
|
|
12
12
|
return;
|
|
13
|
+
}
|
|
13
14
|
const recursiveChecker = dedupe.createLocationSet();
|
|
14
15
|
const result = [];
|
|
15
16
|
await withMirrors(document, position);
|
|
16
17
|
return result;
|
|
17
18
|
async function withMirrors(document, position) {
|
|
18
|
-
if (!service[1].provideReferences)
|
|
19
|
+
if (!service[1].provideReferences) {
|
|
19
20
|
return;
|
|
20
|
-
|
|
21
|
+
}
|
|
22
|
+
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) {
|
|
21
23
|
return;
|
|
24
|
+
}
|
|
22
25
|
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
|
23
26
|
const references = await service[1].provideReferences(document, position, referenceContext, token) ?? [];
|
|
24
27
|
for (const reference of references) {
|
|
25
28
|
let foundMirrorPosition = false;
|
|
26
29
|
recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } });
|
|
27
|
-
const [
|
|
28
|
-
const mirrorMap =
|
|
30
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(reference.uri);
|
|
31
|
+
const mirrorMap = virtualCode ? context.documents.getLinkedCodeMap(virtualCode) : undefined;
|
|
29
32
|
if (mirrorMap) {
|
|
30
33
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(reference.range.start)) {
|
|
31
|
-
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } }))
|
|
34
|
+
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
32
35
|
continue;
|
|
36
|
+
}
|
|
33
37
|
foundMirrorPosition = true;
|
|
34
38
|
await withMirrors(mirrorMap.document, linkedPos);
|
|
35
39
|
}
|
|
@@ -39,12 +43,12 @@ function register(context) {
|
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
|
-
},
|
|
46
|
+
}, data => {
|
|
43
47
|
const results = [];
|
|
44
48
|
for (const reference of data) {
|
|
45
|
-
const [
|
|
46
|
-
if (
|
|
47
|
-
for (const map of context.documents.getMaps(
|
|
49
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(reference.uri);
|
|
50
|
+
if (virtualCode) {
|
|
51
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
48
52
|
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
|
|
49
53
|
if (range) {
|
|
50
54
|
results.push({
|
|
@@ -29,37 +29,44 @@ function register(context) {
|
|
|
29
29
|
await withMirrors(document, params.position, params.newName);
|
|
30
30
|
return result;
|
|
31
31
|
async function withMirrors(document, position, newName) {
|
|
32
|
-
if (!service[1].provideRenameEdits)
|
|
32
|
+
if (!service[1].provideRenameEdits) {
|
|
33
33
|
return;
|
|
34
|
-
|
|
34
|
+
}
|
|
35
|
+
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) {
|
|
35
36
|
return;
|
|
37
|
+
}
|
|
36
38
|
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
|
37
39
|
const workspaceEdit = await service[1].provideRenameEdits(document, position, newName, token);
|
|
38
|
-
if (!workspaceEdit)
|
|
40
|
+
if (!workspaceEdit) {
|
|
39
41
|
return;
|
|
40
|
-
|
|
42
|
+
}
|
|
43
|
+
if (!result) {
|
|
41
44
|
result = {};
|
|
45
|
+
}
|
|
42
46
|
if (workspaceEdit.changes) {
|
|
43
47
|
for (const editUri in workspaceEdit.changes) {
|
|
44
48
|
const textEdits = workspaceEdit.changes[editUri];
|
|
45
49
|
for (const textEdit of textEdits) {
|
|
46
50
|
let foundMirrorPosition = false;
|
|
47
51
|
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
|
|
48
|
-
const [
|
|
49
|
-
const mirrorMap =
|
|
52
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(editUri);
|
|
53
|
+
const mirrorMap = virtualCode ? context.documents.getLinkedCodeMap(virtualCode) : undefined;
|
|
50
54
|
if (mirrorMap) {
|
|
51
55
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(textEdit.range.start)) {
|
|
52
|
-
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } }))
|
|
56
|
+
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
53
57
|
continue;
|
|
58
|
+
}
|
|
54
59
|
foundMirrorPosition = true;
|
|
55
60
|
await withMirrors(mirrorMap.document, linkedPos, newName);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
if (!foundMirrorPosition) {
|
|
59
|
-
if (!result.changes)
|
|
64
|
+
if (!result.changes) {
|
|
60
65
|
result.changes = {};
|
|
61
|
-
|
|
66
|
+
}
|
|
67
|
+
if (!result.changes[editUri]) {
|
|
62
68
|
result.changes[editUri] = [];
|
|
69
|
+
}
|
|
63
70
|
result.changes[editUri].push(textEdit);
|
|
64
71
|
}
|
|
65
72
|
}
|
|
@@ -67,20 +74,22 @@ function register(context) {
|
|
|
67
74
|
}
|
|
68
75
|
if (workspaceEdit.changeAnnotations) {
|
|
69
76
|
for (const uri in workspaceEdit.changeAnnotations) {
|
|
70
|
-
if (!result.changeAnnotations)
|
|
77
|
+
if (!result.changeAnnotations) {
|
|
71
78
|
result.changeAnnotations = {};
|
|
79
|
+
}
|
|
72
80
|
result.changeAnnotations[uri] = workspaceEdit.changeAnnotations[uri];
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
if (workspaceEdit.documentChanges) {
|
|
76
|
-
if (!result.documentChanges)
|
|
84
|
+
if (!result.documentChanges) {
|
|
77
85
|
result.documentChanges = [];
|
|
86
|
+
}
|
|
78
87
|
result.documentChanges = result.documentChanges.concat(workspaceEdit.documentChanges);
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
|
-
},
|
|
90
|
+
}, data => {
|
|
82
91
|
return (0, transform_1.transformWorkspaceEdit)(data, context, 'rename');
|
|
83
|
-
},
|
|
92
|
+
}, workspaceEdits => {
|
|
84
93
|
const mainEdit = workspaceEdits[0];
|
|
85
94
|
const otherEdits = workspaceEdits.slice(1);
|
|
86
95
|
mergeWorkspaceEdits(mainEdit, ...otherEdits);
|
|
@@ -16,8 +16,9 @@ function register(context) {
|
|
|
16
16
|
yield result;
|
|
17
17
|
}
|
|
18
18
|
}, (service, document, positions) => {
|
|
19
|
-
if (token.isCancellationRequested)
|
|
19
|
+
if (token.isCancellationRequested) {
|
|
20
20
|
return;
|
|
21
|
+
}
|
|
21
22
|
return service[1].provideSelectionRanges?.(document, positions, token);
|
|
22
23
|
}, (data, map) => {
|
|
23
24
|
if (!map) {
|
|
@@ -22,9 +22,9 @@ function register(context) {
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
const symbols = embeddedSymbols.map(symbol => (0, transform_1.transformWorkspaceSymbol)(symbol, loc => {
|
|
25
|
-
const [
|
|
26
|
-
if (
|
|
27
|
-
for (const map of context.documents.getMaps(
|
|
25
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(loc.uri);
|
|
26
|
+
if (virtualCode) {
|
|
27
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
28
28
|
const range = map.getSourceRange(loc.range);
|
|
29
29
|
if (range) {
|
|
30
30
|
return { uri: map.sourceFileDocument.uri, range };
|
|
@@ -8,8 +8,9 @@ function register(context) {
|
|
|
8
8
|
const data = item.data;
|
|
9
9
|
if (data) {
|
|
10
10
|
const service = context.services[data.serviceIndex];
|
|
11
|
-
if (!service[1].resolveCodeAction)
|
|
11
|
+
if (!service[1].resolveCodeAction) {
|
|
12
12
|
return item;
|
|
13
|
+
}
|
|
13
14
|
Object.assign(item, data.original);
|
|
14
15
|
item = await service[1].resolveCodeAction(item, token);
|
|
15
16
|
item = service[1].transformCodeAction?.(item)
|
|
@@ -9,8 +9,9 @@ function register(context) {
|
|
|
9
9
|
const data = item.data;
|
|
10
10
|
if (data?.kind === 'normal') {
|
|
11
11
|
const service = context.services[data.serviceIndex];
|
|
12
|
-
if (!service[1].resolveCodeLens)
|
|
12
|
+
if (!service[1].resolveCodeLens) {
|
|
13
13
|
return item;
|
|
14
|
+
}
|
|
14
15
|
Object.assign(item, data.original);
|
|
15
16
|
item = await service[1].resolveCodeLens(item, token);
|
|
16
17
|
// item.range already transformed in codeLens request
|
|
@@ -8,13 +8,14 @@ function register(context) {
|
|
|
8
8
|
const data = item.data;
|
|
9
9
|
if (data) {
|
|
10
10
|
const service = context.services[data.serviceIndex];
|
|
11
|
-
if (!service[1].resolveCompletionItem)
|
|
11
|
+
if (!service[1].resolveCompletionItem) {
|
|
12
12
|
return item;
|
|
13
|
+
}
|
|
13
14
|
item = Object.assign(item, data.original);
|
|
14
15
|
if (data.virtualDocumentUri) {
|
|
15
|
-
const [
|
|
16
|
-
if (
|
|
17
|
-
for (const map of context.documents.getMaps(
|
|
16
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(data.virtualDocumentUri);
|
|
17
|
+
if (virtualCode) {
|
|
18
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
18
19
|
item = await service[1].resolveCompletionItem(item, token);
|
|
19
20
|
item = service[1].transformCompletionItem?.(item) ?? (0, transform_1.transformCompletionItem)(item, embeddedRange => map.getSourceRange(embeddedRange), map.virtualFileDocument);
|
|
20
21
|
}
|
|
@@ -9,8 +9,9 @@ function register(context) {
|
|
|
9
9
|
const data = item.data;
|
|
10
10
|
if (data) {
|
|
11
11
|
const service = context.services[data.serviceIndex];
|
|
12
|
-
if (!service[1].resolveDocumentLink)
|
|
12
|
+
if (!service[1].resolveDocumentLink) {
|
|
13
13
|
return item;
|
|
14
|
+
}
|
|
14
15
|
Object.assign(item, data.original);
|
|
15
16
|
item = await service[1].resolveDocumentLink(item, token);
|
|
16
17
|
if (item.target) {
|
|
@@ -24,9 +25,9 @@ exports.register = register;
|
|
|
24
25
|
function transformDocumentLinkTarget(target, context) {
|
|
25
26
|
const targetUri = vscode_uri_1.URI.parse(target);
|
|
26
27
|
const clearUri = targetUri.with({ fragment: '' }).toString();
|
|
27
|
-
const [
|
|
28
|
-
if (
|
|
29
|
-
for (const map of context.documents.getMaps(
|
|
28
|
+
const [virtualCode] = context.documents.getVirtualCodeByUri(clearUri);
|
|
29
|
+
if (virtualCode) {
|
|
30
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
30
31
|
if (!map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
|
|
31
32
|
continue;
|
|
32
33
|
}
|
|
@@ -7,8 +7,9 @@ function register(context) {
|
|
|
7
7
|
const data = item.data;
|
|
8
8
|
if (data) {
|
|
9
9
|
const service = context.services[data.serviceIndex];
|
|
10
|
-
if (!service[1].resolveInlayHint)
|
|
10
|
+
if (!service[1].resolveInlayHint) {
|
|
11
11
|
return item;
|
|
12
|
+
}
|
|
12
13
|
Object.assign(item, data.original);
|
|
13
14
|
item = await service[1].resolveInlayHint(item, token);
|
|
14
15
|
}
|
package/lib/languageService.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type LanguageContext } from '@volar/language-core';
|
|
2
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
3
|
import type { ServiceContext, ServiceEnvironment, ServicePlugin } from './types';
|
|
4
4
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
5
|
-
export declare function createLanguageService(
|
|
5
|
+
export declare function createLanguageService(languageContext: LanguageContext, servicePlugins: ServicePlugin[], env: ServiceEnvironment): {
|
|
6
6
|
getTriggerCharacters: () => string[];
|
|
7
7
|
getAutoFormatTriggerCharacters: () => string[];
|
|
8
8
|
getSignatureHelpTriggerCharacters: () => string[];
|