@volar/language-service 2.1.6 → 2.2.0-alpha.1
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 +127 -80
- package/lib/types.d.ts +67 -57
- 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
|
@@ -13,9 +13,9 @@ function register(context) {
|
|
|
13
13
|
}
|
|
14
14
|
const recursiveChecker = dedupe.createLocationSet();
|
|
15
15
|
const result = [];
|
|
16
|
-
await
|
|
16
|
+
await withLinkedCode(document, position);
|
|
17
17
|
return result;
|
|
18
|
-
async function
|
|
18
|
+
async function withLinkedCode(document, position) {
|
|
19
19
|
if (!service[1].provideReferences) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
@@ -27,15 +27,19 @@ function register(context) {
|
|
|
27
27
|
for (const reference of references) {
|
|
28
28
|
let foundMirrorPosition = false;
|
|
29
29
|
recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } });
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const decoded = context.decodeEmbeddedDocumentUri(reference.uri);
|
|
31
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
32
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
33
|
+
const linkedCodeMap = virtualCode && sourceScript
|
|
34
|
+
? context.documents.getLinkedCodeMap(virtualCode, sourceScript.id)
|
|
35
|
+
: undefined;
|
|
36
|
+
if (linkedCodeMap) {
|
|
37
|
+
for (const linkedPos of linkedCodeMap.getLinkedCodePositions(reference.range.start)) {
|
|
38
|
+
if (recursiveChecker.has({ uri: linkedCodeMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
35
39
|
continue;
|
|
36
40
|
}
|
|
37
41
|
foundMirrorPosition = true;
|
|
38
|
-
await
|
|
42
|
+
await withLinkedCode(linkedCodeMap.document, linkedPos);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
if (!foundMirrorPosition) {
|
|
@@ -46,7 +50,9 @@ function register(context) {
|
|
|
46
50
|
}, data => {
|
|
47
51
|
const results = [];
|
|
48
52
|
for (const reference of data) {
|
|
49
|
-
const
|
|
53
|
+
const decoded = context.decodeEmbeddedDocumentUri(reference.uri);
|
|
54
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
55
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
50
56
|
if (virtualCode) {
|
|
51
57
|
for (const map of context.documents.getMaps(virtualCode)) {
|
|
52
58
|
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
|
|
@@ -26,9 +26,9 @@ function register(context) {
|
|
|
26
26
|
}
|
|
27
27
|
const recursiveChecker = dedupe.createLocationSet();
|
|
28
28
|
let result;
|
|
29
|
-
await
|
|
29
|
+
await withLinkedCode(document, params.position, params.newName);
|
|
30
30
|
return result;
|
|
31
|
-
async function
|
|
31
|
+
async function withLinkedCode(document, position, newName) {
|
|
32
32
|
if (!service[1].provideRenameEdits) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -49,15 +49,19 @@ function register(context) {
|
|
|
49
49
|
for (const textEdit of textEdits) {
|
|
50
50
|
let foundMirrorPosition = false;
|
|
51
51
|
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const decoded = context.decodeEmbeddedDocumentUri(editUri);
|
|
53
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
54
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
55
|
+
const linkedCodeMap = virtualCode && sourceScript
|
|
56
|
+
? context.documents.getLinkedCodeMap(virtualCode, sourceScript.id)
|
|
57
|
+
: undefined;
|
|
58
|
+
if (linkedCodeMap) {
|
|
59
|
+
for (const linkedPos of linkedCodeMap.getLinkedCodePositions(textEdit.range.start)) {
|
|
60
|
+
if (recursiveChecker.has({ uri: linkedCodeMap.document.uri, range: { start: linkedPos, end: linkedPos } })) {
|
|
57
61
|
continue;
|
|
58
62
|
}
|
|
59
63
|
foundMirrorPosition = true;
|
|
60
|
-
await
|
|
64
|
+
await withLinkedCode(linkedCodeMap.document, linkedPos, newName);
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
if (!foundMirrorPosition) {
|
|
@@ -22,7 +22,9 @@ function register(context) {
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
const symbols = embeddedSymbols.map(symbol => (0, transform_1.transformWorkspaceSymbol)(symbol, loc => {
|
|
25
|
-
const
|
|
25
|
+
const decoded = context.decodeEmbeddedDocumentUri(loc.uri);
|
|
26
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
27
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
26
28
|
if (virtualCode) {
|
|
27
29
|
for (const map of context.documents.getMaps(virtualCode)) {
|
|
28
30
|
const range = map.getSourceRange(loc.range);
|
|
@@ -12,8 +12,10 @@ function register(context) {
|
|
|
12
12
|
return item;
|
|
13
13
|
}
|
|
14
14
|
item = Object.assign(item, data.original);
|
|
15
|
-
if (data.
|
|
16
|
-
const
|
|
15
|
+
if (data.embeddedDocumentUri) {
|
|
16
|
+
const decoded = context.decodeEmbeddedDocumentUri(data.embeddedDocumentUri);
|
|
17
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
18
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
17
19
|
if (virtualCode) {
|
|
18
20
|
for (const map of context.documents.getMaps(virtualCode)) {
|
|
19
21
|
item = await service[1].resolveCompletionItem(item, token);
|
package/lib/languageService.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Language } from '@volar/language-core';
|
|
2
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
import type { ServiceContext, ServiceEnvironment,
|
|
3
|
+
import type { ServiceContext, ServiceEnvironment, LanguageServicePlugin } from './types';
|
|
4
4
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
5
|
-
export declare function createLanguageService(
|
|
5
|
+
export declare function createLanguageService(language: Language, servicePlugins: LanguageServicePlugin[], env: ServiceEnvironment): {
|
|
6
6
|
getTriggerCharacters: () => string[];
|
|
7
7
|
getAutoFormatTriggerCharacters: () => string[];
|
|
8
8
|
getSignatureHelpTriggerCharacters: () => string[];
|
|
@@ -19,7 +19,7 @@ export declare function createLanguageService(languageContext: LanguageContext,
|
|
|
19
19
|
getColorPresentations: (uri: string, color: vscode.Color, range: vscode.Range, token?: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>;
|
|
20
20
|
doValidation: (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
21
21
|
findReferences: (uri: string, position: vscode.Position, referenceContext: vscode.ReferenceContext, token?: vscode.CancellationToken) => Promise<vscode.Location[] | undefined>;
|
|
22
|
-
findFileReferences: (uri: string, token?: vscode.CancellationToken) => import("./types").
|
|
22
|
+
findFileReferences: (uri: string, token?: vscode.CancellationToken) => import("./types").NullableProviderResult<vscode.Location[]>;
|
|
23
23
|
findDefinition: (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
|
24
24
|
findTypeDefinition: (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
|
25
25
|
findImplementations: (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
package/lib/languageService.js
CHANGED
|
@@ -35,8 +35,133 @@ const codeLensResolve = require("./features/resolveCodeLens");
|
|
|
35
35
|
const completionResolve = require("./features/resolveCompletionItem");
|
|
36
36
|
const documentLinkResolve = require("./features/resolveDocumentLink");
|
|
37
37
|
const inlayHintResolve = require("./features/resolveInlayHint");
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
39
|
+
function createLanguageService(language, servicePlugins, env) {
|
|
40
|
+
const documentVersions = new Map();
|
|
41
|
+
const map2DocMap = new WeakMap();
|
|
42
|
+
const mirrorMap2DocMirrorMap = new WeakMap();
|
|
43
|
+
const snapshot2Doc = new WeakMap();
|
|
44
|
+
const embeddedContentScheme = 'volar-embedded-content';
|
|
45
|
+
const context = {
|
|
46
|
+
language,
|
|
47
|
+
documents: {
|
|
48
|
+
get(uri, languageId, snapshot) {
|
|
49
|
+
if (!snapshot2Doc.has(snapshot)) {
|
|
50
|
+
snapshot2Doc.set(snapshot, new Map());
|
|
51
|
+
}
|
|
52
|
+
const map = snapshot2Doc.get(snapshot);
|
|
53
|
+
if (!map.has(uri)) {
|
|
54
|
+
const version = documentVersions.get(uri) ?? 0;
|
|
55
|
+
documentVersions.set(uri, version + 1);
|
|
56
|
+
map.set(uri, vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, version, snapshot.getText(0, snapshot.getLength())));
|
|
57
|
+
}
|
|
58
|
+
return map.get(uri);
|
|
59
|
+
},
|
|
60
|
+
*getMaps(virtualCode) {
|
|
61
|
+
for (const [uri, [snapshot, map]] of context.language.maps.forEach(virtualCode)) {
|
|
62
|
+
if (!map2DocMap.has(map)) {
|
|
63
|
+
const embeddedUri = context.encodeEmbeddedDocumentUri(uri, virtualCode.id);
|
|
64
|
+
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));
|
|
65
|
+
}
|
|
66
|
+
yield map2DocMap.get(map);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
getLinkedCodeMap(virtualCode, sourceScriptId) {
|
|
70
|
+
const map = context.language.linkedCodeMaps.get(virtualCode);
|
|
71
|
+
if (map) {
|
|
72
|
+
if (!mirrorMap2DocMirrorMap.has(map)) {
|
|
73
|
+
const embeddedUri = context.encodeEmbeddedDocumentUri(sourceScriptId, virtualCode.id);
|
|
74
|
+
mirrorMap2DocMirrorMap.set(map, new documents_1.LinkedCodeMapWithDocument(this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map));
|
|
75
|
+
}
|
|
76
|
+
return mirrorMap2DocMirrorMap.get(map);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
env,
|
|
81
|
+
inject: (key, ...args) => {
|
|
82
|
+
for (const service of context.services) {
|
|
83
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const provide = service[1].provide?.[key];
|
|
87
|
+
if (provide) {
|
|
88
|
+
return provide(...args);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
services: [],
|
|
93
|
+
commands: {
|
|
94
|
+
rename: {
|
|
95
|
+
create(uri, position) {
|
|
96
|
+
return {
|
|
97
|
+
title: '',
|
|
98
|
+
command: 'editor.action.rename',
|
|
99
|
+
arguments: [
|
|
100
|
+
uri,
|
|
101
|
+
position,
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
is(command) {
|
|
106
|
+
return command.command === 'editor.action.rename';
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
showReferences: {
|
|
110
|
+
create(uri, position, locations) {
|
|
111
|
+
return {
|
|
112
|
+
title: locations.length === 1 ? '1 reference' : `${locations.length} references`,
|
|
113
|
+
command: 'editor.action.showReferences',
|
|
114
|
+
arguments: [
|
|
115
|
+
uri,
|
|
116
|
+
position,
|
|
117
|
+
locations,
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
is(command) {
|
|
122
|
+
return command.command === 'editor.action.showReferences';
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
setSelection: {
|
|
126
|
+
create(position) {
|
|
127
|
+
return {
|
|
128
|
+
title: '',
|
|
129
|
+
command: 'setSelection',
|
|
130
|
+
arguments: [{
|
|
131
|
+
selection: {
|
|
132
|
+
selectionStartLineNumber: position.line + 1,
|
|
133
|
+
positionLineNumber: position.line + 1,
|
|
134
|
+
selectionStartColumn: position.character + 1,
|
|
135
|
+
positionColumn: position.character + 1,
|
|
136
|
+
},
|
|
137
|
+
}],
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
is(command) {
|
|
141
|
+
return command.command === 'setSelection';
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
disabledEmbeddedDocumentUris: new Set(),
|
|
146
|
+
disabledServicePlugins: new WeakSet(),
|
|
147
|
+
decodeEmbeddedDocumentUri(maybeEmbeddedContentUri) {
|
|
148
|
+
if (maybeEmbeddedContentUri.startsWith(`${embeddedContentScheme}://`)) {
|
|
149
|
+
const trimed = maybeEmbeddedContentUri.substring(`${embeddedContentScheme}://`.length);
|
|
150
|
+
const embeddedCodeId = trimed.substring(0, trimed.indexOf('/'));
|
|
151
|
+
const documentUri = trimed.substring(embeddedCodeId.length + 1);
|
|
152
|
+
return [
|
|
153
|
+
decodeURIComponent(documentUri),
|
|
154
|
+
decodeURIComponent(embeddedCodeId),
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
encodeEmbeddedDocumentUri(documentUri, embeddedContentId) {
|
|
159
|
+
return `${embeddedContentScheme}://${encodeURIComponent(embeddedContentId)}/${encodeURIComponent(documentUri)}`;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
for (const servicePlugin of servicePlugins) {
|
|
163
|
+
context.services.push([servicePlugin, servicePlugin.create(context)]);
|
|
164
|
+
}
|
|
40
165
|
return {
|
|
41
166
|
getTriggerCharacters: () => servicePlugins.map(service => service.triggerCharacters ?? []).flat(),
|
|
42
167
|
getAutoFormatTriggerCharacters: () => servicePlugins.map(service => service.autoFormatTriggerCharacters ?? []).flat(),
|
|
@@ -79,84 +204,6 @@ function createLanguageService(languageContext, servicePlugins, env) {
|
|
|
79
204
|
dispose: () => context.services.forEach(service => service[1].dispose?.()),
|
|
80
205
|
context,
|
|
81
206
|
};
|
|
82
|
-
function createServiceContext() {
|
|
83
|
-
const context = {
|
|
84
|
-
language: languageContext,
|
|
85
|
-
documents: (0, documents_1.createDocumentProvider)(languageContext.files),
|
|
86
|
-
env,
|
|
87
|
-
inject: (key, ...args) => {
|
|
88
|
-
for (const service of context.services) {
|
|
89
|
-
if (context.disabledServicePlugins.has(service[1])) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const provide = service[1].provide?.[key];
|
|
93
|
-
if (provide) {
|
|
94
|
-
return provide(...args);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
throw `No service provide ${key}`;
|
|
98
|
-
},
|
|
99
|
-
services: [],
|
|
100
|
-
commands: {
|
|
101
|
-
rename: {
|
|
102
|
-
create(uri, position) {
|
|
103
|
-
return {
|
|
104
|
-
title: '',
|
|
105
|
-
command: 'editor.action.rename',
|
|
106
|
-
arguments: [
|
|
107
|
-
uri,
|
|
108
|
-
position,
|
|
109
|
-
],
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
is(command) {
|
|
113
|
-
return command.command === 'editor.action.rename';
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
showReferences: {
|
|
117
|
-
create(uri, position, locations) {
|
|
118
|
-
return {
|
|
119
|
-
title: locations.length === 1 ? '1 reference' : `${locations.length} references`,
|
|
120
|
-
command: 'editor.action.showReferences',
|
|
121
|
-
arguments: [
|
|
122
|
-
uri,
|
|
123
|
-
position,
|
|
124
|
-
locations,
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
is(command) {
|
|
129
|
-
return command.command === 'editor.action.showReferences';
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
setSelection: {
|
|
133
|
-
create(position) {
|
|
134
|
-
return {
|
|
135
|
-
title: '',
|
|
136
|
-
command: 'setSelection',
|
|
137
|
-
arguments: [{
|
|
138
|
-
selection: {
|
|
139
|
-
selectionStartLineNumber: position.line + 1,
|
|
140
|
-
positionLineNumber: position.line + 1,
|
|
141
|
-
selectionStartColumn: position.character + 1,
|
|
142
|
-
positionColumn: position.character + 1,
|
|
143
|
-
},
|
|
144
|
-
}],
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
is(command) {
|
|
148
|
-
return command.command === 'setSelection';
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
disabledVirtualFileUris: new Set(),
|
|
153
|
-
disabledServicePlugins: new WeakSet(),
|
|
154
|
-
};
|
|
155
|
-
for (const servicePlugin of servicePlugins) {
|
|
156
|
-
context.services.push([servicePlugin, servicePlugin.create(context)]);
|
|
157
|
-
}
|
|
158
|
-
return context;
|
|
159
|
-
}
|
|
160
207
|
}
|
|
161
208
|
exports.createLanguageService = createLanguageService;
|
|
162
209
|
//# sourceMappingURL=languageService.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Language, SourceScript, VirtualCode } from '@volar/language-core';
|
|
2
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
import type
|
|
4
|
+
import type * as ts from 'typescript';
|
|
5
|
+
import type { LinkedCodeMapWithDocument, SourceMapWithDocuments } from './documents';
|
|
5
6
|
export type * from 'vscode-languageserver-protocol';
|
|
6
7
|
export interface ServiceEnvironment {
|
|
7
8
|
workspaceFolder: string;
|
|
@@ -14,13 +15,13 @@ export interface ServiceEnvironment {
|
|
|
14
15
|
fs?: FileSystem;
|
|
15
16
|
console?: Console;
|
|
16
17
|
getConfiguration?<T>(section: string, scopeUri?: string): Promise<T | undefined>;
|
|
17
|
-
onDidChangeConfiguration?(cb: () => void): vscode.Disposable;
|
|
18
|
+
onDidChangeConfiguration?(cb: (params: vscode.DidChangeConfigurationParams) => void): vscode.Disposable;
|
|
18
19
|
onDidChangeWatchedFiles?(cb: (params: vscode.DidChangeWatchedFilesParams) => void): vscode.Disposable;
|
|
19
20
|
}
|
|
20
21
|
export interface FileSystem {
|
|
21
|
-
stat(uri: string):
|
|
22
|
-
readDirectory(uri: string):
|
|
23
|
-
readFile(uri: string, encoding?: string):
|
|
22
|
+
stat(uri: string): ProviderResult<FileStat | undefined>;
|
|
23
|
+
readDirectory(uri: string): ProviderResult<[string, FileType][]>;
|
|
24
|
+
readFile(uri: string, encoding?: string): ProviderResult<string | undefined>;
|
|
24
25
|
}
|
|
25
26
|
export interface FileStat {
|
|
26
27
|
type: FileType;
|
|
@@ -39,21 +40,30 @@ export interface ServiceCommand<T extends any[]> {
|
|
|
39
40
|
is(value: vscode.Command): boolean;
|
|
40
41
|
}
|
|
41
42
|
export interface ServiceContext {
|
|
42
|
-
language:
|
|
43
|
+
language: Language;
|
|
43
44
|
env: ServiceEnvironment;
|
|
44
|
-
inject<Provide, K extends keyof Provide = keyof Provide>(key: K, ...args: Provide[K] extends (...args: any) => any ? Parameters<Provide[K]> : never): ReturnType<Provide[K] extends (...args: any) => any ? Provide[K] : never
|
|
45
|
+
inject<Provide, K extends keyof Provide = keyof Provide>(key: K, ...args: Provide[K] extends (...args: any) => any ? Parameters<Provide[K]> : never): ReturnType<Provide[K] extends (...args: any) => any ? Provide[K] : never> | undefined;
|
|
45
46
|
commands: {
|
|
46
47
|
showReferences: ServiceCommand<[uri: string, position: vscode.Position, locations: vscode.Location[]]>;
|
|
47
48
|
rename: ServiceCommand<[uri: string, position: vscode.Position]>;
|
|
48
49
|
setSelection: ServiceCommand<[position: vscode.Position]>;
|
|
49
50
|
};
|
|
50
|
-
documents:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
documents: {
|
|
52
|
+
get(uri: string, languageId: string, snapshot: ts.IScriptSnapshot): TextDocument;
|
|
53
|
+
getMaps(virtualCode: VirtualCode): Generator<SourceMapWithDocuments>;
|
|
54
|
+
getLinkedCodeMap(virtualCode: VirtualCode, sourceScriptId: string): LinkedCodeMapWithDocument | undefined;
|
|
55
|
+
};
|
|
56
|
+
services: [LanguageServicePlugin, LanguageServicePluginInstance][];
|
|
57
|
+
disabledEmbeddedDocumentUris: Set<string>;
|
|
58
|
+
disabledServicePlugins: WeakSet<LanguageServicePluginInstance>;
|
|
59
|
+
decodeEmbeddedDocumentUri(maybeEmbeddedUri: string): [
|
|
60
|
+
documentUri: string,
|
|
61
|
+
embeddedCodeId: string
|
|
62
|
+
] | undefined;
|
|
63
|
+
encodeEmbeddedDocumentUri(uri: string, embeededCodeId: string): string;
|
|
54
64
|
}
|
|
55
|
-
export type
|
|
56
|
-
export type
|
|
65
|
+
export type ProviderResult<T> = T | Thenable<T>;
|
|
66
|
+
export type NullableProviderResult<T> = ProviderResult<T | undefined | null>;
|
|
57
67
|
export type SemanticToken = [
|
|
58
68
|
line: number,
|
|
59
69
|
character: number,
|
|
@@ -61,69 +71,69 @@ export type SemanticToken = [
|
|
|
61
71
|
tokenTypes: number,
|
|
62
72
|
tokenModifiers: number
|
|
63
73
|
];
|
|
64
|
-
export interface
|
|
74
|
+
export interface LanguageServicePlugin<P = any> {
|
|
65
75
|
name?: string;
|
|
66
76
|
triggerCharacters?: string[];
|
|
67
77
|
signatureHelpTriggerCharacters?: string[];
|
|
68
78
|
signatureHelpRetriggerCharacters?: string[];
|
|
69
79
|
autoFormatTriggerCharacters?: string[];
|
|
70
|
-
create(context: ServiceContext):
|
|
80
|
+
create(context: ServiceContext): LanguageServicePluginInstance<P>;
|
|
71
81
|
}
|
|
72
82
|
export interface EmbeddedCodeFormattingOptions {
|
|
73
83
|
level: number;
|
|
74
84
|
initialIndentLevel: number;
|
|
75
85
|
}
|
|
76
|
-
export interface
|
|
86
|
+
export interface LanguageServicePluginInstance<P = any> {
|
|
77
87
|
provide?: P;
|
|
78
88
|
isAdditionalCompletion?: boolean;
|
|
79
|
-
provideHover?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
80
|
-
provideDocumentSymbols?(document: TextDocument, token: vscode.CancellationToken):
|
|
81
|
-
provideDocumentHighlights?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
82
|
-
provideLinkedEditingRanges?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
83
|
-
provideDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
84
|
-
provideTypeDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
85
|
-
provideImplementation?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
86
|
-
provideCodeLenses?(document: TextDocument, token: vscode.CancellationToken):
|
|
87
|
-
provideCodeActions?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken):
|
|
88
|
-
provideDocumentFormattingEdits?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions, embeddedCodeContext: EmbeddedCodeFormattingOptions | undefined, token: vscode.CancellationToken):
|
|
89
|
-
provideOnTypeFormattingEdits?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions, embeddedCodeContext: EmbeddedCodeFormattingOptions | undefined, token: vscode.CancellationToken):
|
|
90
|
-
provideDocumentLinks?(document: TextDocument, token: vscode.CancellationToken):
|
|
91
|
-
provideCompletionItems?(document: TextDocument, position: vscode.Position, context: vscode.CompletionContext, token: vscode.CancellationToken):
|
|
92
|
-
provideDocumentColors?(document: TextDocument, token: vscode.CancellationToken):
|
|
93
|
-
provideColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range, token: vscode.CancellationToken):
|
|
94
|
-
provideFoldingRanges?(document: TextDocument, token: vscode.CancellationToken):
|
|
95
|
-
provideSignatureHelp?(document: TextDocument, position: vscode.Position, context: vscode.SignatureHelpContext, token: vscode.CancellationToken):
|
|
96
|
-
provideRenameRange?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
89
|
+
provideHover?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.Hover>;
|
|
90
|
+
provideDocumentSymbols?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.DocumentSymbol[]>;
|
|
91
|
+
provideDocumentHighlights?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.DocumentHighlight[]>;
|
|
92
|
+
provideLinkedEditingRanges?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.LinkedEditingRanges>;
|
|
93
|
+
provideDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.LocationLink[]>;
|
|
94
|
+
provideTypeDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.LocationLink[]>;
|
|
95
|
+
provideImplementation?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.LocationLink[]>;
|
|
96
|
+
provideCodeLenses?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.CodeLens[]>;
|
|
97
|
+
provideCodeActions?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): NullableProviderResult<vscode.CodeAction[]>;
|
|
98
|
+
provideDocumentFormattingEdits?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions, embeddedCodeContext: EmbeddedCodeFormattingOptions | undefined, token: vscode.CancellationToken): NullableProviderResult<vscode.TextEdit[]>;
|
|
99
|
+
provideOnTypeFormattingEdits?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions, embeddedCodeContext: EmbeddedCodeFormattingOptions | undefined, token: vscode.CancellationToken): NullableProviderResult<vscode.TextEdit[]>;
|
|
100
|
+
provideDocumentLinks?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.DocumentLink[]>;
|
|
101
|
+
provideCompletionItems?(document: TextDocument, position: vscode.Position, context: vscode.CompletionContext, token: vscode.CancellationToken): NullableProviderResult<vscode.CompletionList>;
|
|
102
|
+
provideDocumentColors?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.ColorInformation[]>;
|
|
103
|
+
provideColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range, token: vscode.CancellationToken): NullableProviderResult<vscode.ColorPresentation[]>;
|
|
104
|
+
provideFoldingRanges?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.FoldingRange[]>;
|
|
105
|
+
provideSignatureHelp?(document: TextDocument, position: vscode.Position, context: vscode.SignatureHelpContext, token: vscode.CancellationToken): NullableProviderResult<vscode.SignatureHelp>;
|
|
106
|
+
provideRenameRange?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.Range | {
|
|
97
107
|
range: vscode.Range;
|
|
98
108
|
placeholder: string;
|
|
99
109
|
} | {
|
|
100
110
|
message: string;
|
|
101
111
|
}>;
|
|
102
|
-
provideRenameEdits?(document: TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken):
|
|
103
|
-
provideReferences?(document: TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken):
|
|
104
|
-
provideSelectionRanges?(document: TextDocument, positions: vscode.Position[], token: vscode.CancellationToken):
|
|
105
|
-
provideInlayHints?(document: TextDocument, range: vscode.Range, token: vscode.CancellationToken):
|
|
106
|
-
provideCallHierarchyItems?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken):
|
|
107
|
-
provideCallHierarchyIncomingCalls?(item: vscode.CallHierarchyItem, token: vscode.CancellationToken):
|
|
108
|
-
provideCallHierarchyOutgoingCalls?(item: vscode.CallHierarchyItem, token: vscode.CancellationToken):
|
|
109
|
-
provideDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken):
|
|
110
|
-
provideWorkspaceSymbols?(query: string, token: vscode.CancellationToken):
|
|
111
|
-
provideDiagnostics?(document: TextDocument, token: vscode.CancellationToken):
|
|
112
|
-
provideSemanticDiagnostics?(document: TextDocument, token: vscode.CancellationToken):
|
|
113
|
-
provideFileReferences?(document: TextDocument, token: vscode.CancellationToken):
|
|
114
|
-
provideReferencesCodeLensRanges?(document: TextDocument, token: vscode.CancellationToken):
|
|
112
|
+
provideRenameEdits?(document: TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): NullableProviderResult<vscode.WorkspaceEdit>;
|
|
113
|
+
provideReferences?(document: TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): NullableProviderResult<vscode.Location[]>;
|
|
114
|
+
provideSelectionRanges?(document: TextDocument, positions: vscode.Position[], token: vscode.CancellationToken): NullableProviderResult<vscode.SelectionRange[]>;
|
|
115
|
+
provideInlayHints?(document: TextDocument, range: vscode.Range, token: vscode.CancellationToken): NullableProviderResult<vscode.InlayHint[]>;
|
|
116
|
+
provideCallHierarchyItems?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableProviderResult<vscode.CallHierarchyItem[]>;
|
|
117
|
+
provideCallHierarchyIncomingCalls?(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): ProviderResult<vscode.CallHierarchyIncomingCall[]>;
|
|
118
|
+
provideCallHierarchyOutgoingCalls?(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): ProviderResult<vscode.CallHierarchyOutgoingCall[]>;
|
|
119
|
+
provideDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken): NullableProviderResult<SemanticToken[]>;
|
|
120
|
+
provideWorkspaceSymbols?(query: string, token: vscode.CancellationToken): NullableProviderResult<vscode.WorkspaceSymbol[]>;
|
|
121
|
+
provideDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Diagnostic[]>;
|
|
122
|
+
provideSemanticDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Diagnostic[]>;
|
|
123
|
+
provideFileReferences?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Location[]>;
|
|
124
|
+
provideReferencesCodeLensRanges?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Range[]>;
|
|
115
125
|
provideAutoInsertionEdit?(document: TextDocument, position: vscode.Position, lastChange: {
|
|
116
126
|
range: vscode.Range;
|
|
117
127
|
text: string;
|
|
118
|
-
}, token: vscode.CancellationToken):
|
|
119
|
-
provideFileRenameEdits?(oldUri: string, newUri: string, token: vscode.CancellationToken):
|
|
120
|
-
provideDocumentDropEdits?(document: TextDocument, position: vscode.Position, dataTransfer: Map<string, DataTransferItem>, token: vscode.CancellationToken):
|
|
121
|
-
resolveCodeLens?(codeLens: vscode.CodeLens, token: vscode.CancellationToken):
|
|
122
|
-
resolveCodeAction?(codeAction: vscode.CodeAction, token: vscode.CancellationToken):
|
|
123
|
-
resolveCompletionItem?(item: vscode.CompletionItem, token: vscode.CancellationToken):
|
|
124
|
-
resolveDocumentLink?(link: vscode.DocumentLink, token: vscode.CancellationToken):
|
|
125
|
-
resolveInlayHint?(inlayHint: vscode.InlayHint, token: vscode.CancellationToken):
|
|
126
|
-
resolveEmbeddedCodeFormattingOptions?(
|
|
128
|
+
}, token: vscode.CancellationToken): NullableProviderResult<string | vscode.TextEdit>;
|
|
129
|
+
provideFileRenameEdits?(oldUri: string, newUri: string, token: vscode.CancellationToken): NullableProviderResult<vscode.WorkspaceEdit>;
|
|
130
|
+
provideDocumentDropEdits?(document: TextDocument, position: vscode.Position, dataTransfer: Map<string, DataTransferItem>, token: vscode.CancellationToken): NullableProviderResult<DocumentDropEdit>;
|
|
131
|
+
resolveCodeLens?(codeLens: vscode.CodeLens, token: vscode.CancellationToken): ProviderResult<vscode.CodeLens>;
|
|
132
|
+
resolveCodeAction?(codeAction: vscode.CodeAction, token: vscode.CancellationToken): ProviderResult<vscode.CodeAction>;
|
|
133
|
+
resolveCompletionItem?(item: vscode.CompletionItem, token: vscode.CancellationToken): ProviderResult<vscode.CompletionItem>;
|
|
134
|
+
resolveDocumentLink?(link: vscode.DocumentLink, token: vscode.CancellationToken): ProviderResult<vscode.DocumentLink>;
|
|
135
|
+
resolveInlayHint?(inlayHint: vscode.InlayHint, token: vscode.CancellationToken): ProviderResult<vscode.InlayHint>;
|
|
136
|
+
resolveEmbeddedCodeFormattingOptions?(sourceScript: SourceScript, embeddedCode: VirtualCode, options: EmbeddedCodeFormattingOptions, token: vscode.CancellationToken): NullableProviderResult<EmbeddedCodeFormattingOptions>;
|
|
127
137
|
transformCompletionItem?(item: vscode.CompletionItem): vscode.CompletionItem | undefined;
|
|
128
138
|
transformCodeAction?(item: vscode.CodeAction): vscode.CodeAction | undefined;
|
|
129
139
|
dispose?(): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CodeInformation, VirtualCode } from '@volar/language-core';
|
|
2
2
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
3
|
import type { SourceMapWithDocuments } from '../documents';
|
|
4
|
-
import type { ServiceContext,
|
|
5
|
-
export declare function documentFeatureWorker<T>(context: ServiceContext, uri: string, valid: (map: SourceMapWithDocuments<CodeInformation>) => boolean, worker: (service: [
|
|
6
|
-
export declare function languageFeatureWorker<T, K>(context: ServiceContext, uri: string, getReadDocParams: () => K, eachVirtualDocParams: (map: SourceMapWithDocuments<CodeInformation>) => Generator<K>, worker: (service: [
|
|
4
|
+
import type { ServiceContext, LanguageServicePluginInstance, LanguageServicePlugin } from '../types';
|
|
5
|
+
export declare function documentFeatureWorker<T>(context: ServiceContext, uri: string, valid: (map: SourceMapWithDocuments<CodeInformation>) => boolean, worker: (service: [LanguageServicePlugin, LanguageServicePluginInstance], document: TextDocument) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: SourceMapWithDocuments<CodeInformation>) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
6
|
+
export declare function languageFeatureWorker<T, K>(context: ServiceContext, uri: string, getReadDocParams: () => K, eachVirtualDocParams: (map: SourceMapWithDocuments<CodeInformation>) => Generator<K>, worker: (service: [LanguageServicePlugin, LanguageServicePluginInstance], document: TextDocument, params: K, map?: SourceMapWithDocuments<CodeInformation>) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: SourceMapWithDocuments<CodeInformation>) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
7
7
|
export declare function safeCall<T>(cb: () => Thenable<T> | T, errorMsg?: string): Promise<T | undefined>;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function forEachEmbeddedDocument(context: ServiceContext, sourceScriptId: string, current: VirtualCode): Generator<SourceMapWithDocuments<CodeInformation>>;
|
|
9
9
|
export declare function getEmbeddedFilesByLevel(context: ServiceContext, sourceFileUri: string, rootFile: VirtualCode, level: number): VirtualCode[];
|