@volar/language-service 1.1.0-alpha.2 → 1.2.0-alpha.2
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.d.ts +3 -11
- package/out/baseLanguageService.js +32 -23
- package/out/documentFeatures/format.js +1 -1
- package/out/languageFeatures/callHierarchy.d.ts +2 -2
- package/out/languageFeatures/callHierarchy.js +16 -17
- package/out/languageFeatures/codeActionResolve.js +3 -5
- package/out/languageFeatures/codeActions.d.ts +2 -2
- package/out/languageFeatures/codeActions.js +14 -4
- package/out/languageFeatures/codeLens.d.ts +4 -4
- package/out/languageFeatures/codeLens.js +18 -10
- package/out/languageFeatures/codeLensResolve.js +10 -4
- package/out/languageFeatures/complete.d.ts +2 -2
- package/out/languageFeatures/complete.js +39 -20
- package/out/languageFeatures/completeResolve.js +3 -5
- package/out/languageFeatures/executeCommand.d.ts +1 -1
- package/out/languageFeatures/executeCommand.js +1 -1
- package/out/languageFeatures/fileRename.js +1 -1
- package/out/languageFeatures/validation.d.ts +6 -0
- package/out/languageFeatures/validation.js +120 -39
- package/out/languageFeatures/workspaceSymbols.js +1 -1
- package/out/types.d.ts +36 -5
- package/out/types.js +0 -1
- package/out/utils/featureWorkers.d.ts +2 -1
- package/out/utils/featureWorkers.js +87 -5
- package/package.json +6 -6
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageServiceHost } from '@volar/language-core';
|
|
2
2
|
import * as executeCommand from './languageFeatures/executeCommand';
|
|
3
|
-
import {
|
|
3
|
+
import { LanguageServiceConfig, LanguageServiceRuntimeContext } from './types';
|
|
4
4
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
5
5
|
import type * as _ from 'vscode-languageserver-protocol';
|
|
6
6
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
7
|
-
export declare function
|
|
8
|
-
host: LanguageServiceHost;
|
|
9
|
-
context: ReturnType<typeof createLanguageContext>;
|
|
10
|
-
getPlugins(): (LanguageServicePlugin | LanguageServicePluginInstance)[];
|
|
11
|
-
env: LanguageServiceRuntimeContext['env'];
|
|
12
|
-
documentRegistry: ts.DocumentRegistry | undefined;
|
|
13
|
-
getLanguageService: () => LanguageService;
|
|
14
|
-
}): LanguageServiceRuntimeContext<LanguageServiceHost>;
|
|
15
|
-
export declare function createLanguageService(context: LanguageServiceRuntimeContext): {
|
|
7
|
+
export declare function createLanguageService(host: LanguageServiceHost, config: LanguageServiceConfig, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): {
|
|
16
8
|
format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
|
|
17
9
|
ch: string;
|
|
18
10
|
position: _.Position;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.createLanguageService =
|
|
2
|
+
exports.createLanguageService = void 0;
|
|
3
|
+
const language_core_1 = require("@volar/language-core");
|
|
3
4
|
const shared = require("@volar/shared");
|
|
4
5
|
const tsFaster = require("@volar/typescript-faster");
|
|
5
6
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
@@ -34,42 +35,52 @@ const foldingRanges = require("./documentFeatures/foldingRanges");
|
|
|
34
35
|
const format = require("./documentFeatures/format");
|
|
35
36
|
const linkedEditingRanges = require("./documentFeatures/linkedEditingRanges");
|
|
36
37
|
const selectionRanges = require("./documentFeatures/selectionRanges");
|
|
37
|
-
function
|
|
38
|
+
function createLanguageService(host, config, env, documentRegistry) {
|
|
39
|
+
var _a;
|
|
40
|
+
const languageContext = (0, language_core_1.createLanguageContext)(host, Object.values((_a = config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
|
|
41
|
+
const context = createLanguageServiceContext(host, languageContext, config, env, () => languageService, documentRegistry);
|
|
42
|
+
const languageService = createLanguageServiceBase(context);
|
|
43
|
+
return languageService;
|
|
44
|
+
}
|
|
45
|
+
exports.createLanguageService = createLanguageService;
|
|
46
|
+
function createLanguageServiceContext(host, languageContext, config, env, getLanguageService, documentRegistry) {
|
|
38
47
|
var _a, _b;
|
|
39
|
-
const ts = (
|
|
40
|
-
const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(
|
|
48
|
+
const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
49
|
+
const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
|
|
41
50
|
if (ts && tsLs) {
|
|
42
|
-
tsFaster.decorate(ts,
|
|
51
|
+
tsFaster.decorate(ts, languageContext.typescript.languageServiceHost, tsLs);
|
|
43
52
|
}
|
|
44
53
|
let plugins;
|
|
45
|
-
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(
|
|
54
|
+
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(languageContext.virtualFiles);
|
|
46
55
|
const documents = new WeakMap();
|
|
47
56
|
const documentVersions = new Map();
|
|
48
57
|
const context = {
|
|
49
|
-
host
|
|
50
|
-
core:
|
|
51
|
-
env:
|
|
58
|
+
host,
|
|
59
|
+
core: languageContext,
|
|
60
|
+
env: env,
|
|
52
61
|
get plugins() {
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
53
63
|
if (!plugins) {
|
|
54
|
-
plugins =
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
plugins = {}; // avoid infinite loop
|
|
65
|
+
for (let pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
|
|
66
|
+
const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
|
|
57
67
|
if (plugin instanceof Function) {
|
|
58
|
-
const _plugin = plugin(this,
|
|
59
|
-
(
|
|
60
|
-
|
|
68
|
+
const _plugin = plugin(this, getLanguageService());
|
|
69
|
+
(_c = _plugin.setup) === null || _c === void 0 ? void 0 : _c.call(_plugin, this);
|
|
70
|
+
plugins[pluginId] = _plugin;
|
|
61
71
|
}
|
|
62
72
|
else {
|
|
63
|
-
(
|
|
64
|
-
|
|
73
|
+
(_e = (_d = plugin).setup) === null || _e === void 0 ? void 0 : _e.call(_d, this);
|
|
74
|
+
plugins[pluginId] = plugin;
|
|
65
75
|
}
|
|
66
|
-
}
|
|
76
|
+
}
|
|
67
77
|
}
|
|
68
78
|
return plugins;
|
|
69
79
|
},
|
|
80
|
+
rules: (_b = config.rules) !== null && _b !== void 0 ? _b : {},
|
|
70
81
|
typescript: ts && tsLs ? {
|
|
71
82
|
module: ts,
|
|
72
|
-
languageServiceHost:
|
|
83
|
+
languageServiceHost: languageContext.typescript.languageServiceHost,
|
|
73
84
|
languageService: tsLs,
|
|
74
85
|
} : undefined,
|
|
75
86
|
documents: textDocumentMapper,
|
|
@@ -79,7 +90,7 @@ function createLanguageServiceContext(options) {
|
|
|
79
90
|
function getTextDocument(uri) {
|
|
80
91
|
var _a;
|
|
81
92
|
const fileName = shared.uriToFileName(uri);
|
|
82
|
-
const scriptSnapshot =
|
|
93
|
+
const scriptSnapshot = host.getScriptSnapshot(fileName);
|
|
83
94
|
if (scriptSnapshot) {
|
|
84
95
|
let document = documents.get(scriptSnapshot);
|
|
85
96
|
if (!document) {
|
|
@@ -92,8 +103,7 @@ function createLanguageServiceContext(options) {
|
|
|
92
103
|
}
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
function createLanguageService(context) {
|
|
106
|
+
function createLanguageServiceBase(context) {
|
|
97
107
|
return {
|
|
98
108
|
format: format.register(context),
|
|
99
109
|
getFoldingRanges: foldingRanges.register(context),
|
|
@@ -131,5 +141,4 @@ function createLanguageService(context) {
|
|
|
131
141
|
context,
|
|
132
142
|
};
|
|
133
143
|
}
|
|
134
|
-
exports.createLanguageService = createLanguageService;
|
|
135
144
|
//# sourceMappingURL=baseLanguageService.js.map
|
|
@@ -155,7 +155,7 @@ function register(context) {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
for (const plugin of context.plugins) {
|
|
158
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
159
159
|
let edits;
|
|
160
160
|
let recover;
|
|
161
161
|
if (formatDocument !== document && isTsDocument(formatDocument) && context.typescript) {
|
|
@@ -2,8 +2,8 @@ import type * as vscode from 'vscode-languageserver-protocol';
|
|
|
2
2
|
import type { LanguageServiceRuntimeContext } from '../types';
|
|
3
3
|
export interface PluginCallHierarchyData {
|
|
4
4
|
uri: string;
|
|
5
|
-
|
|
6
|
-
pluginId:
|
|
5
|
+
original: Pick<vscode.CallHierarchyItem, 'data'>;
|
|
6
|
+
pluginId: string;
|
|
7
7
|
map: {
|
|
8
8
|
embeddedDocumentUri: string;
|
|
9
9
|
} | undefined;
|
|
@@ -19,16 +19,19 @@ function register(context) {
|
|
|
19
19
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
var _a;
|
|
21
21
|
const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
items === null || items === void 0 ? void 0 : items.forEach(item => {
|
|
23
|
+
item.data = {
|
|
24
|
+
uri,
|
|
25
|
+
original: {
|
|
26
|
+
data: item.data,
|
|
27
|
+
},
|
|
28
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
29
|
+
map: map ? {
|
|
30
|
+
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
31
|
+
} : undefined,
|
|
32
|
+
};
|
|
31
33
|
});
|
|
34
|
+
return items;
|
|
32
35
|
}), (data, sourceMap) => !sourceMap ? data : data
|
|
33
36
|
.map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; })
|
|
34
37
|
.filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat()));
|
|
@@ -39,14 +42,12 @@ function register(context) {
|
|
|
39
42
|
let incomingItems = [];
|
|
40
43
|
if (data) {
|
|
41
44
|
const plugin = context.plugins[data.pluginId];
|
|
42
|
-
if (!plugin)
|
|
43
|
-
return incomingItems;
|
|
44
45
|
if (!plugin.callHierarchy)
|
|
45
46
|
return incomingItems;
|
|
46
|
-
|
|
47
|
+
Object.assign(item, data.original);
|
|
47
48
|
if (data.map) {
|
|
48
49
|
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
49
|
-
const _calls = yield plugin.callHierarchy.onIncomingCalls(
|
|
50
|
+
const _calls = yield plugin.callHierarchy.onIncomingCalls(item);
|
|
50
51
|
for (const _call of _calls) {
|
|
51
52
|
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
|
|
52
53
|
if (!calls)
|
|
@@ -80,14 +81,12 @@ function register(context) {
|
|
|
80
81
|
let items = [];
|
|
81
82
|
if (data) {
|
|
82
83
|
const plugin = context.plugins[data.pluginId];
|
|
83
|
-
if (!plugin)
|
|
84
|
-
return items;
|
|
85
84
|
if (!plugin.callHierarchy)
|
|
86
85
|
return items;
|
|
87
|
-
|
|
86
|
+
Object.assign(item, data.original);
|
|
88
87
|
if (data.map) {
|
|
89
88
|
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
90
|
-
const _calls = yield plugin.callHierarchy.onOutgoingCalls(
|
|
89
|
+
const _calls = yield plugin.callHierarchy.onOutgoingCalls(item);
|
|
91
90
|
for (const call of _calls) {
|
|
92
91
|
const calls = transformCallHierarchyItem(call.to, call.fromRanges);
|
|
93
92
|
if (!calls)
|
|
@@ -16,14 +16,12 @@ function register(context) {
|
|
|
16
16
|
const data = item.data;
|
|
17
17
|
if (data) {
|
|
18
18
|
const plugin = context.plugins[data.pluginId];
|
|
19
|
-
if (!plugin)
|
|
20
|
-
return item;
|
|
21
19
|
if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve))
|
|
22
20
|
return item;
|
|
23
|
-
|
|
21
|
+
Object.assign(item, data.original);
|
|
24
22
|
if (data.map) {
|
|
25
23
|
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
26
|
-
const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(
|
|
24
|
+
const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(item));
|
|
27
25
|
if (resolvedItem.edit) {
|
|
28
26
|
const edit = (0, rename_1.embeddedEditToSourceEdit)(resolvedItem.edit, context.documents);
|
|
29
27
|
if (edit) {
|
|
@@ -34,7 +32,7 @@ function register(context) {
|
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
else {
|
|
37
|
-
return yield ((_c = plugin.codeAction) === null || _c === void 0 ? void 0 : _c.resolve(
|
|
35
|
+
return yield ((_c = plugin.codeAction) === null || _c === void 0 ? void 0 : _c.resolve(item));
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
return item;
|
|
@@ -2,8 +2,8 @@ import * as vscode from 'vscode-languageserver-protocol';
|
|
|
2
2
|
import type { LanguageServiceRuntimeContext } from '../types';
|
|
3
3
|
export interface PluginCodeActionData {
|
|
4
4
|
uri: string;
|
|
5
|
-
|
|
6
|
-
pluginId:
|
|
5
|
+
original: Pick<vscode.CodeAction, 'data'>;
|
|
6
|
+
pluginId: string;
|
|
7
7
|
map: {
|
|
8
8
|
embeddedDocumentUri: string;
|
|
9
9
|
} | undefined;
|
|
@@ -53,14 +53,24 @@ function register(context) {
|
|
|
53
53
|
}];
|
|
54
54
|
}
|
|
55
55
|
return [];
|
|
56
|
-
}, (plugin, document,
|
|
56
|
+
}, (plugin, document, { range, codeActionContext }, map) => __awaiter(this, void 0, void 0, function* () {
|
|
57
57
|
var _a, _b;
|
|
58
|
-
const
|
|
58
|
+
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
59
|
+
const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
|
|
60
|
+
const data = diagnostic.data;
|
|
61
|
+
return (data === null || data === void 0 ? void 0 : data.type) === 'plugin' && (data === null || data === void 0 ? void 0 : data.pluginOrRuleId) === pluginId;
|
|
62
|
+
}).map(diagnostic => {
|
|
63
|
+
const data = diagnostic.data;
|
|
64
|
+
return Object.assign(Object.assign({}, diagnostic), data.original);
|
|
65
|
+
});
|
|
66
|
+
const codeActions = yield ((_b = (_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics })));
|
|
59
67
|
return codeActions === null || codeActions === void 0 ? void 0 : codeActions.map(_codeAction => {
|
|
60
68
|
return Object.assign(Object.assign({}, _codeAction), { data: {
|
|
61
69
|
uri,
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
original: {
|
|
71
|
+
data: _codeAction.data,
|
|
72
|
+
},
|
|
73
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
64
74
|
map: map ? {
|
|
65
75
|
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
66
76
|
} : undefined,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
1
|
import type { LanguageServiceRuntimeContext } from '../types';
|
|
2
|
+
import type * as _ from 'vscode-languageserver-protocol';
|
|
3
3
|
export interface PluginCodeLensData {
|
|
4
4
|
uri: string;
|
|
5
|
-
|
|
6
|
-
pluginId:
|
|
5
|
+
original: Pick<_.CodeLens, 'data'>;
|
|
6
|
+
pluginId: string;
|
|
7
7
|
}
|
|
8
|
-
export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<
|
|
8
|
+
export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<_.CodeLens[]>;
|
|
@@ -18,16 +18,24 @@ function register(context) {
|
|
|
18
18
|
return (_a = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
var _b, _c;
|
|
20
20
|
const codeLens = yield ((_c = (_b = plugin.codeLens) === null || _b === void 0 ? void 0 : _b.on) === null || _c === void 0 ? void 0 : _c.call(_b, document));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
21
|
+
codeLens === null || codeLens === void 0 ? void 0 : codeLens.forEach(codeLens => {
|
|
22
|
+
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
23
|
+
if (codeLens.command) {
|
|
24
|
+
codeLens.command = {
|
|
25
|
+
title: codeLens.command.title,
|
|
26
|
+
command: executeCommand_1.executePluginCommand,
|
|
27
|
+
arguments: [uri, pluginId, codeLens.command],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
codeLens.data = {
|
|
31
|
+
uri,
|
|
32
|
+
original: {
|
|
33
|
+
data: codeLens.data,
|
|
34
|
+
},
|
|
35
|
+
pluginId,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return codeLens;
|
|
31
39
|
}), (data, map) => data.map(codeLens => {
|
|
32
40
|
if (!map)
|
|
33
41
|
return codeLens;
|
|
@@ -16,12 +16,18 @@ function register(context) {
|
|
|
16
16
|
const data = item.data;
|
|
17
17
|
if (data) {
|
|
18
18
|
const plugin = context.plugins[data.pluginId];
|
|
19
|
-
if (!plugin)
|
|
20
|
-
return item;
|
|
21
19
|
if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve))
|
|
22
20
|
return item;
|
|
23
|
-
|
|
24
|
-
item =
|
|
21
|
+
Object.assign(item, data.original);
|
|
22
|
+
item = yield plugin.codeLens.resolve(item);
|
|
23
|
+
if (item.command) {
|
|
24
|
+
item.command = {
|
|
25
|
+
title: item.command.title,
|
|
26
|
+
command: executeCommand_1.executePluginCommand,
|
|
27
|
+
arguments: [data.uri, data.pluginId, item.command],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// item.range already transformed in codeLens request
|
|
25
31
|
}
|
|
26
32
|
return item;
|
|
27
33
|
});
|
|
@@ -2,8 +2,8 @@ import * as vscode from 'vscode-languageserver-protocol';
|
|
|
2
2
|
import type { LanguageServiceRuntimeContext } from '../types';
|
|
3
3
|
export interface PluginCompletionData {
|
|
4
4
|
uri: string;
|
|
5
|
-
|
|
6
|
-
pluginId:
|
|
5
|
+
original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
|
|
6
|
+
pluginId: string;
|
|
7
7
|
map: {
|
|
8
8
|
embeddedDocumentUri: string;
|
|
9
9
|
} | undefined;
|
|
@@ -34,8 +34,12 @@ function register(context) {
|
|
|
34
34
|
}
|
|
35
35
|
cacheData.list = transformer.asCompletionList(embeddedCompletionList, range => map.toSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
|
|
36
36
|
uri,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
original: {
|
|
38
|
+
additionalTextEdits: oldItem.additionalTextEdits,
|
|
39
|
+
textEdit: oldItem.textEdit,
|
|
40
|
+
data: oldItem.data,
|
|
41
|
+
},
|
|
42
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
|
|
39
43
|
map: {
|
|
40
44
|
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
41
45
|
},
|
|
@@ -51,12 +55,18 @@ function register(context) {
|
|
|
51
55
|
cacheData.list.isIncomplete = false;
|
|
52
56
|
continue;
|
|
53
57
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
completionList.items.forEach(item => {
|
|
59
|
+
item.data = {
|
|
60
|
+
uri,
|
|
61
|
+
original: {
|
|
62
|
+
additionalTextEdits: item.additionalTextEdits,
|
|
63
|
+
textEdit: item.textEdit,
|
|
64
|
+
data: item.data,
|
|
65
|
+
},
|
|
66
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
|
|
67
|
+
map: undefined,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
60
70
|
}
|
|
61
71
|
}
|
|
62
72
|
}
|
|
@@ -72,7 +82,7 @@ function register(context) {
|
|
|
72
82
|
if (rootFile) {
|
|
73
83
|
yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () {
|
|
74
84
|
var _f, _g;
|
|
75
|
-
const plugins = context.plugins.sort(sortPlugins);
|
|
85
|
+
const plugins = Object.values(context.plugins).sort(sortPlugins);
|
|
76
86
|
let _data;
|
|
77
87
|
for (const mapped of map.toGeneratedPositions(position, data => {
|
|
78
88
|
_data = data;
|
|
@@ -102,8 +112,12 @@ function register(context) {
|
|
|
102
112
|
}
|
|
103
113
|
const completionList = transformer.asCompletionList(embeddedCompletionList, range => map.toSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
|
|
104
114
|
uri,
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
original: {
|
|
116
|
+
additionalTextEdits: oldItem.additionalTextEdits,
|
|
117
|
+
textEdit: oldItem.textEdit,
|
|
118
|
+
data: oldItem.data,
|
|
119
|
+
},
|
|
120
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
107
121
|
map: {
|
|
108
122
|
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
109
123
|
}
|
|
@@ -122,7 +136,7 @@ function register(context) {
|
|
|
122
136
|
}));
|
|
123
137
|
}
|
|
124
138
|
if (document = context.getTextDocument(uri)) {
|
|
125
|
-
const plugins = context.plugins.sort(sortPlugins);
|
|
139
|
+
const plugins = Object.values(context.plugins).sort(sortPlugins);
|
|
126
140
|
for (const plugin of plugins) {
|
|
127
141
|
if (!((_d = plugin.complete) === null || _d === void 0 ? void 0 : _d.on))
|
|
128
142
|
continue;
|
|
@@ -141,17 +155,22 @@ function register(context) {
|
|
|
141
155
|
if (!plugin.complete.isAdditional) {
|
|
142
156
|
cache.mainCompletion = { documentUri: document.uri };
|
|
143
157
|
}
|
|
158
|
+
completionList.items.forEach(item => {
|
|
159
|
+
item.data = {
|
|
160
|
+
uri,
|
|
161
|
+
original: {
|
|
162
|
+
additionalTextEdits: item.additionalTextEdits,
|
|
163
|
+
textEdit: item.textEdit,
|
|
164
|
+
data: item.data,
|
|
165
|
+
},
|
|
166
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
167
|
+
map: undefined,
|
|
168
|
+
};
|
|
169
|
+
});
|
|
144
170
|
cache.data.push({
|
|
145
171
|
map: undefined,
|
|
146
172
|
plugin,
|
|
147
|
-
list:
|
|
148
|
-
return Object.assign(Object.assign({}, item), { data: {
|
|
149
|
-
uri,
|
|
150
|
-
originalItem: item,
|
|
151
|
-
pluginId: context.plugins.indexOf(plugin),
|
|
152
|
-
sourceMap: undefined,
|
|
153
|
-
} });
|
|
154
|
-
}) }),
|
|
173
|
+
list: completionList,
|
|
155
174
|
});
|
|
156
175
|
}
|
|
157
176
|
}
|
|
@@ -16,14 +16,12 @@ function register(context) {
|
|
|
16
16
|
const data = item.data;
|
|
17
17
|
if (data) {
|
|
18
18
|
const plugin = context.plugins[data.pluginId];
|
|
19
|
-
if (!plugin)
|
|
20
|
-
return item;
|
|
21
19
|
if (!((_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.resolve))
|
|
22
20
|
return item;
|
|
23
|
-
|
|
21
|
+
item = Object.assign(item, data.original);
|
|
24
22
|
if (data.map) {
|
|
25
23
|
for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) {
|
|
26
|
-
const resolvedItem = yield plugin.complete.resolve(
|
|
24
|
+
const resolvedItem = yield plugin.complete.resolve(item);
|
|
27
25
|
// fix https://github.com/johnsoncodehk/volar/issues/916
|
|
28
26
|
if (resolvedItem.additionalTextEdits) {
|
|
29
27
|
for (const edit of resolvedItem.additionalTextEdits) {
|
|
@@ -45,7 +43,7 @@ function register(context) {
|
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
else {
|
|
48
|
-
item = yield plugin.complete.resolve(
|
|
46
|
+
item = yield plugin.complete.resolve(item);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
// TODO: monkey fix import ts file icon
|
|
@@ -5,7 +5,7 @@ export declare const executePluginCommand: string;
|
|
|
5
5
|
export type ExecutePluginCommandArgs = [
|
|
6
6
|
string,
|
|
7
7
|
// uri
|
|
8
|
-
|
|
8
|
+
string | undefined,
|
|
9
9
|
vscode.Command
|
|
10
10
|
];
|
|
11
11
|
export declare function register(context: LanguageServiceRuntimeContext): (command: string, args: ExecutePluginCommandArgs, executeCommandContext: ExecuteCommandContext) => Promise<void>;
|
|
@@ -21,7 +21,7 @@ function register(context) {
|
|
|
21
21
|
yield ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.doExecuteCommand) === null || _a === void 0 ? void 0 : _a.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
for (const plugin of context.plugins) {
|
|
24
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
25
25
|
yield ((_b = plugin.doExecuteCommand) === null || _b === void 0 ? void 0 : _b.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -29,7 +29,7 @@ function register(context) {
|
|
|
29
29
|
oldUri += tsExt;
|
|
30
30
|
newUri += tsExt;
|
|
31
31
|
}
|
|
32
|
-
for (const plugin of context.plugins) {
|
|
32
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
33
33
|
if (!plugin.doFileRename)
|
|
34
34
|
continue;
|
|
35
35
|
const workspaceEdit = yield plugin.doFileRename(oldUri, newUri);
|
|
@@ -4,4 +4,10 @@ export declare function updateRange(range: vscode.Range, change: {
|
|
|
4
4
|
range: vscode.Range;
|
|
5
5
|
newEnd: vscode.Position;
|
|
6
6
|
}): vscode.Range | undefined;
|
|
7
|
+
export interface PluginDiagnosticData {
|
|
8
|
+
uri: string;
|
|
9
|
+
original: Pick<vscode.Diagnostic, 'data'>;
|
|
10
|
+
type: 'plugin' | 'rule';
|
|
11
|
+
pluginOrRuleId: string;
|
|
12
|
+
}
|
|
7
13
|
export declare function register(context: LanguageServiceRuntimeContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.register = exports.updateRange = void 0;
|
|
12
12
|
const shared = require("@volar/shared");
|
|
13
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
14
13
|
const dedupe = require("../utils/dedupe");
|
|
15
14
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
16
15
|
function updateRange(range, change) {
|
|
@@ -86,32 +85,39 @@ function updatePosition(position, change, isEnd) {
|
|
|
86
85
|
return false;
|
|
87
86
|
}
|
|
88
87
|
function register(context) {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const lastResponses = new Map();
|
|
89
|
+
const cacheMaps = {
|
|
90
|
+
semantic: new Map(),
|
|
91
|
+
declaration: new Map(),
|
|
92
|
+
syntactic: new Map(),
|
|
93
|
+
suggestion: new Map(),
|
|
94
|
+
semantic_rules: new Map(),
|
|
95
|
+
syntactic_rules: new Map(),
|
|
96
|
+
formatic_rules: new Map(),
|
|
97
|
+
};
|
|
95
98
|
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
|
|
96
99
|
var _a;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const lastResponse = (_a = lastResponses.get(uri)) !== null && _a !== void 0 ? _a : lastResponses.set(uri, {
|
|
101
|
+
semantic: { errors: [] },
|
|
102
|
+
declaration: { errors: [] },
|
|
103
|
+
suggestion: { errors: [] },
|
|
104
|
+
syntactic: { errors: [] },
|
|
105
|
+
semantic_rules: { errors: [] },
|
|
106
|
+
syntactic_rules: { errors: [] },
|
|
107
|
+
formatic_rules: { errors: [] },
|
|
103
108
|
}).get(uri);
|
|
104
109
|
const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
|
|
105
|
-
const newDocument =
|
|
106
|
-
let
|
|
110
|
+
const newDocument = context.getTextDocument(uri);
|
|
111
|
+
let updateCacheRangeFailed = false;
|
|
107
112
|
let errorsUpdated = false;
|
|
108
113
|
let lastCheckCancelAt = 0;
|
|
109
|
-
for (const
|
|
110
|
-
const oldSnapshot =
|
|
114
|
+
for (const cache of Object.values(lastResponse)) {
|
|
115
|
+
const oldSnapshot = cache.snapshot;
|
|
116
|
+
const oldDocument = cache.document;
|
|
111
117
|
const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
cache.snapshot = newSnapshot;
|
|
119
|
+
cache.document = newDocument;
|
|
120
|
+
if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
|
|
115
121
|
const changeRange = {
|
|
116
122
|
range: {
|
|
117
123
|
start: oldDocument.positionAt(change.span.start),
|
|
@@ -119,32 +125,96 @@ function register(context) {
|
|
|
119
125
|
},
|
|
120
126
|
newEnd: newDocument.positionAt(change.span.start + change.newLength),
|
|
121
127
|
};
|
|
122
|
-
for (const error of
|
|
128
|
+
for (const error of cache.errors) {
|
|
123
129
|
if (!updateRange(error.range, changeRange)) {
|
|
124
|
-
|
|
130
|
+
updateCacheRangeFailed = true;
|
|
125
131
|
break;
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
|
-
yield
|
|
136
|
+
yield lintWorker('onFormat', cacheMaps.formatic_rules, lastResponse.formatic_rules);
|
|
131
137
|
doResponse();
|
|
132
|
-
yield
|
|
138
|
+
yield lintWorker('onSyntax', cacheMaps.syntactic_rules, lastResponse.syntactic_rules);
|
|
133
139
|
doResponse();
|
|
134
|
-
yield worker('
|
|
140
|
+
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
135
141
|
doResponse();
|
|
136
|
-
yield worker('
|
|
137
|
-
|
|
142
|
+
yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion);
|
|
143
|
+
doResponse();
|
|
144
|
+
yield lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules);
|
|
145
|
+
doResponse();
|
|
146
|
+
yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic);
|
|
147
|
+
doResponse();
|
|
148
|
+
yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration);
|
|
149
|
+
return collectErrors();
|
|
138
150
|
function doResponse() {
|
|
139
|
-
if (errorsUpdated && !
|
|
140
|
-
response === null || response === void 0 ? void 0 : response(
|
|
151
|
+
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
152
|
+
response === null || response === void 0 ? void 0 : response(collectErrors());
|
|
141
153
|
errorsUpdated = false;
|
|
142
154
|
}
|
|
143
155
|
}
|
|
144
|
-
function
|
|
145
|
-
return Object.values(
|
|
156
|
+
function collectErrors() {
|
|
157
|
+
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
146
158
|
}
|
|
147
|
-
function
|
|
159
|
+
function lintWorker(api, cacheMap, cache) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const result = yield (0, featureWorkers_1.ruleWorker)(context, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
var _a, _b, _c, _d;
|
|
163
|
+
if (token) {
|
|
164
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
165
|
+
yield shared.sleep(5); // wait for LSP event polling
|
|
166
|
+
lastCheckCancelAt = Date.now();
|
|
167
|
+
}
|
|
168
|
+
if (token.isCancellationRequested) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const pluginCache = (_a = cacheMap.get(ruleName)) !== null && _a !== void 0 ? _a : cacheMap.set(ruleName, new Map()).get(ruleName);
|
|
173
|
+
const cache = pluginCache.get(ruleCtx.document.uri);
|
|
174
|
+
const tsProjectVersion = (api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
175
|
+
if (api === 'onSemantic') {
|
|
176
|
+
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
177
|
+
return cache.errors;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
if (cache && cache.documentVersion === ruleCtx.document.version) {
|
|
182
|
+
return cache.errors;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const reportResults = [];
|
|
186
|
+
ruleCtx.report = (error, ...fixes) => {
|
|
187
|
+
error.source || (error.source = 'rules');
|
|
188
|
+
error.code || (error.code = ruleCtx.ruleId);
|
|
189
|
+
reportResults.push([error, ...fixes]);
|
|
190
|
+
};
|
|
191
|
+
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
|
|
192
|
+
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
193
|
+
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
194
|
+
error.data = {
|
|
195
|
+
uri,
|
|
196
|
+
type: 'rule',
|
|
197
|
+
pluginOrRuleId: ruleCtx.ruleId,
|
|
198
|
+
original: {
|
|
199
|
+
data: error.data,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
errorsUpdated = true;
|
|
204
|
+
pluginCache.set(ruleCtx.document.uri, {
|
|
205
|
+
documentVersion: ruleCtx.document.version,
|
|
206
|
+
errors,
|
|
207
|
+
tsProjectVersion,
|
|
208
|
+
});
|
|
209
|
+
return errors;
|
|
210
|
+
}), transformErrorRange, arr => arr.flat());
|
|
211
|
+
if (result) {
|
|
212
|
+
cache.errors = result;
|
|
213
|
+
cache.snapshot = newSnapshot;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function worker(api, cacheMap, cache) {
|
|
148
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
219
|
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
150
220
|
if (file.capabilities.diagnostic) {
|
|
@@ -157,14 +227,15 @@ function register(context) {
|
|
|
157
227
|
yield shared.sleep(5); // wait for LSP event polling
|
|
158
228
|
lastCheckCancelAt = Date.now();
|
|
159
229
|
}
|
|
160
|
-
if (token.isCancellationRequested)
|
|
230
|
+
if (token.isCancellationRequested) {
|
|
161
231
|
return;
|
|
232
|
+
}
|
|
162
233
|
}
|
|
163
|
-
const pluginId = context.plugins.
|
|
234
|
+
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
164
235
|
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
165
236
|
const cache = pluginCache.get(document.uri);
|
|
166
|
-
const tsProjectVersion = (
|
|
167
|
-
if (
|
|
237
|
+
const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
238
|
+
if (api === 'onDeclaration' || api === 'onSemantic') {
|
|
168
239
|
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
169
240
|
return cache.errors;
|
|
170
241
|
}
|
|
@@ -174,7 +245,17 @@ function register(context) {
|
|
|
174
245
|
return cache.errors;
|
|
175
246
|
}
|
|
176
247
|
}
|
|
177
|
-
const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[
|
|
248
|
+
const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[api]) === null || _e === void 0 ? void 0 : _e.call(_d, document));
|
|
249
|
+
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
250
|
+
error.data = {
|
|
251
|
+
uri,
|
|
252
|
+
type: 'plugin',
|
|
253
|
+
pluginOrRuleId: pluginId,
|
|
254
|
+
original: {
|
|
255
|
+
data: error.data,
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
});
|
|
178
259
|
errorsUpdated = true;
|
|
179
260
|
pluginCache.set(document.uri, {
|
|
180
261
|
documentVersion: document.version,
|
|
@@ -182,7 +263,7 @@ function register(context) {
|
|
|
182
263
|
tsProjectVersion,
|
|
183
264
|
});
|
|
184
265
|
return errors;
|
|
185
|
-
}),
|
|
266
|
+
}), transformErrorRange, arr => dedupe.withDiagnostics(arr.flat()));
|
|
186
267
|
if (result) {
|
|
187
268
|
cache.errors = result;
|
|
188
269
|
cache.snapshot = newSnapshot;
|
|
@@ -190,7 +271,7 @@ function register(context) {
|
|
|
190
271
|
});
|
|
191
272
|
}
|
|
192
273
|
});
|
|
193
|
-
function transformErrorRange(
|
|
274
|
+
function transformErrorRange(errors, map) {
|
|
194
275
|
const result = [];
|
|
195
276
|
for (const error of errors) {
|
|
196
277
|
// clone it to avoid modify cache
|
|
@@ -14,7 +14,7 @@ const vscode = require("vscode-languageserver-protocol");
|
|
|
14
14
|
function register(context) {
|
|
15
15
|
return (query) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const symbolsList = [];
|
|
17
|
-
for (const plugin of context.plugins) {
|
|
17
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
18
18
|
if (!plugin.findWorkspaceSymbols)
|
|
19
19
|
continue;
|
|
20
20
|
const embeddedSymbols = yield plugin.findWorkspaceSymbols(query);
|
package/out/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { LanguageContext, LanguageServiceHost } from '@volar/language-core';
|
|
1
|
+
import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core';
|
|
2
|
+
import { LanguageService } from '@volar/language-service';
|
|
2
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
4
|
import type { DocumentContext, FileSystemProvider } from 'vscode-html-languageservice';
|
|
4
5
|
import type { SchemaRequestService } from 'vscode-json-languageservice';
|
|
@@ -6,7 +7,6 @@ import type * as vscode from 'vscode-languageserver-protocol';
|
|
|
6
7
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
7
8
|
import { URI } from 'vscode-uri';
|
|
8
9
|
import { DocumentsAndSourceMaps } from './documents';
|
|
9
|
-
import { LanguageService } from '@volar/language-service';
|
|
10
10
|
export * from 'vscode-languageserver-protocol';
|
|
11
11
|
export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost = LanguageServiceHost> {
|
|
12
12
|
typescript: {
|
|
@@ -28,7 +28,13 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
|
|
|
28
28
|
/** @private */
|
|
29
29
|
documents: DocumentsAndSourceMaps;
|
|
30
30
|
/** @private */
|
|
31
|
-
plugins:
|
|
31
|
+
plugins: {
|
|
32
|
+
[id: string]: LanguageServicePluginInstance;
|
|
33
|
+
};
|
|
34
|
+
/** @private */
|
|
35
|
+
rules: {
|
|
36
|
+
[id: string]: Rule | undefined;
|
|
37
|
+
};
|
|
32
38
|
/** @private */
|
|
33
39
|
getTextDocument(uri: string): TextDocument | undefined;
|
|
34
40
|
}
|
|
@@ -58,10 +64,13 @@ export interface ExecuteCommandContext {
|
|
|
58
64
|
}): Promise<void>;
|
|
59
65
|
applyEdit(paramOrEdit: vscode.ApplyWorkspaceEditParams | vscode.WorkspaceEdit): Promise<vscode.ApplyWorkspaceEditResult>;
|
|
60
66
|
}
|
|
61
|
-
export
|
|
67
|
+
export interface LanguageServicePlugin<T = {}> {
|
|
68
|
+
(context: LanguageServiceRuntimeContext, service: LanguageService): LanguageServicePluginInstance & T;
|
|
69
|
+
}
|
|
62
70
|
export interface LanguageServicePluginInstance {
|
|
63
71
|
setup?(context: LanguageServiceRuntimeContext): void;
|
|
64
72
|
validation?: {
|
|
73
|
+
resolveRuleContext?(context: RuleContext): void;
|
|
65
74
|
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
66
75
|
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
67
76
|
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
@@ -76,7 +85,7 @@ export interface LanguageServicePluginInstance {
|
|
|
76
85
|
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.SymbolInformation[]>;
|
|
77
86
|
findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>;
|
|
78
87
|
findWorkspaceSymbols?(query: string): NullableResult<vscode.SymbolInformation[]>;
|
|
79
|
-
doExecuteCommand?(command: string, args: any[], context: ExecuteCommandContext): NotNullableResult<void>;
|
|
88
|
+
doExecuteCommand?(command: string, args: any[] | undefined, context: ExecuteCommandContext): NotNullableResult<void>;
|
|
80
89
|
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
|
|
81
90
|
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
|
|
82
91
|
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
|
|
@@ -129,3 +138,25 @@ export interface LanguageServicePluginInstance {
|
|
|
129
138
|
*/
|
|
130
139
|
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
|
|
131
140
|
}
|
|
141
|
+
export interface Rule {
|
|
142
|
+
onFormat?(ctx: RuleContext): void;
|
|
143
|
+
onSyntax?(ctx: RuleContext): void;
|
|
144
|
+
onSemantic?(ctx: RuleContext): void;
|
|
145
|
+
}
|
|
146
|
+
export interface RuleContext {
|
|
147
|
+
ruleId: string;
|
|
148
|
+
document: TextDocument;
|
|
149
|
+
report(error: vscode.Diagnostic, ...fixes: {
|
|
150
|
+
kinds?: string[];
|
|
151
|
+
getCodeActions(): NullableResult<vscode.CodeAction[]>;
|
|
152
|
+
resolveCodeAction?(codeAction: vscode.CodeAction): NotNullableResult<vscode.CodeAction>;
|
|
153
|
+
}[]): void;
|
|
154
|
+
}
|
|
155
|
+
export interface LanguageServiceConfig {
|
|
156
|
+
languages?: ConfigValue<LanguageModule>;
|
|
157
|
+
plugins?: ConfigValue<LanguageServicePlugin>;
|
|
158
|
+
rules?: ConfigValue<Rule>;
|
|
159
|
+
}
|
|
160
|
+
type ConfigValue<T> = {
|
|
161
|
+
[id: string]: T | undefined;
|
|
162
|
+
};
|
package/out/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
import type { LanguageServicePluginInstance, LanguageServiceRuntimeContext } from '../types';
|
|
2
|
+
import type { LanguageServicePluginInstance, LanguageServiceRuntimeContext, Rule, RuleContext } from '../types';
|
|
3
3
|
import { FileRangeCapabilities, VirtualFile } from '@volar/language-service';
|
|
4
4
|
import { SourceMapWithDocuments } from '../documents';
|
|
5
5
|
export declare function documentFeatureWorker<T>(context: LanguageServiceRuntimeContext, uri: string, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (plugin: LanguageServicePluginInstance, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
6
6
|
export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (plugin: LanguageServicePluginInstance, document: TextDocument, arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined, file: VirtualFile | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
7
|
+
export declare function ruleWorker<T>(context: LanguageServiceRuntimeContext, uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleName: string, rule: Rule, ruleCtx: RuleContext) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
@@ -8,13 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
11
|
+
exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
12
12
|
const definePlugin_1 = require("./definePlugin");
|
|
13
13
|
function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
return languageFeatureWorker(context, uri,
|
|
15
|
+
return languageFeatureWorker(context, uri, undefined, (_, map, file) => {
|
|
16
16
|
if (isValidSourceMap(file, map)) {
|
|
17
|
-
return [
|
|
17
|
+
return [undefined];
|
|
18
18
|
}
|
|
19
19
|
return [];
|
|
20
20
|
}, worker, transform, combineResult);
|
|
@@ -30,7 +30,7 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
30
30
|
if (virtualFile) {
|
|
31
31
|
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
for (const mappedArg of transformArg(arg, map, file)) {
|
|
33
|
-
for (const plugin of context.plugins) {
|
|
33
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
34
34
|
const embeddedResult = yield worker(plugin, map.virtualFileDocument, mappedArg, map, file);
|
|
35
35
|
if (!embeddedResult)
|
|
36
36
|
continue;
|
|
@@ -50,7 +50,7 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
50
50
|
}));
|
|
51
51
|
}
|
|
52
52
|
else if (document) {
|
|
53
|
-
for (const plugin of context.plugins) {
|
|
53
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
54
54
|
const embeddedResult = yield worker(plugin, document, arg, undefined, undefined);
|
|
55
55
|
if (!embeddedResult)
|
|
56
56
|
continue;
|
|
@@ -75,4 +75,86 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
exports.languageFeatureWorker = languageFeatureWorker;
|
|
78
|
+
function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const document = context.getTextDocument(uri);
|
|
82
|
+
const virtualFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root;
|
|
83
|
+
let results = [];
|
|
84
|
+
if (virtualFile) {
|
|
85
|
+
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
var _d, _e;
|
|
87
|
+
if (!isValidSourceMap(file)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
const ruleCtx = {
|
|
91
|
+
ruleId: '',
|
|
92
|
+
document: map.virtualFileDocument,
|
|
93
|
+
report: () => { },
|
|
94
|
+
};
|
|
95
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
96
|
+
(_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d.resolveRuleContext) === null || _e === void 0 ? void 0 : _e.call(_d, ruleCtx);
|
|
97
|
+
}
|
|
98
|
+
for (const ruleName in context.rules) {
|
|
99
|
+
const rule = context.rules[ruleName];
|
|
100
|
+
if (!rule) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
ruleCtx.ruleId = ruleName;
|
|
104
|
+
const embeddedResult = yield worker(ruleName, rule, ruleCtx);
|
|
105
|
+
if (!embeddedResult)
|
|
106
|
+
continue;
|
|
107
|
+
const result = transform(embeddedResult, map);
|
|
108
|
+
if (!result)
|
|
109
|
+
continue;
|
|
110
|
+
results.push(result);
|
|
111
|
+
if (!combineResult)
|
|
112
|
+
return false;
|
|
113
|
+
const isEmptyArray = Array.isArray(result) && result.length === 0;
|
|
114
|
+
if (reportProgress && !isEmptyArray) {
|
|
115
|
+
reportProgress(combineResult(results));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
else if (document) {
|
|
122
|
+
const ruleCtx = {
|
|
123
|
+
ruleId: '',
|
|
124
|
+
document,
|
|
125
|
+
report: () => { },
|
|
126
|
+
};
|
|
127
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
128
|
+
(_c = (_b = plugin.validation) === null || _b === void 0 ? void 0 : _b.resolveRuleContext) === null || _c === void 0 ? void 0 : _c.call(_b, ruleCtx);
|
|
129
|
+
}
|
|
130
|
+
for (const ruleName in context.rules) {
|
|
131
|
+
const rule = context.rules[ruleName];
|
|
132
|
+
if (!rule) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
ruleCtx.ruleId = ruleName;
|
|
136
|
+
const embeddedResult = yield worker(ruleName, rule, ruleCtx);
|
|
137
|
+
if (!embeddedResult)
|
|
138
|
+
continue;
|
|
139
|
+
const result = transform(embeddedResult, undefined);
|
|
140
|
+
if (!result)
|
|
141
|
+
continue;
|
|
142
|
+
results.push(result);
|
|
143
|
+
if (!combineResult)
|
|
144
|
+
break;
|
|
145
|
+
const isEmptyArray = Array.isArray(result) && result.length === 0;
|
|
146
|
+
if (reportProgress && !isEmptyArray) {
|
|
147
|
+
reportProgress(combineResult(results));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (combineResult && results.length > 0) {
|
|
152
|
+
return combineResult(results);
|
|
153
|
+
}
|
|
154
|
+
else if (results.length > 0) {
|
|
155
|
+
return results[0];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.ruleWorker = ruleWorker;
|
|
78
160
|
//# sourceMappingURL=featureWorkers.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.2",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"directory": "packages/language-service"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.
|
|
17
|
-
"@volar/shared": "1.
|
|
18
|
-
"@volar/source-map": "1.
|
|
19
|
-
"@volar/typescript-faster": "1.
|
|
16
|
+
"@volar/language-core": "1.2.0-alpha.2",
|
|
17
|
+
"@volar/shared": "1.2.0-alpha.2",
|
|
18
|
+
"@volar/source-map": "1.2.0-alpha.2",
|
|
19
|
+
"@volar/typescript-faster": "1.2.0-alpha.2",
|
|
20
20
|
"vscode-html-languageservice": "^5.0.3",
|
|
21
21
|
"vscode-json-languageservice": "^5.1.3",
|
|
22
22
|
"vscode-languageserver-protocol": "^3.17.2",
|
|
23
23
|
"vscode-languageserver-textdocument": "^1.0.8",
|
|
24
24
|
"vscode-uri": "^3.0.7"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "cc4da3728cbbc0933c9957c298d0a36090fbedc1"
|
|
27
27
|
}
|