@volar/language-service 2.3.0-alpha.5 → 2.3.0-alpha.6
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 +2 -2
- package/lib/features/provideCallHierarchyItems.js +13 -11
- package/lib/features/provideCompletionItems.js +22 -21
- package/lib/features/provideDefinition.js +24 -22
- package/lib/features/provideDiagnostics.js +12 -11
- package/lib/features/provideDocumentSymbols.js +1 -1
- package/lib/features/provideFileReferences.js +7 -6
- package/lib/features/provideReferences.js +8 -7
- package/lib/features/provideWorkspaceSymbols.js +5 -4
- package/lib/features/resolveCompletionItem.js +4 -3
- package/lib/languageService.js +7 -8
- package/lib/types.d.ts +2 -2
- package/lib/utils/featureWorkers.d.ts +2 -2
- package/lib/utils/featureWorkers.js +6 -4
- package/lib/utils/transform.js +87 -78
- package/package.json +3 -3
package/lib/documents.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export declare class SourceMapWithDocuments {
|
|
|
5
5
|
sourceDocument: TextDocument;
|
|
6
6
|
embeddedDocument: TextDocument;
|
|
7
7
|
map: SourceMap<CodeInformation>;
|
|
8
|
-
virtuaoCode?: VirtualCode | undefined;
|
|
9
|
-
constructor(sourceDocument: TextDocument, embeddedDocument: TextDocument, map: SourceMap<CodeInformation>, virtuaoCode?: VirtualCode | undefined);
|
|
8
|
+
virtuaoCode?: VirtualCode<unknown> | undefined;
|
|
9
|
+
constructor(sourceDocument: TextDocument, embeddedDocument: TextDocument, map: SourceMap<CodeInformation>, virtuaoCode?: VirtualCode<unknown> | undefined);
|
|
10
10
|
getSourceRange(range: vscode.Range, filter?: (data: CodeInformation) => boolean): vscode.Range | undefined;
|
|
11
11
|
getGeneratedRange(range: vscode.Range, filter?: (data: CodeInformation) => boolean): vscode.Range | undefined;
|
|
12
12
|
getSourceRanges(range: vscode.Range, filter?: (data: CodeInformation) => boolean): Generator<vscode.Range, void, unknown>;
|
|
@@ -125,17 +125,19 @@ function register(context) {
|
|
|
125
125
|
if (!virtualCode) {
|
|
126
126
|
return [tsItem, tsRanges];
|
|
127
127
|
}
|
|
128
|
-
const map
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
129
|
+
let range = map.getSourceRange(tsItem.range);
|
|
130
|
+
if (!range) {
|
|
131
|
+
// TODO: <script> range
|
|
132
|
+
range = {
|
|
133
|
+
start: map.sourceDocument.positionAt(0),
|
|
134
|
+
end: map.sourceDocument.positionAt(map.sourceDocument.getText().length),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const selectionRange = map.getSourceRange(tsItem.selectionRange);
|
|
138
|
+
if (!selectionRange) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
139
141
|
const vueRanges = tsRanges.map(tsRange => map.getSourceRange(tsRange)).filter(common_1.notEmpty);
|
|
140
142
|
const vueItem = {
|
|
141
143
|
...tsItem,
|
|
@@ -30,28 +30,29 @@ function register(context) {
|
|
|
30
30
|
if (!virtualCode) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
const map
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
34
|
+
for (const mapped of map.getGeneratedPositions(position, data => (0, language_core_1.isCompletionEnabled)(data))) {
|
|
35
|
+
if (!cacheData.plugin.provideCompletionItems) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
cacheData.list = await cacheData.plugin.provideCompletionItems(map.embeddedDocument, mapped, completionContext, token);
|
|
39
|
+
if (!cacheData.list) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
for (const item of cacheData.list.items) {
|
|
43
|
+
item.data = {
|
|
44
|
+
uri: uri.toString(),
|
|
45
|
+
original: {
|
|
46
|
+
additionalTextEdits: item.additionalTextEdits,
|
|
47
|
+
textEdit: item.textEdit,
|
|
48
|
+
data: item.data,
|
|
49
|
+
},
|
|
50
|
+
pluginIndex: pluginIndex,
|
|
51
|
+
embeddedDocumentUri: map.embeddedDocument.uri,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
|
|
37
55
|
}
|
|
38
|
-
cacheData.list = await cacheData.plugin.provideCompletionItems(map.embeddedDocument, mapped, completionContext, token);
|
|
39
|
-
if (!cacheData.list) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
for (const item of cacheData.list.items) {
|
|
43
|
-
item.data = {
|
|
44
|
-
uri: uri.toString(),
|
|
45
|
-
original: {
|
|
46
|
-
additionalTextEdits: item.additionalTextEdits,
|
|
47
|
-
textEdit: item.textEdit,
|
|
48
|
-
data: item.data,
|
|
49
|
-
},
|
|
50
|
-
pluginIndex: pluginIndex,
|
|
51
|
-
embeddedDocumentUri: map.embeddedDocument.uri,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
else {
|
|
@@ -65,39 +65,41 @@ function register(context, apiName, isValidPosition) {
|
|
|
65
65
|
}
|
|
66
66
|
link.originSelectionRange = originSelectionRange;
|
|
67
67
|
}
|
|
68
|
+
let foundTargetSelectionRange = false;
|
|
68
69
|
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(link.targetUri));
|
|
69
70
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
70
71
|
const targetVirtualFile = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
71
72
|
if (targetVirtualFile) {
|
|
72
|
-
const targetSourceMap
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
for (const targetSourceMap of context.documents.getMaps(targetVirtualFile)) {
|
|
74
|
+
const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
|
|
75
|
+
if (!targetSelectionRange) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
foundTargetSelectionRange = true;
|
|
75
79
|
let targetRange = targetSourceMap.getSourceRange(link.targetRange);
|
|
76
80
|
link.targetUri = targetSourceMap.sourceDocument.uri;
|
|
77
81
|
// loose range mapping to for template slots, slot properties
|
|
78
82
|
link.targetRange = targetRange ?? targetSelectionRange;
|
|
79
83
|
link.targetSelectionRange = targetSelectionRange;
|
|
80
84
|
}
|
|
81
|
-
|
|
82
|
-
const targetMap
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
return;
|
|
85
|
+
if (apiName === 'provideDefinition' && !foundTargetSelectionRange) {
|
|
86
|
+
for (const targetMap of context.documents.getMaps(targetVirtualFile)) {
|
|
87
|
+
if (targetMap && targetMap.sourceDocument.uri !== uri.toString()) {
|
|
88
|
+
return {
|
|
89
|
+
...link,
|
|
90
|
+
targetUri: targetMap.sourceDocument.uri,
|
|
91
|
+
targetRange: {
|
|
92
|
+
start: { line: 0, character: 0 },
|
|
93
|
+
end: { line: 0, character: 0 },
|
|
94
|
+
},
|
|
95
|
+
targetSelectionRange: {
|
|
96
|
+
start: { line: 0, character: 0 },
|
|
97
|
+
end: { line: 0, character: 0 },
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
100
101
|
}
|
|
102
|
+
return;
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
return link;
|
|
@@ -137,7 +137,7 @@ function register(context) {
|
|
|
137
137
|
errorsUpdated = false;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
function collectErrors() {
|
|
141
141
|
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
142
142
|
}
|
|
143
143
|
async function worker(api, cacheMap, cache) {
|
|
@@ -204,16 +204,17 @@ function register(context) {
|
|
|
204
204
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
205
205
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
206
206
|
if (virtualCode) {
|
|
207
|
-
const map
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
208
|
+
const range = map.getSourceRange(info.location.range, filter);
|
|
209
|
+
if (range) {
|
|
210
|
+
relatedInfos.push({
|
|
211
|
+
location: {
|
|
212
|
+
uri: map.sourceDocument.uri,
|
|
213
|
+
range,
|
|
214
|
+
},
|
|
215
|
+
message: info.message,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
else {
|
|
@@ -8,7 +8,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
8
8
|
const transform_1 = require("../utils/transform");
|
|
9
9
|
function register(context) {
|
|
10
10
|
return (uri, token = cancellation_1.NoneCancellationToken) => {
|
|
11
|
-
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isSymbolsEnabled)(mapping.data)),
|
|
11
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isSymbolsEnabled)(mapping.data)), (plugin, document) => {
|
|
12
12
|
if (token.isCancellationRequested) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
@@ -22,12 +22,13 @@ function register(context) {
|
|
|
22
22
|
if (!virtualCode) {
|
|
23
23
|
return reference;
|
|
24
24
|
}
|
|
25
|
-
const map
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
26
|
+
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
|
|
27
|
+
if (range) {
|
|
28
|
+
reference.uri = map.sourceDocument.uri;
|
|
29
|
+
reference.range = range;
|
|
30
|
+
return reference;
|
|
31
|
+
}
|
|
31
32
|
}
|
|
32
33
|
})
|
|
33
34
|
.filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat()));
|
|
@@ -55,13 +55,14 @@ function register(context) {
|
|
|
55
55
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
56
56
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
57
57
|
if (virtualCode) {
|
|
58
|
-
const map
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
59
|
+
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
|
|
60
|
+
if (range) {
|
|
61
|
+
results.push({
|
|
62
|
+
uri: map.sourceDocument.uri,
|
|
63
|
+
range,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
@@ -27,10 +27,11 @@ function register(context) {
|
|
|
27
27
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
28
28
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
29
29
|
if (virtualCode) {
|
|
30
|
-
const map
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
31
|
+
const range = map.getSourceRange(loc.range);
|
|
32
|
+
if (range) {
|
|
33
|
+
return { uri: map.sourceDocument.uri, range };
|
|
34
|
+
}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
else {
|
|
@@ -18,9 +18,10 @@ function register(context) {
|
|
|
18
18
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
19
19
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
20
20
|
if (virtualCode) {
|
|
21
|
-
const map
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
22
|
+
item = await plugin[1].resolveCompletionItem(item, token);
|
|
23
|
+
item = plugin[1].transformCompletionItem?.(item) ?? (0, transform_1.transformCompletionItem)(item, embeddedRange => map.getSourceRange(embeddedRange), map.embeddedDocument, context);
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
else {
|
package/lib/languageService.js
CHANGED
|
@@ -59,15 +59,14 @@ function createLanguageService(language, plugins, env) {
|
|
|
59
59
|
}
|
|
60
60
|
return map.get(uri);
|
|
61
61
|
},
|
|
62
|
-
|
|
63
|
-
const map
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
map2DocMap.
|
|
62
|
+
*getMaps(virtualCode) {
|
|
63
|
+
for (const [uri, snapshot, map] of context.language.maps.forEach(virtualCode)) {
|
|
64
|
+
if (!map2DocMap.has(map)) {
|
|
65
|
+
const embeddedUri = context.encodeEmbeddedDocumentUri(uri, virtualCode.id);
|
|
66
|
+
map2DocMap.set(map, new documents_1.SourceMapWithDocuments(this.get(uri, context.language.scripts.get(uri).languageId, snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
|
|
67
|
+
}
|
|
68
|
+
yield map2DocMap.get(map);
|
|
69
69
|
}
|
|
70
|
-
return result;
|
|
71
70
|
},
|
|
72
71
|
getLinkedCodeMap(virtualCode, documentUri) {
|
|
73
72
|
const map = context.language.linkedCodeMaps.get(virtualCode);
|
package/lib/types.d.ts
CHANGED
|
@@ -49,8 +49,8 @@ export interface LanguageServiceContext {
|
|
|
49
49
|
};
|
|
50
50
|
documents: {
|
|
51
51
|
get(uri: URI, languageId: string, snapshot: ts.IScriptSnapshot): TextDocument;
|
|
52
|
-
|
|
53
|
-
getLinkedCodeMap(virtualCode: VirtualCode
|
|
52
|
+
getMaps(virtualCode: VirtualCode<URI>): Generator<SourceMapWithDocuments>;
|
|
53
|
+
getLinkedCodeMap(virtualCode: VirtualCode<URI>, documentUri: URI): LinkedCodeMapWithDocument | undefined;
|
|
54
54
|
};
|
|
55
55
|
plugins: [LanguageServicePlugin, LanguageServicePluginInstance][];
|
|
56
56
|
disabledEmbeddedDocumentUris: UriMap<boolean>;
|
|
@@ -6,5 +6,5 @@ import type { LanguageServicePlugin, LanguageServicePluginInstance, LanguageServ
|
|
|
6
6
|
export declare function documentFeatureWorker<T>(context: LanguageServiceContext, uri: URI, valid: (map: SourceMapWithDocuments) => boolean, worker: (plugin: [LanguageServicePlugin, LanguageServicePluginInstance], document: TextDocument) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: SourceMapWithDocuments) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
7
7
|
export declare function languageFeatureWorker<T, K>(context: LanguageServiceContext, uri: URI, getRealDocParams: () => K, eachVirtualDocParams: (map: SourceMapWithDocuments) => Generator<K>, worker: (plugin: [LanguageServicePlugin, LanguageServicePluginInstance], document: TextDocument, params: K, map?: SourceMapWithDocuments) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: SourceMapWithDocuments) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
8
8
|
export declare function safeCall<T>(cb: () => Thenable<T> | T, errorMsg?: string): Promise<T | undefined>;
|
|
9
|
-
export declare function forEachEmbeddedDocument(context: LanguageServiceContext, sourceScriptId: URI, current: VirtualCode): Generator<SourceMapWithDocuments>;
|
|
10
|
-
export declare function getEmbeddedFilesByLevel(context: LanguageServiceContext, sourceFileUri: URI, rootFile: VirtualCode, level: number): VirtualCode[];
|
|
9
|
+
export declare function forEachEmbeddedDocument(context: LanguageServiceContext, sourceScriptId: URI, current: VirtualCode<URI>): Generator<SourceMapWithDocuments>;
|
|
10
|
+
export declare function getEmbeddedFilesByLevel(context: LanguageServiceContext, sourceFileUri: URI, rootFile: VirtualCode, level: number): VirtualCode<unknown>[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEmbeddedFilesByLevel = exports.forEachEmbeddedDocument = exports.safeCall = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
4
|
-
|
|
4
|
+
function documentFeatureWorker(context, uri, valid, worker, transformResult, combineResult) {
|
|
5
5
|
return languageFeatureWorker(context, uri, () => void 0, function* (map) {
|
|
6
6
|
if (valid(map)) {
|
|
7
7
|
yield;
|
|
@@ -89,9 +89,11 @@ function* forEachEmbeddedDocument(context, sourceScriptId, current) {
|
|
|
89
89
|
yield* forEachEmbeddedDocument(context, sourceScriptId, embeddedCode);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
const map
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
for (const map of context.documents.getMaps(current)) {
|
|
93
|
+
if (sourceScriptId.toString() === map.sourceDocument.uri
|
|
94
|
+
&& !context.disabledEmbeddedDocumentUris.get(context.encodeEmbeddedDocumentUri(sourceScriptId, current.id))) {
|
|
95
|
+
yield map;
|
|
96
|
+
}
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
exports.forEachEmbeddedDocument = forEachEmbeddedDocument;
|
package/lib/utils/transform.js
CHANGED
|
@@ -15,8 +15,10 @@ function transformDocumentLinkTarget(_target, context) {
|
|
|
15
15
|
const virtualCode = sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
16
16
|
target = decoded[0];
|
|
17
17
|
if (embeddedRange && virtualCode) {
|
|
18
|
-
const map
|
|
19
|
-
|
|
18
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
19
|
+
if (!map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
20
22
|
const startLine = Number(embeddedRange[1]) - 1;
|
|
21
23
|
const startCharacter = Number(embeddedRange[3] ?? 1) - 1;
|
|
22
24
|
if (embeddedRange[5] !== undefined) {
|
|
@@ -31,6 +33,7 @@ function transformDocumentLinkTarget(_target, context) {
|
|
|
31
33
|
fragment: 'L' + (sourceRange.start.line + 1) + ',' + (sourceRange.start.character + 1)
|
|
32
34
|
+ '-L' + (sourceRange.end.line + 1) + ',' + (sourceRange.end.character + 1),
|
|
33
35
|
});
|
|
36
|
+
break;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
@@ -39,6 +42,7 @@ function transformDocumentLinkTarget(_target, context) {
|
|
|
39
42
|
target = target.with({
|
|
40
43
|
fragment: 'L' + (sourcePos.line + 1) + ',' + (sourcePos.character + 1),
|
|
41
44
|
});
|
|
45
|
+
break;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
}
|
|
@@ -272,10 +276,11 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
|
|
|
272
276
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
273
277
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
274
278
|
if (virtualCode) {
|
|
275
|
-
const map
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
280
|
+
// TODO: check capability?
|
|
281
|
+
const uri = map.sourceDocument.uri;
|
|
282
|
+
sourceResult.changeAnnotations[uri] = tsAnno;
|
|
283
|
+
}
|
|
279
284
|
}
|
|
280
285
|
else {
|
|
281
286
|
sourceResult.changeAnnotations[tsUri] = tsAnno;
|
|
@@ -287,30 +292,31 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
|
|
|
287
292
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
288
293
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
289
294
|
if (virtualCode) {
|
|
290
|
-
const map
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
});
|
|
299
|
-
if (range) {
|
|
300
|
-
sourceResult.changes[map.sourceDocument.uri] ??= [];
|
|
301
|
-
sourceResult.changes[map.sourceDocument.uri].push({
|
|
302
|
-
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
|
|
303
|
-
range,
|
|
295
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
296
|
+
const tsEdits = edit.changes[tsUri];
|
|
297
|
+
for (const tsEdit of tsEdits) {
|
|
298
|
+
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
|
|
299
|
+
let _data;
|
|
300
|
+
const range = map.getSourceRange(tsEdit.range, data => {
|
|
301
|
+
_data = data;
|
|
302
|
+
return (0, language_core_1.isRenameEnabled)(data);
|
|
304
303
|
});
|
|
305
|
-
|
|
304
|
+
if (range) {
|
|
305
|
+
sourceResult.changes[map.sourceDocument.uri] ??= [];
|
|
306
|
+
sourceResult.changes[map.sourceDocument.uri].push({
|
|
307
|
+
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
|
|
308
|
+
range,
|
|
309
|
+
});
|
|
310
|
+
hasResult = true;
|
|
311
|
+
}
|
|
306
312
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
else {
|
|
314
|
+
const range = map.getSourceRange(tsEdit.range);
|
|
315
|
+
if (range) {
|
|
316
|
+
sourceResult.changes[map.sourceDocument.uri] ??= [];
|
|
317
|
+
sourceResult.changes[map.sourceDocument.uri].push({ newText: tsEdit.newText, range });
|
|
318
|
+
hasResult = true;
|
|
319
|
+
}
|
|
314
320
|
}
|
|
315
321
|
}
|
|
316
322
|
}
|
|
@@ -329,43 +335,44 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
|
|
|
329
335
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
330
336
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
331
337
|
if (virtualCode) {
|
|
332
|
-
const map
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
});
|
|
348
|
-
if (range) {
|
|
349
|
-
sourceEdit.edits.push({
|
|
350
|
-
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
|
|
351
|
-
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
|
|
352
|
-
range,
|
|
338
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
339
|
+
sourceEdit = {
|
|
340
|
+
textDocument: {
|
|
341
|
+
uri: map.sourceDocument.uri,
|
|
342
|
+
version: versions[map.sourceDocument.uri] ?? null,
|
|
343
|
+
},
|
|
344
|
+
edits: [],
|
|
345
|
+
};
|
|
346
|
+
for (const tsEdit of tsDocEdit.edits) {
|
|
347
|
+
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
|
|
348
|
+
let _data;
|
|
349
|
+
const range = map.getSourceRange(tsEdit.range, data => {
|
|
350
|
+
_data = data;
|
|
351
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1091
|
|
352
|
+
return (0, language_core_1.isRenameEnabled)(data);
|
|
353
353
|
});
|
|
354
|
+
if (range) {
|
|
355
|
+
sourceEdit.edits.push({
|
|
356
|
+
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
|
|
357
|
+
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
|
|
358
|
+
range,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
354
361
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
362
|
+
else {
|
|
363
|
+
const range = map.getSourceRange(tsEdit.range);
|
|
364
|
+
if (range) {
|
|
365
|
+
sourceEdit.edits.push({
|
|
366
|
+
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
|
|
367
|
+
newText: tsEdit.newText,
|
|
368
|
+
range,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
364
371
|
}
|
|
365
372
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
373
|
+
if (!sourceEdit.edits.length) {
|
|
374
|
+
sourceEdit = undefined;
|
|
375
|
+
}
|
|
369
376
|
}
|
|
370
377
|
}
|
|
371
378
|
else {
|
|
@@ -380,15 +387,16 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
|
|
|
380
387
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
381
388
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
382
389
|
if (virtualCode) {
|
|
383
|
-
const map
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
390
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
391
|
+
// TODO: check capability?
|
|
392
|
+
sourceEdit = {
|
|
393
|
+
kind: 'rename',
|
|
394
|
+
oldUri: map.sourceDocument.uri,
|
|
395
|
+
newUri: tsDocEdit.newUri /* TODO: remove .ts? */,
|
|
396
|
+
options: tsDocEdit.options,
|
|
397
|
+
annotationId: tsDocEdit.annotationId,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
392
400
|
}
|
|
393
401
|
else {
|
|
394
402
|
sourceEdit = tsDocEdit;
|
|
@@ -399,14 +407,15 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
|
|
|
399
407
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
400
408
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
401
409
|
if (virtualCode) {
|
|
402
|
-
const map
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
+
for (const map of context.documents.getMaps(virtualCode)) {
|
|
411
|
+
// TODO: check capability?
|
|
412
|
+
sourceEdit = {
|
|
413
|
+
kind: 'delete',
|
|
414
|
+
uri: map.sourceDocument.uri,
|
|
415
|
+
options: tsDocEdit.options,
|
|
416
|
+
annotationId: tsDocEdit.annotationId,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
410
419
|
}
|
|
411
420
|
else {
|
|
412
421
|
sourceEdit = tsDocEdit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "2.3.0-alpha.
|
|
3
|
+
"version": "2.3.0-alpha.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"directory": "packages/language-service"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.3.0-alpha.
|
|
15
|
+
"@volar/language-core": "2.3.0-alpha.6",
|
|
16
16
|
"vscode-languageserver-protocol": "^3.17.5",
|
|
17
17
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
18
18
|
"vscode-uri": "^3.0.8"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "f3103e86be8d80cb36f66be4c054ef9a255c29b1"
|
|
21
21
|
}
|