@volar/language-service 2.0.0-alpha.8 → 2.0.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/lib/documents.d.ts +7 -7
- 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 +46 -24
- package/lib/features/provideDefinition.js +13 -8
- package/lib/features/provideDiagnostics.js +9 -5
- package/lib/features/provideDocumentDropEdits.js +1 -1
- package/lib/features/provideDocumentFormattingEdits.js +55 -51
- 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 +7 -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 +6 -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 +9 -5
- package/lib/types.d.ts +17 -18
- package/lib/utils/common.d.ts +1 -1
- package/lib/utils/common.js +10 -5
- package/lib/utils/dedupe.d.ts +1 -1
- package/lib/utils/featureWorkers.d.ts +3 -2
- package/lib/utils/featureWorkers.js +44 -17
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.js +26 -21
- package/package.json +3 -3
|
@@ -3,48 +3,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.register = void 0;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const common_1 = require("../utils/common");
|
|
7
|
-
const cancellation_1 = require("../utils/cancellation");
|
|
8
6
|
const documents_1 = require("../documents");
|
|
7
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
8
|
+
const common_1 = require("../utils/common");
|
|
9
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
9
10
|
function register(context) {
|
|
10
11
|
let fakeVersion = 0;
|
|
11
12
|
return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
|
|
12
|
-
const sourceFile = context.language.files.
|
|
13
|
-
if (!sourceFile)
|
|
13
|
+
const sourceFile = context.language.files.get(uri);
|
|
14
|
+
if (!sourceFile) {
|
|
14
15
|
return;
|
|
16
|
+
}
|
|
15
17
|
let document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
16
18
|
range ??= {
|
|
17
19
|
start: document.positionAt(0),
|
|
18
20
|
end: document.positionAt(document.getText().length),
|
|
19
21
|
};
|
|
20
|
-
if (!sourceFile.
|
|
22
|
+
if (!sourceFile.generated) {
|
|
21
23
|
return onTypeParams
|
|
22
24
|
? (await tryFormat(document, onTypeParams.position, onTypeParams.ch))?.edits
|
|
23
25
|
: (await tryFormat(document, range, undefined))?.edits;
|
|
24
26
|
}
|
|
25
27
|
const initialIndentLanguageId = await context.env.getConfiguration?.('volar.format.initialIndent') ?? { html: true };
|
|
26
28
|
let tempSourceSnapshot = sourceFile.snapshot;
|
|
27
|
-
|
|
29
|
+
let tempVirtualFile = sourceFile.generated.languagePlugin.createVirtualCode(uri, sourceFile.languageId, sourceFile.snapshot, context.language.files);
|
|
28
30
|
const originalDocument = document;
|
|
29
31
|
let level = 0;
|
|
30
32
|
while (true) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
+
const embeddedCodes = (0, featureWorkers_1.getEmbeddedFilesByLevel)(context, sourceFile.id, tempVirtualFile, level++);
|
|
34
|
+
if (embeddedCodes.length === 0) {
|
|
33
35
|
break;
|
|
36
|
+
}
|
|
34
37
|
let edits = [];
|
|
35
38
|
const toPatchIndent = [];
|
|
36
|
-
for (const
|
|
37
|
-
if (!
|
|
39
|
+
for (const code of embeddedCodes) {
|
|
40
|
+
if (!code.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data))) {
|
|
38
41
|
continue;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
&&
|
|
42
|
-
&&
|
|
43
|
-
|
|
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) {
|
|
44
48
|
continue;
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
}
|
|
50
|
+
const docMap = createDocMap(code, uri, sourceFile.languageId, tempSourceSnapshot);
|
|
51
|
+
if (!docMap) {
|
|
47
52
|
continue;
|
|
53
|
+
}
|
|
48
54
|
let embeddedCodeResult;
|
|
49
55
|
if (onTypeParams) {
|
|
50
56
|
const embeddedPosition = docMap.getGeneratedPosition(onTypeParams.position);
|
|
@@ -58,10 +64,11 @@ function register(context) {
|
|
|
58
64
|
end: docMap.virtualFileDocument.positionAt(docMap.virtualFileDocument.getText().length),
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
|
-
if (!embeddedCodeResult)
|
|
67
|
+
if (!embeddedCodeResult) {
|
|
62
68
|
continue;
|
|
69
|
+
}
|
|
63
70
|
toPatchIndent.push({
|
|
64
|
-
|
|
71
|
+
virtualCodeId: code.id,
|
|
65
72
|
isCodeBlock,
|
|
66
73
|
service: embeddedCodeResult.service[1],
|
|
67
74
|
});
|
|
@@ -80,7 +87,7 @@ function register(context) {
|
|
|
80
87
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
81
88
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
82
89
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
83
|
-
sourceFile.
|
|
90
|
+
tempVirtualFile = sourceFile.generated.languagePlugin.updateVirtualCode(uri, tempVirtualFile, tempSourceSnapshot, context.language.files);
|
|
84
91
|
}
|
|
85
92
|
if (level > 1) {
|
|
86
93
|
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
@@ -93,20 +100,22 @@ function register(context) {
|
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
for (const item of toPatchIndent) {
|
|
96
|
-
let
|
|
97
|
-
for (const file of (0, language_core_1.
|
|
98
|
-
if (file.
|
|
99
|
-
|
|
103
|
+
let virtualCode;
|
|
104
|
+
for (const file of (0, language_core_1.forEachEmbeddedCode)(tempVirtualFile)) {
|
|
105
|
+
if (file.id === item.virtualCodeId) {
|
|
106
|
+
virtualCode = file;
|
|
100
107
|
break;
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
|
-
const docMap = createDocMap(
|
|
104
|
-
if (!docMap)
|
|
110
|
+
const docMap = createDocMap(virtualCode, uri, sourceFile.languageId, tempSourceSnapshot);
|
|
111
|
+
if (!docMap) {
|
|
105
112
|
continue;
|
|
113
|
+
}
|
|
106
114
|
const indentSensitiveLines = new Set();
|
|
107
115
|
for (const service of item.service.provideFormattingIndentSensitiveLines ? [item.service] : context.services.map(service => service[1])) {
|
|
108
|
-
if (token.isCancellationRequested)
|
|
116
|
+
if (token.isCancellationRequested) {
|
|
109
117
|
break;
|
|
118
|
+
}
|
|
110
119
|
if (service.provideFormattingIndentSensitiveLines) {
|
|
111
120
|
const lines = await service.provideFormattingIndentSensitiveLines(docMap.virtualFileDocument, token);
|
|
112
121
|
if (lines) {
|
|
@@ -138,13 +147,14 @@ function register(context) {
|
|
|
138
147
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
139
148
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
140
149
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
141
|
-
sourceFile.
|
|
150
|
+
tempVirtualFile = sourceFile.generated.languagePlugin.updateVirtualCode(uri, tempVirtualFile, tempSourceSnapshot, context.language.files);
|
|
142
151
|
}
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
|
-
if (document.getText() === originalDocument.getText())
|
|
155
|
+
if (document.getText() === originalDocument.getText()) {
|
|
147
156
|
return;
|
|
157
|
+
}
|
|
148
158
|
const editRange = {
|
|
149
159
|
start: originalDocument.positionAt(0),
|
|
150
160
|
end: originalDocument.positionAt(originalDocument.getText().length),
|
|
@@ -154,23 +164,15 @@ function register(context) {
|
|
|
154
164
|
newText: document.getText(),
|
|
155
165
|
};
|
|
156
166
|
return [textEdit];
|
|
157
|
-
function getEmbeddedFilesByLevel(rootFile, level) {
|
|
158
|
-
const embeddedFilesByLevel = [[rootFile]];
|
|
159
|
-
while (true) {
|
|
160
|
-
if (embeddedFilesByLevel.length > level)
|
|
161
|
-
return embeddedFilesByLevel[level];
|
|
162
|
-
let nextLevel = [];
|
|
163
|
-
for (const file of embeddedFilesByLevel[embeddedFilesByLevel.length - 1]) {
|
|
164
|
-
nextLevel = nextLevel.concat(file.embeddedFiles);
|
|
165
|
-
}
|
|
166
|
-
embeddedFilesByLevel.push(nextLevel);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
167
|
async function tryFormat(document, range, ch) {
|
|
170
168
|
let formatRange = range;
|
|
171
169
|
for (const service of context.services) {
|
|
172
|
-
if (
|
|
170
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (token.isCancellationRequested) {
|
|
173
174
|
break;
|
|
175
|
+
}
|
|
174
176
|
let edits;
|
|
175
177
|
try {
|
|
176
178
|
if (ch !== undefined && 'line' in formatRange && 'character' in formatRange) {
|
|
@@ -185,8 +187,9 @@ function register(context) {
|
|
|
185
187
|
catch (err) {
|
|
186
188
|
console.warn(err);
|
|
187
189
|
}
|
|
188
|
-
if (!edits)
|
|
190
|
+
if (!edits) {
|
|
189
191
|
continue;
|
|
192
|
+
}
|
|
190
193
|
return {
|
|
191
194
|
service,
|
|
192
195
|
edits,
|
|
@@ -194,16 +197,16 @@ function register(context) {
|
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
199
|
};
|
|
197
|
-
function createDocMap(file,
|
|
198
|
-
const maps = (0, language_core_1.
|
|
199
|
-
if (!
|
|
200
|
-
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];
|
|
201
204
|
}
|
|
202
205
|
});
|
|
203
|
-
if (maps.has(
|
|
204
|
-
const map = maps.get(
|
|
206
|
+
if (maps.has(sourceFileUri) && maps.get(sourceFileUri)[0] === _sourceSnapshot) {
|
|
207
|
+
const map = maps.get(sourceFileUri);
|
|
205
208
|
const version = fakeVersion++;
|
|
206
|
-
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]);
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
}
|
|
@@ -222,8 +225,9 @@ function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
|
222
225
|
const baseIndent = firstLineIndent + initialIndent;
|
|
223
226
|
let lineOffset = lines[0].length + 1;
|
|
224
227
|
let insertedFinalNewLine = false;
|
|
225
|
-
if (!text.trim())
|
|
228
|
+
if (!text.trim()) {
|
|
226
229
|
continue;
|
|
230
|
+
}
|
|
227
231
|
if (isCodeBlock && text.trimStart().length === text.length) {
|
|
228
232
|
indentTextEdits.push({
|
|
229
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.language.files.
|
|
12
|
-
if (!sourceFile)
|
|
11
|
+
const sourceFile = context.language.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,29 +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
|
-
if (
|
|
10
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (token.isCancellationRequested) {
|
|
26
14
|
break;
|
|
27
|
-
|
|
15
|
+
}
|
|
16
|
+
if (!service[1].provideFileRenameEdits) {
|
|
28
17
|
continue;
|
|
18
|
+
}
|
|
29
19
|
const workspaceEdit = await service[1].provideFileRenameEdits(oldUri, newUri, token);
|
|
30
20
|
if (workspaceEdit) {
|
|
31
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.language.files.
|
|
12
|
-
if (!sourceFile)
|
|
11
|
+
const sourceFile = context.language.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) {
|
|
@@ -8,6 +8,9 @@ function register(context) {
|
|
|
8
8
|
return async (query, token = cancellation_1.NoneCancellationToken) => {
|
|
9
9
|
const symbolsList = [];
|
|
10
10
|
for (const service of context.services) {
|
|
11
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
11
14
|
if (token.isCancellationRequested) {
|
|
12
15
|
break;
|
|
13
16
|
}
|
|
@@ -19,9 +22,9 @@ function register(context) {
|
|
|
19
22
|
continue;
|
|
20
23
|
}
|
|
21
24
|
const symbols = embeddedSymbols.map(symbol => (0, transform_1.transformWorkspaceSymbol)(symbol, loc => {
|
|
22
|
-
const [
|
|
23
|
-
if (
|
|
24
|
-
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)) {
|
|
25
28
|
const range = map.getSourceRange(loc.range);
|
|
26
29
|
if (range) {
|
|
27
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
|
}
|