@volar/language-service 1.2.0-alpha.3 → 1.2.0-alpha.5
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LanguageServiceHost } from '@volar/language-core';
|
|
2
2
|
import * as executeCommand from './languageFeatures/executeCommand';
|
|
3
|
-
import {
|
|
3
|
+
import { Config, 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 createLanguageService(host: LanguageServiceHost, config:
|
|
7
|
+
export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): {
|
|
8
8
|
format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
|
|
9
9
|
ch: string;
|
|
10
10
|
position: _.Position;
|
|
@@ -61,18 +61,16 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
|
|
|
61
61
|
core: languageContext,
|
|
62
62
|
env: env,
|
|
63
63
|
get plugins() {
|
|
64
|
-
var _a, _b
|
|
64
|
+
var _a, _b;
|
|
65
65
|
if (!plugins) {
|
|
66
66
|
plugins = {}; // avoid infinite loop
|
|
67
|
-
for (
|
|
67
|
+
for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
|
|
68
68
|
const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
|
|
69
69
|
if (plugin instanceof Function) {
|
|
70
70
|
const _plugin = plugin(this, getLanguageService());
|
|
71
|
-
(_c = _plugin.setup) === null || _c === void 0 ? void 0 : _c.call(_plugin, this);
|
|
72
71
|
plugins[pluginId] = _plugin;
|
|
73
72
|
}
|
|
74
|
-
else {
|
|
75
|
-
(_e = (_d = plugin).setup) === null || _e === void 0 ? void 0 : _e.call(_d, this);
|
|
73
|
+
else if (plugin) {
|
|
76
74
|
plugins[pluginId] = plugin;
|
|
77
75
|
}
|
|
78
76
|
}
|
|
@@ -189,7 +189,14 @@ function register(context) {
|
|
|
189
189
|
error.code || (error.code = ruleCtx.ruleId);
|
|
190
190
|
reportResults.push([error, ...fixes]);
|
|
191
191
|
};
|
|
192
|
-
|
|
192
|
+
if (typeof rule === 'function') {
|
|
193
|
+
if (api === 'onSyntax') {
|
|
194
|
+
yield rule(ruleCtx);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
|
|
199
|
+
}
|
|
193
200
|
(_e = context.ruleFixes) !== null && _e !== void 0 ? _e : (context.ruleFixes = {});
|
|
194
201
|
(_f = (_h = context.ruleFixes)[_j = ruleCtx.document.uri]) !== null && _f !== void 0 ? _f : (_h[_j] = {});
|
|
195
202
|
(_g = (_k = context.ruleFixes[ruleCtx.document.uri])[_l = ruleCtx.ruleId]) !== null && _g !== void 0 ? _g : (_k[_l] = {});
|
package/out/types.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
|
|
|
16
16
|
} | undefined;
|
|
17
17
|
env: {
|
|
18
18
|
rootUri: URI;
|
|
19
|
+
locale?: string;
|
|
19
20
|
configurationHost?: ConfigurationHost;
|
|
20
21
|
documentContext: DocumentContext;
|
|
21
22
|
fileSystemProvider?: FileSystemProvider;
|
|
@@ -78,9 +79,10 @@ export interface LanguageServicePlugin<T = {}> {
|
|
|
78
79
|
(context: LanguageServiceRuntimeContext, service: LanguageService): LanguageServicePluginInstance & T;
|
|
79
80
|
}
|
|
80
81
|
export interface LanguageServicePluginInstance {
|
|
81
|
-
|
|
82
|
+
rules?: {
|
|
83
|
+
prepare?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
84
|
+
};
|
|
82
85
|
validation?: {
|
|
83
|
-
resolveRuleContext?(context: RuleContext): void;
|
|
84
86
|
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
85
87
|
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
86
88
|
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
@@ -148,16 +150,21 @@ export interface LanguageServicePluginInstance {
|
|
|
148
150
|
*/
|
|
149
151
|
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
|
|
150
152
|
}
|
|
151
|
-
export
|
|
153
|
+
export type Rule = _Rule | NonNullable<_Rule['onSyntax']>;
|
|
154
|
+
export interface _Rule {
|
|
152
155
|
onFormat?(ctx: RuleContext): void;
|
|
153
156
|
onSyntax?(ctx: RuleContext): void;
|
|
154
157
|
onSemantic?(ctx: RuleContext): void;
|
|
155
158
|
}
|
|
156
159
|
export interface RuleContext {
|
|
157
|
-
|
|
158
|
-
document: TextDocument;
|
|
160
|
+
locale?: string;
|
|
159
161
|
uriToFileName(uri: string): string;
|
|
160
162
|
fileNameToUri(fileName: string): string;
|
|
163
|
+
rootUri: URI;
|
|
164
|
+
getConfiguration?: ConfigurationHost['getConfiguration'];
|
|
165
|
+
onDidChangeConfiguration?: ConfigurationHost['onDidChangeConfiguration'];
|
|
166
|
+
ruleId: string;
|
|
167
|
+
document: TextDocument;
|
|
161
168
|
report(error: vscode.Diagnostic, ...fixes: RuleFix[]): void;
|
|
162
169
|
}
|
|
163
170
|
export interface RuleFix {
|
|
@@ -166,11 +173,14 @@ export interface RuleFix {
|
|
|
166
173
|
getEdits?(diagnostic: vscode.Diagnostic): NullableResult<vscode.TextEdit[]>;
|
|
167
174
|
getWorkspaceEdit?(diagnostic: vscode.Diagnostic): NullableResult<vscode.WorkspaceEdit>;
|
|
168
175
|
}
|
|
169
|
-
export interface
|
|
170
|
-
languages?:
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
export interface Config {
|
|
177
|
+
languages?: {
|
|
178
|
+
[id: string]: LanguageModule | undefined;
|
|
179
|
+
};
|
|
180
|
+
plugins?: {
|
|
181
|
+
[id: string]: LanguageServicePlugin | LanguageServicePluginInstance | undefined;
|
|
182
|
+
};
|
|
183
|
+
rules?: {
|
|
184
|
+
[id: string]: Rule | undefined;
|
|
185
|
+
};
|
|
173
186
|
}
|
|
174
|
-
type ConfigValue<T> = {
|
|
175
|
-
[id: string]: T | undefined;
|
|
176
|
-
};
|
package/out/types.js
CHANGED
|
@@ -77,26 +77,34 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
77
77
|
}
|
|
78
78
|
exports.languageFeatureWorker = languageFeatureWorker;
|
|
79
79
|
function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
|
|
80
|
-
var _a, _b, _c;
|
|
80
|
+
var _a, _b, _c, _d, _e;
|
|
81
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
82
|
const document = context.getTextDocument(uri);
|
|
83
83
|
const virtualFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root;
|
|
84
84
|
let results = [];
|
|
85
85
|
if (virtualFile) {
|
|
86
86
|
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
var
|
|
87
|
+
var _f, _g, _h;
|
|
88
88
|
if (!isValidSourceMap(file)) {
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
document: map.virtualFileDocument,
|
|
91
|
+
let ruleCtx = {
|
|
92
|
+
// project context
|
|
94
93
|
uriToFileName: shared.uriToFileName,
|
|
95
94
|
fileNameToUri: shared.fileNameToUri,
|
|
95
|
+
rootUri: context.env.rootUri,
|
|
96
|
+
locale: context.env.locale,
|
|
97
|
+
getConfiguration: (_f = context.env.configurationHost) === null || _f === void 0 ? void 0 : _f.getConfiguration,
|
|
98
|
+
onDidChangeConfiguration: (_g = context.env.configurationHost) === null || _g === void 0 ? void 0 : _g.onDidChangeConfiguration,
|
|
99
|
+
// document context
|
|
100
|
+
ruleId: '',
|
|
101
|
+
document: map.virtualFileDocument,
|
|
96
102
|
report: () => { },
|
|
97
103
|
};
|
|
98
104
|
for (const plugin of Object.values(context.plugins)) {
|
|
99
|
-
|
|
105
|
+
if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.prepare) {
|
|
106
|
+
ruleCtx = yield plugin.rules.prepare(ruleCtx);
|
|
107
|
+
}
|
|
100
108
|
}
|
|
101
109
|
for (const ruleName in context.rules) {
|
|
102
110
|
const rule = context.rules[ruleName];
|
|
@@ -122,15 +130,23 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
122
130
|
}));
|
|
123
131
|
}
|
|
124
132
|
else if (document) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
document,
|
|
133
|
+
let ruleCtx = {
|
|
134
|
+
// project context
|
|
128
135
|
uriToFileName: shared.uriToFileName,
|
|
129
136
|
fileNameToUri: shared.fileNameToUri,
|
|
137
|
+
rootUri: context.env.rootUri,
|
|
138
|
+
locale: context.env.locale,
|
|
139
|
+
getConfiguration: (_b = context.env.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration,
|
|
140
|
+
onDidChangeConfiguration: (_c = context.env.configurationHost) === null || _c === void 0 ? void 0 : _c.onDidChangeConfiguration,
|
|
141
|
+
// document context
|
|
142
|
+
ruleId: '',
|
|
143
|
+
document,
|
|
130
144
|
report: () => { },
|
|
131
145
|
};
|
|
132
146
|
for (const plugin of Object.values(context.plugins)) {
|
|
133
|
-
|
|
147
|
+
if ((_d = plugin.rules) === null || _d === void 0 ? void 0 : _d.prepare) {
|
|
148
|
+
ruleCtx = yield ((_e = plugin.rules) === null || _e === void 0 ? void 0 : _e.prepare(ruleCtx));
|
|
149
|
+
}
|
|
134
150
|
}
|
|
135
151
|
for (const ruleName in context.rules) {
|
|
136
152
|
const rule = context.rules[ruleName];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.5",
|
|
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.2.0-alpha.
|
|
17
|
-
"@volar/shared": "1.2.0-alpha.
|
|
18
|
-
"@volar/source-map": "1.2.0-alpha.
|
|
19
|
-
"@volar/typescript-faster": "1.2.0-alpha.
|
|
16
|
+
"@volar/language-core": "1.2.0-alpha.5",
|
|
17
|
+
"@volar/shared": "1.2.0-alpha.5",
|
|
18
|
+
"@volar/source-map": "1.2.0-alpha.5",
|
|
19
|
+
"@volar/typescript-faster": "1.2.0-alpha.5",
|
|
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": "a31d022987c454762d1ba3c9ef8e7d74a5bca06a"
|
|
27
27
|
}
|