@volar/language-service 1.4.0-alpha.4 → 1.4.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/out/baseLanguageService.js +10 -0
- package/out/documentFeatures/format.js +13 -9
- package/out/documentFeatures/selectionRanges.js +27 -11
- package/out/languageFeatures/callHierarchy.d.ts +1 -3
- package/out/languageFeatures/callHierarchy.js +5 -7
- package/out/languageFeatures/complete.d.ts +1 -3
- package/out/languageFeatures/complete.js +8 -14
- package/out/languageFeatures/completeResolve.js +2 -2
- package/out/languageFeatures/documentSemanticTokens.js +1 -1
- package/out/types.d.ts +1 -0
- package/package.json +4 -4
|
@@ -91,6 +91,16 @@ function createLanguageServiceContext(ctx, languageContext, documentRegistry) {
|
|
|
91
91
|
}
|
|
92
92
|
return vscode.Command.create(locations.length === 1 ? '1 reference' : `${locations.length} references`, 'editor.action.showReferences', source.uri, source.position, sourceReferences);
|
|
93
93
|
},
|
|
94
|
+
createSetSelectionCommand(position) {
|
|
95
|
+
return vscode.Command.create('', 'setSelection', {
|
|
96
|
+
selection: {
|
|
97
|
+
selectionStartLineNumber: position.line + 1,
|
|
98
|
+
positionLineNumber: position.line + 1,
|
|
99
|
+
selectionStartColumn: position.character + 1,
|
|
100
|
+
positionColumn: position.character + 1,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
},
|
|
94
104
|
},
|
|
95
105
|
getTextDocument,
|
|
96
106
|
};
|
|
@@ -13,8 +13,8 @@ function register(context) {
|
|
|
13
13
|
const source = context.documents.getSourceByUri(document.uri);
|
|
14
14
|
if (!source) {
|
|
15
15
|
return onTypeParams
|
|
16
|
-
? await tryFormat(document, onTypeParams.position, onTypeParams.ch)
|
|
17
|
-
: await tryFormat(document, range, undefined);
|
|
16
|
+
? (await tryFormat(document, onTypeParams.position, onTypeParams.ch))?.edits
|
|
17
|
+
: (await tryFormat(document, range, undefined))?.edits;
|
|
18
18
|
}
|
|
19
19
|
const initialIndentLanguageId = await context.configurationHost?.getConfiguration('volar.format.initialIndent') ?? { html: true };
|
|
20
20
|
const originalSnapshot = source.snapshot;
|
|
@@ -38,26 +38,27 @@ function register(context) {
|
|
|
38
38
|
const map = maps.find(map => map[1].sourceFileDocument.uri === document.uri)?.[1];
|
|
39
39
|
if (!map)
|
|
40
40
|
continue;
|
|
41
|
-
let
|
|
41
|
+
let embeddedCodeResult;
|
|
42
42
|
if (onTypeParams) {
|
|
43
43
|
const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
|
|
44
44
|
if (embeddedPosition) {
|
|
45
|
-
|
|
45
|
+
embeddedCodeResult = await tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
|
|
49
|
+
embeddedCodeResult = await tryFormat(map.virtualFileDocument, {
|
|
50
50
|
start: map.virtualFileDocument.positionAt(0),
|
|
51
51
|
end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
if (!
|
|
54
|
+
if (!embeddedCodeResult)
|
|
55
55
|
continue;
|
|
56
56
|
toPatchIndentUris.push({
|
|
57
57
|
uri: map.virtualFileDocument.uri,
|
|
58
58
|
isCodeBlock,
|
|
59
|
+
plugin: embeddedCodeResult.plugin,
|
|
59
60
|
});
|
|
60
|
-
for (const textEdit of
|
|
61
|
+
for (const textEdit of embeddedCodeResult.edits) {
|
|
61
62
|
const range = map.toSourceRange(textEdit.range);
|
|
62
63
|
if (range) {
|
|
63
64
|
edits.push({
|
|
@@ -87,7 +88,7 @@ function register(context) {
|
|
|
87
88
|
for (const toPatchIndentUri of toPatchIndentUris) {
|
|
88
89
|
for (const [_, map] of context.documents.getMapsByVirtualFileUri(toPatchIndentUri.uri)) {
|
|
89
90
|
const indentSensitiveLines = new Set();
|
|
90
|
-
for (const plugin of Object.values(context.plugins)) {
|
|
91
|
+
for (const plugin of toPatchIndentUri.plugin.provideFormattingIndentSensitiveLines ? [toPatchIndentUri.plugin] : Object.values(context.plugins)) {
|
|
91
92
|
if (token.isCancellationRequested)
|
|
92
93
|
break;
|
|
93
94
|
if (plugin.provideFormattingIndentSensitiveLines) {
|
|
@@ -166,7 +167,10 @@ function register(context) {
|
|
|
166
167
|
}
|
|
167
168
|
if (!edits)
|
|
168
169
|
continue;
|
|
169
|
-
return
|
|
170
|
+
return {
|
|
171
|
+
plugin,
|
|
172
|
+
edits,
|
|
173
|
+
};
|
|
170
174
|
}
|
|
171
175
|
}
|
|
172
176
|
};
|
|
@@ -22,21 +22,37 @@ function register(context) {
|
|
|
22
22
|
return;
|
|
23
23
|
return plugin.provideSelectionRanges?.(document, positions, token);
|
|
24
24
|
}, (item, map) => map ? transformer.asSelectionRanges(item, range => map.toSourceRange(range)) : item, results => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const result = [];
|
|
26
|
+
for (let i = 0; i < positions.length; i++) {
|
|
27
|
+
let pluginResults = [];
|
|
28
|
+
for (const ranges of results) {
|
|
29
|
+
pluginResults.push(ranges[i]);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
pluginResults = pluginResults.sort((a, b) => {
|
|
32
|
+
if ((0, common_1.isInsideRange)(a.range, b.range)) {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
if ((0, common_1.isInsideRange)(b.range, a.range)) {
|
|
36
|
+
return -1;
|
|
37
|
+
}
|
|
38
|
+
return 0;
|
|
39
|
+
});
|
|
40
|
+
for (let i = 1; i < pluginResults.length; i++) {
|
|
41
|
+
let root = pluginResults[i - 1];
|
|
42
|
+
while (root.parent) {
|
|
43
|
+
root = root.parent;
|
|
44
|
+
}
|
|
45
|
+
let parent = pluginResults[i];
|
|
46
|
+
while (parent && !(0, common_1.isInsideRange)(parent.range, root.range)) {
|
|
47
|
+
parent = parent.parent;
|
|
48
|
+
}
|
|
49
|
+
if (parent) {
|
|
50
|
+
root.parent = parent;
|
|
36
51
|
}
|
|
37
52
|
}
|
|
53
|
+
result.push(pluginResults[0]);
|
|
38
54
|
}
|
|
39
|
-
return
|
|
55
|
+
return result;
|
|
40
56
|
});
|
|
41
57
|
};
|
|
42
58
|
}
|
|
@@ -4,9 +4,7 @@ export interface PluginCallHierarchyData {
|
|
|
4
4
|
uri: string;
|
|
5
5
|
original: Pick<vscode.CallHierarchyItem, 'data'>;
|
|
6
6
|
pluginId: string;
|
|
7
|
-
|
|
8
|
-
embeddedDocumentUri: string;
|
|
9
|
-
} | undefined;
|
|
7
|
+
virtualDocumentUri: string | undefined;
|
|
10
8
|
}
|
|
11
9
|
export declare function register(context: LanguageServicePluginContext): {
|
|
12
10
|
doPrepare(uri: string, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.CallHierarchyItem[] | undefined>;
|
|
@@ -20,9 +20,7 @@ function register(context) {
|
|
|
20
20
|
data: item.data,
|
|
21
21
|
},
|
|
22
22
|
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
23
|
-
|
|
24
|
-
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
25
|
-
} : undefined,
|
|
23
|
+
virtualDocumentUri: map?.virtualFileDocument.uri,
|
|
26
24
|
};
|
|
27
25
|
});
|
|
28
26
|
return items;
|
|
@@ -38,8 +36,8 @@ function register(context) {
|
|
|
38
36
|
if (!plugin.provideCallHierarchyIncomingCalls)
|
|
39
37
|
return incomingItems;
|
|
40
38
|
Object.assign(item, data.original);
|
|
41
|
-
if (data.
|
|
42
|
-
if (context.documents.isVirtualFileUri(data.
|
|
39
|
+
if (data.virtualDocumentUri) {
|
|
40
|
+
if (context.documents.isVirtualFileUri(data.virtualDocumentUri)) {
|
|
43
41
|
const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token);
|
|
44
42
|
for (const _call of _calls) {
|
|
45
43
|
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
|
|
@@ -75,8 +73,8 @@ function register(context) {
|
|
|
75
73
|
if (!plugin.provideCallHierarchyOutgoingCalls)
|
|
76
74
|
return items;
|
|
77
75
|
Object.assign(item, data.original);
|
|
78
|
-
if (data.
|
|
79
|
-
if (context.documents.isVirtualFileUri(data.
|
|
76
|
+
if (data.virtualDocumentUri) {
|
|
77
|
+
if (context.documents.isVirtualFileUri(data.virtualDocumentUri)) {
|
|
80
78
|
const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token);
|
|
81
79
|
for (const call of _calls) {
|
|
82
80
|
const calls = transformCallHierarchyItem(call.to, call.fromRanges);
|
|
@@ -4,8 +4,6 @@ export interface PluginCompletionData {
|
|
|
4
4
|
uri: string;
|
|
5
5
|
original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
|
|
6
6
|
pluginId: string;
|
|
7
|
-
|
|
8
|
-
embeddedDocumentUri: string;
|
|
9
|
-
} | undefined;
|
|
7
|
+
virtualDocumentUri: string | undefined;
|
|
10
8
|
}
|
|
11
9
|
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;
|
|
@@ -13,8 +13,8 @@ function register(context) {
|
|
|
13
13
|
for (const cacheData of cache.data) {
|
|
14
14
|
if (!cacheData.list.isIncomplete)
|
|
15
15
|
continue;
|
|
16
|
-
if (cacheData.
|
|
17
|
-
for (const [_, map] of context.documents.getMapsByVirtualFileUri(cacheData.
|
|
16
|
+
if (cacheData.virtualDocumentUri) {
|
|
17
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(cacheData.virtualDocumentUri)) {
|
|
18
18
|
for (const mapped of map.toGeneratedPositions(position, data => !!data.completion)) {
|
|
19
19
|
if (!cacheData.plugin.provideCompletionItems)
|
|
20
20
|
continue;
|
|
@@ -31,9 +31,7 @@ function register(context) {
|
|
|
31
31
|
data: oldItem.data,
|
|
32
32
|
},
|
|
33
33
|
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
|
|
34
|
-
|
|
35
|
-
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
36
|
-
},
|
|
34
|
+
virtualDocumentUri: map.virtualFileDocument.uri,
|
|
37
35
|
});
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -55,7 +53,7 @@ function register(context) {
|
|
|
55
53
|
data: item.data,
|
|
56
54
|
},
|
|
57
55
|
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
|
|
58
|
-
|
|
56
|
+
virtualDocumentUri: undefined,
|
|
59
57
|
};
|
|
60
58
|
});
|
|
61
59
|
}
|
|
@@ -110,14 +108,10 @@ function register(context) {
|
|
|
110
108
|
data: oldItem.data,
|
|
111
109
|
},
|
|
112
110
|
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
113
|
-
|
|
114
|
-
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
115
|
-
}
|
|
111
|
+
virtualDocumentUri: map.virtualFileDocument.uri,
|
|
116
112
|
});
|
|
117
113
|
cache.data.push({
|
|
118
|
-
|
|
119
|
-
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
120
|
-
},
|
|
114
|
+
virtualDocumentUri: map.virtualFileDocument.uri,
|
|
121
115
|
plugin,
|
|
122
116
|
list: completionList,
|
|
123
117
|
});
|
|
@@ -158,11 +152,11 @@ function register(context) {
|
|
|
158
152
|
data: item.data,
|
|
159
153
|
},
|
|
160
154
|
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
161
|
-
|
|
155
|
+
virtualDocumentUri: undefined,
|
|
162
156
|
};
|
|
163
157
|
});
|
|
164
158
|
cache.data.push({
|
|
165
|
-
|
|
159
|
+
virtualDocumentUri: undefined,
|
|
166
160
|
plugin,
|
|
167
161
|
list: completionList,
|
|
168
162
|
});
|
|
@@ -11,8 +11,8 @@ function register(context) {
|
|
|
11
11
|
if (!plugin.resolveCompletionItem)
|
|
12
12
|
return item;
|
|
13
13
|
item = Object.assign(item, data.original);
|
|
14
|
-
if (data.
|
|
15
|
-
for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.
|
|
14
|
+
if (data.virtualDocumentUri) {
|
|
15
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.virtualDocumentUri)) {
|
|
16
16
|
item = await plugin.resolveCompletionItem(item, token);
|
|
17
17
|
item = transformer.asCompletionItem(item, embeddedRange => {
|
|
18
18
|
let range = plugin.resolveEmbeddedRange?.(embeddedRange);
|
|
@@ -47,7 +47,7 @@ function register(context) {
|
|
|
47
47
|
end: { line: _token[0], character: _token[1] + _token[2] },
|
|
48
48
|
}, data => !!data.semanticTokens);
|
|
49
49
|
if (range) {
|
|
50
|
-
return [range.start.line, range.start.character,
|
|
50
|
+
return [range.start.line, range.start.character, range.end.character - range.start.character, _token[3], _token[4]];
|
|
51
51
|
}
|
|
52
52
|
}).filter(common_1.notEmpty), tokens => tokens.flat(), tokens => reportProgress?.(buildTokens(tokens)));
|
|
53
53
|
if (tokens) {
|
package/out/types.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface LanguageServiceOptions {
|
|
|
23
23
|
export interface Commands {
|
|
24
24
|
createShowReferencesCommand(uri: string, position: vscode.Position, locations: vscode.Location[]): vscode.Command | undefined;
|
|
25
25
|
createRenameCommand(uri: string, position: vscode.Position): vscode.Command | undefined;
|
|
26
|
+
createSetSelectionCommand(position: vscode.Position): vscode.Command | undefined;
|
|
26
27
|
}
|
|
27
28
|
export interface LanguageServicePluginContext extends LanguageServiceOptions {
|
|
28
29
|
typescript: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.6",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/language-service"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.4.0-alpha.
|
|
17
|
-
"@volar/source-map": "1.4.0-alpha.
|
|
16
|
+
"@volar/language-core": "1.4.0-alpha.6",
|
|
17
|
+
"@volar/source-map": "1.4.0-alpha.6",
|
|
18
18
|
"typescript-auto-import-cache": "^0.0.1",
|
|
19
19
|
"vscode-html-languageservice": "^5.0.4",
|
|
20
20
|
"vscode-json-languageservice": "^5.2.0",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"vscode-languageserver-textdocument": "^1.0.8",
|
|
23
23
|
"vscode-uri": "^3.0.7"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "e975c5cbd4230afaa97155c9498b8887ab58eec6"
|
|
26
26
|
}
|