@volar/language-service 2.1.4 → 2.2.0-alpha.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 +2 -11
- package/lib/documents.js +1 -52
- package/lib/features/provideCallHierarchyItems.d.ts +1 -1
- package/lib/features/provideCallHierarchyItems.js +10 -8
- package/lib/features/provideCodeActions.js +2 -2
- package/lib/features/provideCompletionItems.d.ts +1 -1
- package/lib/features/provideCompletionItems.js +14 -12
- package/lib/features/provideDefinition.js +15 -9
- package/lib/features/provideDiagnostics.js +9 -7
- package/lib/features/provideDocumentFormattingEdits.js +40 -41
- package/lib/features/provideDocumentHighlights.js +12 -8
- package/lib/features/provideDocumentSemanticTokens.js +3 -3
- package/lib/features/provideFileReferences.d.ts +2 -2
- package/lib/features/provideFileReferences.js +3 -1
- package/lib/features/provideInlayHints.js +2 -2
- package/lib/features/provideReferences.js +15 -9
- package/lib/features/provideRenameEdits.js +12 -8
- package/lib/features/provideWorkspaceSymbols.js +3 -1
- package/lib/features/resolveCompletionItem.js +4 -2
- package/lib/languageService.d.ts +4 -4
- package/lib/languageService.js +128 -80
- package/lib/types.d.ts +66 -56
- package/lib/utils/featureWorkers.d.ts +4 -4
- package/lib/utils/featureWorkers.js +12 -13
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.js +24 -12
- package/package.json +3 -3
package/lib/documents.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type * as ts from 'typescript';
|
|
1
|
+
import { CodeRangeKey, LinkedCodeMap, Mapping, SourceMap } from '@volar/language-core';
|
|
3
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
4
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
-
export type DocumentProvider = ReturnType<typeof createDocumentProvider>;
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
6
4
|
export declare class SourceMapWithDocuments<Data = any> {
|
|
7
5
|
sourceDocument: TextDocument;
|
|
8
6
|
embeddedDocument: TextDocument;
|
|
@@ -29,10 +27,3 @@ export declare class LinkedCodeMapWithDocument extends SourceMapWithDocuments {
|
|
|
29
27
|
constructor(document: TextDocument, linkedMap: LinkedCodeMap);
|
|
30
28
|
getLinkedCodePositions(posotion: vscode.Position): Generator<import("vscode-languageserver-textdocument").Position, void, unknown>;
|
|
31
29
|
}
|
|
32
|
-
export declare function createDocumentProvider(files: FileRegistry): {
|
|
33
|
-
get: (uri: string, languageId: string, snapshot: ts.IScriptSnapshot) => TextDocument;
|
|
34
|
-
getMaps(virtualCode: VirtualCode): Generator<SourceMapWithDocuments<CodeInformation>, void, unknown>;
|
|
35
|
-
getLinkedCodeMap(virtualCode: VirtualCode): LinkedCodeMapWithDocument | undefined;
|
|
36
|
-
getVirtualCodeByUri(uri: string): readonly [VirtualCode, import("@volar/language-core").SourceFile] | readonly [undefined, undefined];
|
|
37
|
-
getVirtualCodeUri(sourceFileUri: string, virtualCodeId: string): string;
|
|
38
|
-
};
|
package/lib/documents.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.LinkedCodeMapWithDocument = exports.SourceMapWithDocuments = void 0;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
5
|
class SourceMapWithDocuments {
|
|
7
6
|
constructor(sourceDocument, embeddedDocument, map) {
|
|
8
7
|
this.sourceDocument = sourceDocument;
|
|
@@ -113,54 +112,4 @@ class LinkedCodeMapWithDocument extends SourceMapWithDocuments {
|
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
exports.LinkedCodeMapWithDocument = LinkedCodeMapWithDocument;
|
|
116
|
-
function createDocumentProvider(files) {
|
|
117
|
-
let version = 0;
|
|
118
|
-
const map2DocMap = new WeakMap();
|
|
119
|
-
const mirrorMap2DocMirrorMap = new WeakMap();
|
|
120
|
-
const snapshot2Doc = new WeakMap();
|
|
121
|
-
return {
|
|
122
|
-
get,
|
|
123
|
-
*getMaps(virtualCode) {
|
|
124
|
-
for (const [sourceFileUri, [sourceSnapshot, map]] of files.getMaps(virtualCode)) {
|
|
125
|
-
if (!map2DocMap.has(map)) {
|
|
126
|
-
map2DocMap.set(map, new SourceMapWithDocuments(get(sourceFileUri, files.get(sourceFileUri).languageId, sourceSnapshot), get(this.getVirtualCodeUri(sourceFileUri, virtualCode.id), virtualCode.languageId, virtualCode.snapshot), map));
|
|
127
|
-
}
|
|
128
|
-
yield map2DocMap.get(map);
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
getLinkedCodeMap(virtualCode) {
|
|
132
|
-
const map = files.getLinkedCodeMap(virtualCode);
|
|
133
|
-
if (map) {
|
|
134
|
-
if (!mirrorMap2DocMirrorMap.has(map)) {
|
|
135
|
-
mirrorMap2DocMirrorMap.set(map, new LinkedCodeMapWithDocument(get(this.getVirtualCodeUri(files.getByVirtualCode(virtualCode).id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot), map));
|
|
136
|
-
}
|
|
137
|
-
return mirrorMap2DocMirrorMap.get(map);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
// TODO: rename to getVirtualCodeByDocumentUri
|
|
141
|
-
getVirtualCodeByUri(uri) {
|
|
142
|
-
if (uri.includes('?virtualCodeId=')) {
|
|
143
|
-
const sourceFileUri = uri.split('?virtualCodeId=')[0];
|
|
144
|
-
const virtualCodeId = uri.split('?virtualCodeId=')[1];
|
|
145
|
-
return files.getVirtualCode(sourceFileUri, virtualCodeId);
|
|
146
|
-
}
|
|
147
|
-
return [undefined, undefined];
|
|
148
|
-
},
|
|
149
|
-
// TODO: rename to getDocumentUriByVirtualCode
|
|
150
|
-
getVirtualCodeUri(sourceFileUri, virtualCodeId) {
|
|
151
|
-
return sourceFileUri + `?virtualCodeId=${virtualCodeId}`;
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
function get(uri, languageId, snapshot) {
|
|
155
|
-
if (!snapshot2Doc.has(snapshot)) {
|
|
156
|
-
snapshot2Doc.set(snapshot, new Map());
|
|
157
|
-
}
|
|
158
|
-
const map = snapshot2Doc.get(snapshot);
|
|
159
|
-
if (!map.has(uri)) {
|
|
160
|
-
map.set(uri, vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, version++, snapshot.getText(0, snapshot.getLength())));
|
|
161
|
-
}
|
|
162
|
-
return map.get(uri);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exports.createDocumentProvider = createDocumentProvider;
|
|
166
115
|
//# sourceMappingURL=documents.js.map
|
|
@@ -4,7 +4,7 @@ export interface PluginCallHierarchyData {
|
|
|
4
4
|
uri: string;
|
|
5
5
|
original: Pick<vscode.CallHierarchyItem, 'data'>;
|
|
6
6
|
serviceIndex: number;
|
|
7
|
-
|
|
7
|
+
embeddedDocumentUri: string | undefined;
|
|
8
8
|
}
|
|
9
9
|
export declare function register(context: ServiceContext): {
|
|
10
10
|
doPrepare(uri: string, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.CallHierarchyItem[] | undefined>;
|
|
@@ -21,7 +21,7 @@ function register(context) {
|
|
|
21
21
|
data: item.data,
|
|
22
22
|
},
|
|
23
23
|
serviceIndex: context.services.indexOf(service),
|
|
24
|
-
|
|
24
|
+
embeddedDocumentUri: map?.embeddedDocument.uri,
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
27
|
return items;
|
|
@@ -43,9 +43,9 @@ function register(context) {
|
|
|
43
43
|
return incomingItems;
|
|
44
44
|
}
|
|
45
45
|
Object.assign(item, data.original);
|
|
46
|
-
if (data.
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
46
|
+
if (data.embeddedDocumentUri) {
|
|
47
|
+
const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(data.embeddedDocumentUri);
|
|
48
|
+
if (isEmbeddedContent) {
|
|
49
49
|
const _calls = await service[1].provideCallHierarchyIncomingCalls(item, token);
|
|
50
50
|
for (const _call of _calls) {
|
|
51
51
|
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
|
|
@@ -84,9 +84,9 @@ function register(context) {
|
|
|
84
84
|
return items;
|
|
85
85
|
}
|
|
86
86
|
Object.assign(item, data.original);
|
|
87
|
-
if (data.
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
87
|
+
if (data.embeddedDocumentUri) {
|
|
88
|
+
const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(data.embeddedDocumentUri);
|
|
89
|
+
if (isEmbeddedContent) {
|
|
90
90
|
const _calls = await service[1].provideCallHierarchyOutgoingCalls(item, token);
|
|
91
91
|
for (const call of _calls) {
|
|
92
92
|
const calls = transformCallHierarchyItem(call.to, call.fromRanges);
|
|
@@ -118,7 +118,9 @@ function register(context) {
|
|
|
118
118
|
},
|
|
119
119
|
};
|
|
120
120
|
function transformCallHierarchyItem(tsItem, tsRanges) {
|
|
121
|
-
const
|
|
121
|
+
const decoded = context.decodeEmbeddedDocumentUri(tsItem.uri);
|
|
122
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
123
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
122
124
|
if (!virtualCode) {
|
|
123
125
|
return [tsItem, tsRanges];
|
|
124
126
|
}
|
|
@@ -9,8 +9,8 @@ const transform_1 = require("../utils/transform");
|
|
|
9
9
|
const language_core_1 = require("@volar/language-core");
|
|
10
10
|
function register(context) {
|
|
11
11
|
return async (uri, range, codeActionContext, token = cancellation_1.NoneCancellationToken) => {
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
12
|
+
const sourceScript = context.language.scripts.get(uri);
|
|
13
|
+
if (!sourceScript) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
const transformedCodeActions = new WeakSet();
|
|
@@ -4,6 +4,6 @@ export interface ServiceCompletionData {
|
|
|
4
4
|
uri: string;
|
|
5
5
|
original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
|
|
6
6
|
serviceIndex: number;
|
|
7
|
-
|
|
7
|
+
embeddedDocumentUri: string | undefined;
|
|
8
8
|
}
|
|
9
9
|
export declare function register(context: ServiceContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;
|
|
@@ -8,8 +8,8 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
8
8
|
function register(context) {
|
|
9
9
|
let lastResult;
|
|
10
10
|
return async (uri, position, completionContext = { triggerKind: 1, }, token = cancellation_1.NoneCancellationToken) => {
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
11
|
+
const sourceScript = context.language.scripts.get(uri);
|
|
12
|
+
if (!sourceScript) {
|
|
13
13
|
return {
|
|
14
14
|
isIncomplete: false,
|
|
15
15
|
items: [],
|
|
@@ -22,8 +22,10 @@ function register(context) {
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
const serviceIndex = context.services.findIndex(service => service[1] === cacheData.service);
|
|
25
|
-
if (cacheData.
|
|
26
|
-
const
|
|
25
|
+
if (cacheData.embeddedDocumentUri) {
|
|
26
|
+
const decoded = context.decodeEmbeddedDocumentUri(cacheData.embeddedDocumentUri);
|
|
27
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
28
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
27
29
|
if (!virtualCode) {
|
|
28
30
|
continue;
|
|
29
31
|
}
|
|
@@ -45,7 +47,7 @@ function register(context) {
|
|
|
45
47
|
data: item.data,
|
|
46
48
|
},
|
|
47
49
|
serviceIndex,
|
|
48
|
-
|
|
50
|
+
embeddedDocumentUri: map.embeddedDocument.uri,
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
|
|
@@ -56,7 +58,7 @@ function register(context) {
|
|
|
56
58
|
if (!cacheData.service.provideCompletionItems) {
|
|
57
59
|
continue;
|
|
58
60
|
}
|
|
59
|
-
const document = context.documents.get(uri,
|
|
61
|
+
const document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
|
60
62
|
cacheData.list = await cacheData.service.provideCompletionItems(document, position, completionContext, token);
|
|
61
63
|
if (!cacheData.list) {
|
|
62
64
|
continue;
|
|
@@ -70,7 +72,7 @@ function register(context) {
|
|
|
70
72
|
data: item.data,
|
|
71
73
|
},
|
|
72
74
|
serviceIndex,
|
|
73
|
-
|
|
75
|
+
embeddedDocumentUri: undefined,
|
|
74
76
|
};
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -129,22 +131,22 @@ function register(context) {
|
|
|
129
131
|
data: item.data,
|
|
130
132
|
},
|
|
131
133
|
serviceIndex,
|
|
132
|
-
|
|
134
|
+
embeddedDocumentUri: map ? document.uri : undefined,
|
|
133
135
|
};
|
|
134
136
|
}
|
|
135
137
|
if (map) {
|
|
136
138
|
completionList = (0, transform_1.transformCompletionList)(completionList, range => map.getSourceRange(range, language_core_1.isCompletionEnabled), document, context);
|
|
137
139
|
}
|
|
138
140
|
lastResult?.results.push({
|
|
139
|
-
|
|
141
|
+
embeddedDocumentUri: map ? document.uri : undefined,
|
|
140
142
|
service: service[1],
|
|
141
143
|
list: completionList,
|
|
142
144
|
});
|
|
143
145
|
}
|
|
144
146
|
isFirstMapping = false;
|
|
145
147
|
};
|
|
146
|
-
if (
|
|
147
|
-
for (const map of (0, featureWorkers_1.
|
|
148
|
+
if (sourceScript.generated) {
|
|
149
|
+
for (const map of (0, featureWorkers_1.forEachEmbeddedDocument)(context, sourceScript.id, sourceScript.generated.root)) {
|
|
148
150
|
let _data;
|
|
149
151
|
for (const mappedPosition of map.getGeneratedPositions(position, data => {
|
|
150
152
|
_data = data;
|
|
@@ -155,7 +157,7 @@ function register(context) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
else {
|
|
158
|
-
const document = context.documents.get(uri,
|
|
160
|
+
const document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
|
159
161
|
await worker(document, position);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
@@ -13,9 +13,9 @@ function register(context, apiName, isValidPosition) {
|
|
|
13
13
|
}
|
|
14
14
|
const recursiveChecker = dedupe.createLocationSet();
|
|
15
15
|
const result = [];
|
|
16
|
-
await
|
|
16
|
+
await withLinkedCode(document, position, undefined);
|
|
17
17
|
return result;
|
|
18
|
-
async function
|
|
18
|
+
async function withLinkedCode(document, position, originDefinition) {
|
|
19
19
|
const api = service[1][apiName];
|
|
20
20
|
if (!api) {
|
|
21
21
|
return;
|
|
@@ -28,15 +28,19 @@ function register(context, apiName, isValidPosition) {
|
|
|
28
28
|
for (const definition of definitions) {
|
|
29
29
|
let foundMirrorPosition = false;
|
|
30
30
|
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const decoded = context.decodeEmbeddedDocumentUri(definition.targetUri);
|
|
32
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
33
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
34
|
+
const linkedCodeMap = virtualCode && sourceScript
|
|
35
|
+
? context.documents.getLinkedCodeMap(virtualCode, sourceScript.id)
|
|
36
|
+
: undefined;
|
|
37
|
+
if (linkedCodeMap) {
|
|
38
|
+
for (const linkedPos of linkedCodeMap.getLinkedCodePositions(definition.targetSelectionRange.start)) {
|
|
39
|
+
if (recursiveChecker.has({ uri: linkedCodeMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
36
40
|
continue;
|
|
37
41
|
}
|
|
38
42
|
foundMirrorPosition = true;
|
|
39
|
-
await
|
|
43
|
+
await withLinkedCode(linkedCodeMap.document, linkedPos, originDefinition ?? definition);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
if (!foundMirrorPosition) {
|
|
@@ -61,7 +65,9 @@ function register(context, apiName, isValidPosition) {
|
|
|
61
65
|
link.originSelectionRange = originSelectionRange;
|
|
62
66
|
}
|
|
63
67
|
let foundTargetSelectionRange = false;
|
|
64
|
-
const
|
|
68
|
+
const decoded = context.decodeEmbeddedDocumentUri(link.targetUri);
|
|
69
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
70
|
+
const targetVirtualFile = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
65
71
|
if (targetVirtualFile) {
|
|
66
72
|
for (const targetSourceMap of context.documents.getMaps(targetVirtualFile)) {
|
|
67
73
|
const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
|
|
@@ -91,11 +91,11 @@ function register(context) {
|
|
|
91
91
|
cacheMaps.syntactic.clear();
|
|
92
92
|
});
|
|
93
93
|
return async (uri, token = cancellation_1.NoneCancellationToken, response) => {
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
94
|
+
const sourceScript = context.language.scripts.get(uri);
|
|
95
|
+
if (!sourceScript) {
|
|
96
96
|
return [];
|
|
97
97
|
}
|
|
98
|
-
const document = context.documents.get(uri,
|
|
98
|
+
const document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
|
99
99
|
const lastResponse = lastResponses.get(uri) ?? lastResponses.set(uri, {
|
|
100
100
|
semantic: { errors: [] },
|
|
101
101
|
syntactic: { errors: [] },
|
|
@@ -106,8 +106,8 @@ function register(context) {
|
|
|
106
106
|
for (const cache of Object.values(lastResponse)) {
|
|
107
107
|
const oldSnapshot = cache.snapshot;
|
|
108
108
|
const oldDocument = cache.document;
|
|
109
|
-
const change = oldSnapshot ?
|
|
110
|
-
cache.snapshot =
|
|
109
|
+
const change = oldSnapshot ? sourceScript.snapshot.getChangeRange(oldSnapshot) : undefined;
|
|
110
|
+
cache.snapshot = sourceScript.snapshot;
|
|
111
111
|
cache.document = document;
|
|
112
112
|
if (!updateCacheRangeFailed && oldDocument && change) {
|
|
113
113
|
const changeRange = {
|
|
@@ -179,7 +179,7 @@ function register(context) {
|
|
|
179
179
|
}, arr => dedupe.withDiagnostics(arr.flat()));
|
|
180
180
|
if (result) {
|
|
181
181
|
cache.errors = result;
|
|
182
|
-
cache.snapshot =
|
|
182
|
+
cache.snapshot = sourceScript?.snapshot;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
};
|
|
@@ -198,7 +198,9 @@ function register(context) {
|
|
|
198
198
|
if (_error.relatedInformation) {
|
|
199
199
|
const relatedInfos = [];
|
|
200
200
|
for (const info of _error.relatedInformation) {
|
|
201
|
-
const
|
|
201
|
+
const decoded = context.decodeEmbeddedDocumentUri(info.location.uri);
|
|
202
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
203
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
202
204
|
if (virtualCode) {
|
|
203
205
|
for (const map of context.documents.getMaps(virtualCode)) {
|
|
204
206
|
const range = map.getSourceRange(info.location.range, filter);
|
|
@@ -10,51 +10,49 @@ 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
|
|
14
|
-
if (!
|
|
13
|
+
const sourceScript = context.language.scripts.get(uri);
|
|
14
|
+
if (!sourceScript) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
let document = context.documents.get(uri,
|
|
17
|
+
let document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
|
18
18
|
range ??= {
|
|
19
19
|
start: document.positionAt(0),
|
|
20
20
|
end: document.positionAt(document.getText().length),
|
|
21
21
|
};
|
|
22
|
-
if (!
|
|
22
|
+
if (!sourceScript.generated) {
|
|
23
23
|
return onTypeParams
|
|
24
|
-
? (await tryFormat(document, document, undefined, 0, onTypeParams.position, onTypeParams.ch))?.edits
|
|
25
|
-
: (await tryFormat(document, document, undefined, 0, range, undefined))?.edits;
|
|
24
|
+
? (await tryFormat(document, document, sourceScript, undefined, 0, onTypeParams.position, onTypeParams.ch))?.edits
|
|
25
|
+
: (await tryFormat(document, document, sourceScript, undefined, 0, range, undefined))?.edits;
|
|
26
26
|
}
|
|
27
27
|
const embeddedRanges = new Map();
|
|
28
28
|
const startOffset = document.offsetAt(range.start);
|
|
29
29
|
const endOffset = document.offsetAt(range.end);
|
|
30
|
-
for (const code of (0, language_core_1.forEachEmbeddedCode)(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
const lastMapping = map.mappings[map.mappings.length - 1];
|
|
39
|
-
if (embeddedRange.end === lastMapping.generatedOffsets[lastMapping.generatedOffsets.length - 1] + lastMapping.lengths[lastMapping.lengths.length - 1]) {
|
|
40
|
-
embeddedRange.end = code.snapshot.getLength();
|
|
41
|
-
}
|
|
42
|
-
embeddedRanges.set(code.id, embeddedRange);
|
|
30
|
+
for (const code of (0, language_core_1.forEachEmbeddedCode)(sourceScript.generated.root)) {
|
|
31
|
+
const map = context.language.maps.get(code);
|
|
32
|
+
if (map) {
|
|
33
|
+
const embeddedRange = (0, common_1.findOverlapCodeRange)(startOffset, endOffset, map, language_core_1.isFormattingEnabled);
|
|
34
|
+
if (embeddedRange) {
|
|
35
|
+
if (embeddedRange.start === map.mappings[0].generatedOffsets[0]) {
|
|
36
|
+
embeddedRange.start = 0;
|
|
43
37
|
}
|
|
44
|
-
|
|
38
|
+
const lastMapping = map.mappings[map.mappings.length - 1];
|
|
39
|
+
if (embeddedRange.end === lastMapping.generatedOffsets[lastMapping.generatedOffsets.length - 1] + lastMapping.lengths[lastMapping.lengths.length - 1]) {
|
|
40
|
+
embeddedRange.end = code.snapshot.getLength();
|
|
41
|
+
}
|
|
42
|
+
embeddedRanges.set(code.id, embeddedRange);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
try {
|
|
49
47
|
const originalDocument = document;
|
|
50
|
-
let tempSourceSnapshot =
|
|
51
|
-
let tempVirtualFile = context.language.
|
|
48
|
+
let tempSourceSnapshot = sourceScript.snapshot;
|
|
49
|
+
let tempVirtualFile = context.language.scripts.set(sourceScript.id + '.tmp', sourceScript.languageId, sourceScript.snapshot, [sourceScript.generated.languagePlugin]).generated?.root;
|
|
52
50
|
if (!tempVirtualFile) {
|
|
53
51
|
return;
|
|
54
52
|
}
|
|
55
53
|
let level = 0;
|
|
56
54
|
while (true) {
|
|
57
|
-
const embeddedCodes = (0, featureWorkers_1.getEmbeddedFilesByLevel)(context,
|
|
55
|
+
const embeddedCodes = (0, featureWorkers_1.getEmbeddedFilesByLevel)(context, sourceScript.id, tempVirtualFile, level++);
|
|
58
56
|
if (embeddedCodes.length === 0) {
|
|
59
57
|
break;
|
|
60
58
|
}
|
|
@@ -63,7 +61,7 @@ function register(context) {
|
|
|
63
61
|
if (!code.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data))) {
|
|
64
62
|
continue;
|
|
65
63
|
}
|
|
66
|
-
const docMap = createDocMap(code, uri,
|
|
64
|
+
const docMap = createDocMap(code, uri, sourceScript.languageId, tempSourceSnapshot);
|
|
67
65
|
if (!docMap) {
|
|
68
66
|
continue;
|
|
69
67
|
}
|
|
@@ -72,11 +70,11 @@ function register(context) {
|
|
|
72
70
|
if (onTypeParams) {
|
|
73
71
|
const embeddedPosition = docMap.getGeneratedPosition(onTypeParams.position);
|
|
74
72
|
if (embeddedPosition) {
|
|
75
|
-
embeddedCodeResult = await tryFormat(docMap.sourceDocument, docMap.embeddedDocument, code, level, embeddedPosition, onTypeParams.ch);
|
|
73
|
+
embeddedCodeResult = await tryFormat(docMap.sourceDocument, docMap.embeddedDocument, sourceScript, code, level, embeddedPosition, onTypeParams.ch);
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
else if (embeddedRange) {
|
|
79
|
-
embeddedCodeResult = await tryFormat(docMap.sourceDocument, docMap.embeddedDocument, code, level, {
|
|
77
|
+
embeddedCodeResult = await tryFormat(docMap.sourceDocument, docMap.embeddedDocument, sourceScript, code, level, {
|
|
80
78
|
start: docMap.embeddedDocument.positionAt(embeddedRange.start),
|
|
81
79
|
end: docMap.embeddedDocument.positionAt(embeddedRange.end),
|
|
82
80
|
});
|
|
@@ -98,7 +96,7 @@ function register(context) {
|
|
|
98
96
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
99
97
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
100
98
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
101
|
-
tempVirtualFile = context.language.
|
|
99
|
+
tempVirtualFile = context.language.scripts.set(sourceScript.id + '.tmp', sourceScript.languageId, tempSourceSnapshot, [sourceScript.generated.languagePlugin]).generated?.root;
|
|
102
100
|
if (!tempVirtualFile) {
|
|
103
101
|
break;
|
|
104
102
|
}
|
|
@@ -118,10 +116,10 @@ function register(context) {
|
|
|
118
116
|
return [textEdit];
|
|
119
117
|
}
|
|
120
118
|
finally {
|
|
121
|
-
context.language.
|
|
119
|
+
context.language.scripts.delete(sourceScript.id + '.tmp');
|
|
122
120
|
}
|
|
123
|
-
async function tryFormat(sourceDocument, document,
|
|
124
|
-
if (context.
|
|
121
|
+
async function tryFormat(sourceDocument, document, sourceScript, virtualCode, embeddedLevel, rangeOrPosition, ch) {
|
|
122
|
+
if (context.disabledEmbeddedDocumentUris.has(document.uri)) {
|
|
125
123
|
return;
|
|
126
124
|
}
|
|
127
125
|
let codeOptions;
|
|
@@ -129,13 +127,13 @@ function register(context) {
|
|
|
129
127
|
start: document.positionAt(0),
|
|
130
128
|
end: document.positionAt(document.getText().length),
|
|
131
129
|
};
|
|
132
|
-
if (
|
|
130
|
+
if (virtualCode) {
|
|
133
131
|
codeOptions = {
|
|
134
|
-
level:
|
|
132
|
+
level: embeddedLevel - 1,
|
|
135
133
|
initialIndentLevel: 0,
|
|
136
134
|
};
|
|
137
|
-
if (
|
|
138
|
-
const firstMapping =
|
|
135
|
+
if (virtualCode.mappings.length) {
|
|
136
|
+
const firstMapping = virtualCode.mappings[0];
|
|
139
137
|
const startOffset = firstMapping.sourceOffsets[0];
|
|
140
138
|
const startPosition = sourceDocument.positionAt(startOffset);
|
|
141
139
|
codeOptions.initialIndentLevel = computeInitialIndent(sourceDocument.getText(), sourceDocument.offsetAt({ line: startPosition.line, character: 0 }), options);
|
|
@@ -144,7 +142,7 @@ function register(context) {
|
|
|
144
142
|
if (context.disabledServicePlugins.has(service[1])) {
|
|
145
143
|
continue;
|
|
146
144
|
}
|
|
147
|
-
codeOptions = await service[1].resolveEmbeddedCodeFormattingOptions?.(
|
|
145
|
+
codeOptions = await service[1].resolveEmbeddedCodeFormattingOptions?.(sourceScript, virtualCode, codeOptions, token) ?? codeOptions;
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
148
|
for (const service of context.services) {
|
|
@@ -178,16 +176,17 @@ function register(context) {
|
|
|
178
176
|
}
|
|
179
177
|
}
|
|
180
178
|
};
|
|
181
|
-
function createDocMap(
|
|
182
|
-
const
|
|
179
|
+
function createDocMap(virtualCode, documentUri, sourceLanguageId, _sourceSnapshot) {
|
|
180
|
+
const mapOfMap = new Map();
|
|
181
|
+
(0, language_core_1.updateVirtualCodeMapOfMap)(virtualCode, mapOfMap, sourceFileUri2 => {
|
|
183
182
|
if (!sourceFileUri2) {
|
|
184
|
-
return [
|
|
183
|
+
return [documentUri, _sourceSnapshot];
|
|
185
184
|
}
|
|
186
185
|
});
|
|
187
|
-
if (
|
|
188
|
-
const map =
|
|
186
|
+
if (mapOfMap.has(documentUri) && mapOfMap.get(documentUri)[0] === _sourceSnapshot) {
|
|
187
|
+
const map = mapOfMap.get(documentUri);
|
|
189
188
|
const version = fakeVersion++;
|
|
190
|
-
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(
|
|
189
|
+
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(documentUri, sourceLanguageId ?? (0, language_core_1.resolveCommonLanguageId)(documentUri), version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.encodeEmbeddedDocumentUri(documentUri, virtualCode.id), virtualCode.languageId, version, virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength())), map[1]);
|
|
191
190
|
}
|
|
192
191
|
}
|
|
193
192
|
}
|
|
@@ -14,9 +14,9 @@ function register(context) {
|
|
|
14
14
|
}
|
|
15
15
|
const recursiveChecker = dedupe.createLocationSet();
|
|
16
16
|
const result = [];
|
|
17
|
-
await
|
|
17
|
+
await withLinkedCode(document, position);
|
|
18
18
|
return result;
|
|
19
|
-
async function
|
|
19
|
+
async function withLinkedCode(document, position) {
|
|
20
20
|
if (!service[1].provideDocumentHighlights) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
@@ -28,15 +28,19 @@ function register(context) {
|
|
|
28
28
|
for (const reference of references) {
|
|
29
29
|
let foundMirrorPosition = false;
|
|
30
30
|
recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const decoded = context.decodeEmbeddedDocumentUri(document.uri);
|
|
32
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
33
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
34
|
+
const linkedCodeMap = virtualCode && sourceScript
|
|
35
|
+
? context.documents.getLinkedCodeMap(virtualCode, sourceScript.id)
|
|
36
|
+
: undefined;
|
|
37
|
+
if (linkedCodeMap) {
|
|
38
|
+
for (const linkedPos of linkedCodeMap.getLinkedCodePositions(reference.range.start)) {
|
|
39
|
+
if (recursiveChecker.has({ uri: linkedCodeMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
36
40
|
continue;
|
|
37
41
|
}
|
|
38
42
|
foundMirrorPosition = true;
|
|
39
|
-
await
|
|
43
|
+
await withLinkedCode(linkedCodeMap.document, linkedPos);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
if (!foundMirrorPosition) {
|
|
@@ -8,11 +8,11 @@ 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
|
|
12
|
-
if (!
|
|
11
|
+
const sourceScript = context.language.scripts.get(uri);
|
|
12
|
+
if (!sourceScript) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
const document = context.documents.get(uri,
|
|
15
|
+
const document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
|
16
16
|
if (!range) {
|
|
17
17
|
range = {
|
|
18
18
|
start: { line: 0, character: 0 },
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NullableProviderResult, ServiceContext } from '../types';
|
|
2
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context: ServiceContext): (uri: string, token?: vscode.CancellationToken) =>
|
|
3
|
+
export declare function register(context: ServiceContext): (uri: string, token?: vscode.CancellationToken) => NullableProviderResult<vscode.Location[]>;
|
|
@@ -15,7 +15,9 @@ function register(context) {
|
|
|
15
15
|
return await service[1].provideFileReferences?.(document, token) ?? [];
|
|
16
16
|
}, data => data
|
|
17
17
|
.map(reference => {
|
|
18
|
-
const
|
|
18
|
+
const decoded = context.decodeEmbeddedDocumentUri(reference.uri);
|
|
19
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
20
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
19
21
|
if (!virtualCode) {
|
|
20
22
|
return reference;
|
|
21
23
|
}
|
|
@@ -8,8 +8,8 @@ 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
|
|
12
|
-
if (!
|
|
11
|
+
const sourceScript = context.language.scripts.get(uri);
|
|
12
|
+
if (!sourceScript) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => range, function* (map) {
|