@volar/language-service 2.0.0-alpha.8 → 2.0.0-alpha.9
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/features/provideCompletionItems.js +6 -2
- package/lib/features/provideDiagnostics.js +3 -0
- package/lib/features/provideDocumentFormattingEdits.js +7 -15
- package/lib/features/provideFileRenameEdits.js +3 -0
- package/lib/features/provideWorkspaceSymbols.js +3 -0
- package/lib/languageService.js +5 -0
- package/lib/types.d.ts +3 -0
- package/lib/utils/dedupe.d.ts +1 -1
- package/lib/utils/featureWorkers.d.ts +1 -0
- package/lib/utils/featureWorkers.js +24 -5
- package/package.json +3 -3
|
@@ -75,7 +75,9 @@ function register(context) {
|
|
|
75
75
|
let isFirstMapping = true;
|
|
76
76
|
if (rootVirtualFile) {
|
|
77
77
|
await (0, featureWorkers_1.visitEmbedded)(context, rootVirtualFile, async (_, map) => {
|
|
78
|
-
const services = [...context.services]
|
|
78
|
+
const services = [...context.services]
|
|
79
|
+
.filter(service => !context.disabledServicePlugins.has(service[1]))
|
|
80
|
+
.sort((a, b) => sortServices(a[1], b[1]));
|
|
79
81
|
let _data;
|
|
80
82
|
for (const mapped of map.getGeneratedPositions(position, data => {
|
|
81
83
|
_data = data;
|
|
@@ -129,7 +131,9 @@ function register(context) {
|
|
|
129
131
|
}
|
|
130
132
|
if (sourceFile) {
|
|
131
133
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
132
|
-
const services = [...context.services]
|
|
134
|
+
const services = [...context.services]
|
|
135
|
+
.filter(service => !context.disabledServicePlugins.has(service[1]))
|
|
136
|
+
.sort((a, b) => sortServices(a[1], b[1]));
|
|
133
137
|
for (const service of services) {
|
|
134
138
|
if (token.isCancellationRequested)
|
|
135
139
|
break;
|
|
@@ -139,6 +139,9 @@ function register(context) {
|
|
|
139
139
|
exports.errorMarkups[uri] = [];
|
|
140
140
|
for (const error of errors) {
|
|
141
141
|
for (const service of context.services) {
|
|
142
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
142
145
|
const markup = await service[1].provideDiagnosticMarkupContent?.(error, token);
|
|
143
146
|
if (markup) {
|
|
144
147
|
exports.errorMarkups[uri].push({ error, markup });
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.register = void 0;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const common_1 = require("../utils/common");
|
|
7
|
-
const cancellation_1 = require("../utils/cancellation");
|
|
8
6
|
const documents_1 = require("../documents");
|
|
7
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
8
|
+
const common_1 = require("../utils/common");
|
|
9
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
9
10
|
function register(context) {
|
|
10
11
|
let fakeVersion = 0;
|
|
11
12
|
return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
|
|
@@ -28,7 +29,7 @@ function register(context) {
|
|
|
28
29
|
const originalDocument = document;
|
|
29
30
|
let level = 0;
|
|
30
31
|
while (true) {
|
|
31
|
-
const embeddedFiles = getEmbeddedFilesByLevel(tempVirtualFile, level++);
|
|
32
|
+
const embeddedFiles = (0, featureWorkers_1.getEmbeddedFilesByLevel)(context, tempVirtualFile, level++);
|
|
32
33
|
if (embeddedFiles.length === 0)
|
|
33
34
|
break;
|
|
34
35
|
let edits = [];
|
|
@@ -154,21 +155,12 @@ function register(context) {
|
|
|
154
155
|
newText: document.getText(),
|
|
155
156
|
};
|
|
156
157
|
return [textEdit];
|
|
157
|
-
function getEmbeddedFilesByLevel(rootFile, level) {
|
|
158
|
-
const embeddedFilesByLevel = [[rootFile]];
|
|
159
|
-
while (true) {
|
|
160
|
-
if (embeddedFilesByLevel.length > level)
|
|
161
|
-
return embeddedFilesByLevel[level];
|
|
162
|
-
let nextLevel = [];
|
|
163
|
-
for (const file of embeddedFilesByLevel[embeddedFilesByLevel.length - 1]) {
|
|
164
|
-
nextLevel = nextLevel.concat(file.embeddedFiles);
|
|
165
|
-
}
|
|
166
|
-
embeddedFilesByLevel.push(nextLevel);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
158
|
async function tryFormat(document, range, ch) {
|
|
170
159
|
let formatRange = range;
|
|
171
160
|
for (const service of context.services) {
|
|
161
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
172
164
|
if (token.isCancellationRequested)
|
|
173
165
|
break;
|
|
174
166
|
let edits;
|
|
@@ -22,6 +22,9 @@ function register(context) {
|
|
|
22
22
|
newUri += tsExt;
|
|
23
23
|
}
|
|
24
24
|
for (const service of context.services) {
|
|
25
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
25
28
|
if (token.isCancellationRequested)
|
|
26
29
|
break;
|
|
27
30
|
if (!service[1].provideFileRenameEdits)
|
|
@@ -8,6 +8,9 @@ function register(context) {
|
|
|
8
8
|
return async (query, token = cancellation_1.NoneCancellationToken) => {
|
|
9
9
|
const symbolsList = [];
|
|
10
10
|
for (const service of context.services) {
|
|
11
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
11
14
|
if (token.isCancellationRequested) {
|
|
12
15
|
break;
|
|
13
16
|
}
|
package/lib/languageService.js
CHANGED
|
@@ -86,6 +86,9 @@ function createLanguageService(language, servicePlugins, env) {
|
|
|
86
86
|
language: language,
|
|
87
87
|
inject: (key, ...args) => {
|
|
88
88
|
for (const service of context.services) {
|
|
89
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
89
92
|
const provide = service[1].provide?.[key];
|
|
90
93
|
if (provide) {
|
|
91
94
|
return provide(...args);
|
|
@@ -147,6 +150,8 @@ function createLanguageService(language, servicePlugins, env) {
|
|
|
147
150
|
}
|
|
148
151
|
},
|
|
149
152
|
},
|
|
153
|
+
disabledVirtualFiles: new Set(),
|
|
154
|
+
disabledServicePlugins: new WeakSet(),
|
|
150
155
|
};
|
|
151
156
|
for (const servicePlugin of servicePlugins) {
|
|
152
157
|
context.services.push([servicePlugin, servicePlugin.create(context)]);
|
package/lib/types.d.ts
CHANGED
|
@@ -59,11 +59,14 @@ export interface ServiceContext {
|
|
|
59
59
|
};
|
|
60
60
|
documents: DocumentProvider;
|
|
61
61
|
services: [ServicePlugin, ServicePluginInstance][];
|
|
62
|
+
disabledVirtualFiles: Set<string>;
|
|
63
|
+
disabledServicePlugins: WeakSet<ServicePluginInstance>;
|
|
62
64
|
}
|
|
63
65
|
export type Result<T> = T | Thenable<T>;
|
|
64
66
|
export type NullableResult<T> = Result<T | undefined | null>;
|
|
65
67
|
export type SemanticToken = [number, number, number, number, number];
|
|
66
68
|
export interface ServicePlugin {
|
|
69
|
+
name?: string;
|
|
67
70
|
triggerCharacters?: string[];
|
|
68
71
|
signatureHelpTriggerCharacters?: string[];
|
|
69
72
|
signatureHelpRetriggerCharacters?: string[];
|
package/lib/utils/dedupe.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function createLocationSet(): {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function withCodeAction<T extends vscode.CodeAction>(items: T[]): T[];
|
|
7
7
|
export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
|
|
8
|
-
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.
|
|
8
|
+
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.CreateFile | vscode.TextDocumentEdit | vscode.RenameFile | vscode.DeleteFile)[];
|
|
9
9
|
export declare function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[];
|
|
10
10
|
export declare function withLocations<T extends vscode.Location>(items: T[]): T[];
|
|
11
11
|
export declare function withLocationLinks<T extends vscode.LocationLink>(items: T[]): T[];
|
|
@@ -6,3 +6,4 @@ export declare function documentFeatureWorker<T>(context: ServiceContext, uri: s
|
|
|
6
6
|
export declare function languageFeatureWorker<T, K>(context: ServiceContext, uri: string, getReadDocParams: () => K, eachVirtualDocParams: (map: SourceMapWithDocuments<CodeInformation>) => Generator<K>, worker: (service: [ServicePlugin, ServicePluginInstance], 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
8
|
export declare function visitEmbedded(context: ServiceContext, current: VirtualFile, cb: (file: VirtualFile, sourceMap: SourceMapWithDocuments<CodeInformation>) => Promise<boolean>, rootFile?: VirtualFile): Promise<boolean>;
|
|
9
|
+
export declare function getEmbeddedFilesByLevel(context: ServiceContext, rootFile: VirtualFile, level: number): VirtualFile[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.visitEmbedded = exports.safeCall = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
3
|
+
exports.getEmbeddedFilesByLevel = exports.visitEmbedded = exports.safeCall = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
4
4
|
async function documentFeatureWorker(context, uri, valid, worker, transformResult, combineResult) {
|
|
5
5
|
return languageFeatureWorker(context, uri, () => void 0, function* (map) {
|
|
6
6
|
if (valid(map)) {
|
|
@@ -18,6 +18,9 @@ async function languageFeatureWorker(context, uri, getReadDocParams, eachVirtual
|
|
|
18
18
|
await visitEmbedded(context, sourceFile.virtualFile[0], async (_file, map) => {
|
|
19
19
|
for (const mappedArg of eachVirtualDocParams(map)) {
|
|
20
20
|
for (const [serviceId, service] of Object.entries(context.services)) {
|
|
21
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
21
24
|
const embeddedResult = await safeCall(() => worker(service, map.virtualFileDocument, mappedArg, map), 'service ' + serviceId + ' crashed on ' + map.virtualFileDocument.uri);
|
|
22
25
|
if (!embeddedResult)
|
|
23
26
|
continue;
|
|
@@ -36,6 +39,9 @@ async function languageFeatureWorker(context, uri, getReadDocParams, eachVirtual
|
|
|
36
39
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
37
40
|
const params = getReadDocParams();
|
|
38
41
|
for (const [serviceId, service] of Object.entries(context.services)) {
|
|
42
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
39
45
|
const embeddedResult = await safeCall(() => worker(service, document, params, undefined), 'service ' + serviceId + ' crashed on ' + uri);
|
|
40
46
|
if (!embeddedResult)
|
|
41
47
|
continue;
|
|
@@ -72,13 +78,26 @@ async function visitEmbedded(context, current, cb, rootFile = current) {
|
|
|
72
78
|
}
|
|
73
79
|
for (const map of context.documents.getMaps(current)) {
|
|
74
80
|
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(map.sourceFileDocument.uri));
|
|
75
|
-
if (sourceFile?.virtualFile?.[0] === rootFile
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
if (sourceFile?.virtualFile?.[0] === rootFile
|
|
82
|
+
&& !context.disabledVirtualFiles.has(current.fileName)
|
|
83
|
+
&& !await cb(current, map)) {
|
|
84
|
+
return false;
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
return true;
|
|
82
88
|
}
|
|
83
89
|
exports.visitEmbedded = visitEmbedded;
|
|
90
|
+
function getEmbeddedFilesByLevel(context, rootFile, level) {
|
|
91
|
+
const embeddedFilesByLevel = [[rootFile]];
|
|
92
|
+
while (true) {
|
|
93
|
+
if (embeddedFilesByLevel.length > level)
|
|
94
|
+
return embeddedFilesByLevel[level];
|
|
95
|
+
let nextLevel = [];
|
|
96
|
+
for (const file of embeddedFilesByLevel[embeddedFilesByLevel.length - 1]) {
|
|
97
|
+
nextLevel = nextLevel.concat(file.embeddedFiles.filter(file => !context.disabledVirtualFiles.has(file.fileName)));
|
|
98
|
+
}
|
|
99
|
+
embeddedFilesByLevel.push(nextLevel);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.getEmbeddedFilesByLevel = getEmbeddedFilesByLevel;
|
|
84
103
|
//# sourceMappingURL=featureWorkers.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.9",
|
|
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.0.0-alpha.
|
|
15
|
+
"@volar/language-core": "2.0.0-alpha.9",
|
|
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": "dcd70c78b0b6901901dc0e68223e34dd922f5fdc"
|
|
21
21
|
}
|