@volar/language-service 1.5.0 → 1.5.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 +2 -2
- package/out/baseLanguageService.js +7 -7
- package/out/documentFeatures/colorPresentations.js +2 -2
- package/out/documentFeatures/documentColors.js +2 -2
- package/out/documentFeatures/documentSymbols.js +2 -2
- package/out/documentFeatures/foldingRanges.js +2 -2
- package/out/documentFeatures/format.js +9 -9
- package/out/documentFeatures/linkedEditingRanges.js +2 -2
- package/out/documentFeatures/selectionRanges.js +2 -2
- package/out/languageFeatures/autoInsert.js +2 -2
- package/out/languageFeatures/callHierarchy.d.ts +1 -1
- package/out/languageFeatures/callHierarchy.js +11 -11
- package/out/languageFeatures/codeActionResolve.js +4 -4
- package/out/languageFeatures/codeActions.d.ts +3 -3
- package/out/languageFeatures/codeActions.js +8 -9
- package/out/languageFeatures/codeLens.d.ts +4 -4
- package/out/languageFeatures/codeLens.js +6 -6
- package/out/languageFeatures/codeLensResolve.js +6 -6
- package/out/languageFeatures/complete.d.ts +2 -2
- package/out/languageFeatures/complete.js +28 -28
- package/out/languageFeatures/completeResolve.js +5 -5
- package/out/languageFeatures/definition.js +2 -2
- package/out/languageFeatures/documentHighlights.js +3 -3
- package/out/languageFeatures/documentLinkResolve.js +3 -3
- package/out/languageFeatures/documentLinks.d.ts +1 -1
- package/out/languageFeatures/documentLinks.js +3 -3
- package/out/languageFeatures/documentSemanticTokens.js +2 -2
- package/out/languageFeatures/fileReferences.js +2 -2
- package/out/languageFeatures/fileRename.js +3 -3
- package/out/languageFeatures/hover.js +2 -2
- package/out/languageFeatures/inlayHintResolve.js +3 -3
- package/out/languageFeatures/inlayHints.d.ts +1 -1
- package/out/languageFeatures/inlayHints.js +3 -3
- package/out/languageFeatures/references.js +3 -3
- package/out/languageFeatures/rename.js +18 -7
- package/out/languageFeatures/renamePrepare.js +2 -2
- package/out/languageFeatures/signatureHelp.js +4 -4
- package/out/languageFeatures/validation.d.ts +4 -4
- package/out/languageFeatures/validation.js +28 -27
- package/out/languageFeatures/workspaceSymbols.js +3 -3
- package/out/types.d.ts +23 -18
- package/out/types.js +8 -0
- package/out/utils/featureWorkers.d.ts +2 -2
- package/out/utils/featureWorkers.js +48 -49
- package/package.json +4 -4
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = exports.errorMarkups = exports.updateRange = void 0;
|
|
4
4
|
const vscode = require("vscode-languageserver-protocol");
|
|
5
|
+
const types_1 = require("../types");
|
|
5
6
|
const common_1 = require("../utils/common");
|
|
6
7
|
const dedupe = require("../utils/dedupe");
|
|
7
8
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
@@ -126,15 +127,15 @@ function register(context) {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
if (mode === 'all' || mode === 'syntactic') {
|
|
129
|
-
await lintWorker(
|
|
130
|
+
await lintWorker(types_1.RuleType.Format, cacheMaps.format_rules, lastResponse.format_rules);
|
|
130
131
|
await doResponse();
|
|
131
|
-
await lintWorker(
|
|
132
|
+
await lintWorker(types_1.RuleType.Syntax, cacheMaps.syntax_rules, lastResponse.syntax_rules);
|
|
132
133
|
await doResponse();
|
|
133
134
|
await worker('provideDiagnostics', cacheMaps.syntactic, lastResponse.syntactic);
|
|
134
135
|
await doResponse();
|
|
135
136
|
}
|
|
136
137
|
if (mode === 'all' || mode === 'semantic') {
|
|
137
|
-
await lintWorker(
|
|
138
|
+
await lintWorker(types_1.RuleType.Semantic, cacheMaps.semantic_rules, lastResponse.semantic_rules);
|
|
138
139
|
await doResponse();
|
|
139
140
|
await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic);
|
|
140
141
|
}
|
|
@@ -149,8 +150,8 @@ function register(context) {
|
|
|
149
150
|
const errors = Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
150
151
|
exports.errorMarkups[uri] = [];
|
|
151
152
|
for (const error of errors) {
|
|
152
|
-
for (const
|
|
153
|
-
const markup = await
|
|
153
|
+
for (const service of Object.values(context.services)) {
|
|
154
|
+
const markup = await service.provideDiagnosticMarkupContent?.(error, token);
|
|
154
155
|
if (markup) {
|
|
155
156
|
exports.errorMarkups[uri].push({ error, markup });
|
|
156
157
|
}
|
|
@@ -158,8 +159,8 @@ function register(context) {
|
|
|
158
159
|
}
|
|
159
160
|
return errors;
|
|
160
161
|
}
|
|
161
|
-
async function lintWorker(
|
|
162
|
-
const result = await (0, featureWorkers_1.ruleWorker)(context,
|
|
162
|
+
async function lintWorker(ruleType, cacheMap, cache) {
|
|
163
|
+
const result = await (0, featureWorkers_1.ruleWorker)(context, ruleType, uri, file => ruleType === types_1.RuleType.Format ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, async (ruleName, rule, ruleCtx) => {
|
|
163
164
|
if (token) {
|
|
164
165
|
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
165
166
|
await (0, common_1.sleep)(5); // wait for LSP event polling
|
|
@@ -171,8 +172,8 @@ function register(context) {
|
|
|
171
172
|
}
|
|
172
173
|
const pluginCache = cacheMap.get(ruleName) ?? cacheMap.set(ruleName, new Map()).get(ruleName);
|
|
173
174
|
const cache = pluginCache.get(ruleCtx.document.uri);
|
|
174
|
-
const tsProjectVersion = (
|
|
175
|
-
if (
|
|
175
|
+
const tsProjectVersion = (ruleType === types_1.RuleType.Semantic) ? context.core.typescript.languageServiceHost.getProjectVersion?.() : undefined;
|
|
176
|
+
if (ruleType === types_1.RuleType.Semantic) {
|
|
176
177
|
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
177
178
|
return cache.errors;
|
|
178
179
|
}
|
|
@@ -189,19 +190,19 @@ function register(context) {
|
|
|
189
190
|
return;
|
|
190
191
|
}
|
|
191
192
|
error.message ||= 'No message.';
|
|
192
|
-
error.source ||=
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
193
|
+
error.source ||= ruleCtx.ruleId;
|
|
194
|
+
for (const service of Object.values(context.services)) {
|
|
195
|
+
if (service.rules?.resolveDiagnostic) {
|
|
196
|
+
error = service.rules.resolveDiagnostic(error);
|
|
197
|
+
}
|
|
197
198
|
}
|
|
198
199
|
reportResults.push([error, ...fixes]);
|
|
199
200
|
};
|
|
200
201
|
try {
|
|
201
|
-
await rule
|
|
202
|
+
await rule.run(ruleCtx);
|
|
202
203
|
}
|
|
203
204
|
catch (err) {
|
|
204
|
-
console.warn(`[volar/rules-api] ${ruleName} ${
|
|
205
|
+
console.warn(`[volar/rules-api] ${ruleName} ${ruleType} error.`);
|
|
205
206
|
console.warn(err);
|
|
206
207
|
}
|
|
207
208
|
context.ruleFixes ??= {};
|
|
@@ -213,8 +214,8 @@ function register(context) {
|
|
|
213
214
|
uri,
|
|
214
215
|
version: newDocument.version,
|
|
215
216
|
type: 'rule',
|
|
216
|
-
isFormat:
|
|
217
|
-
|
|
217
|
+
isFormat: ruleType === types_1.RuleType.Format,
|
|
218
|
+
serviceOrRuleId: ruleCtx.ruleId,
|
|
218
219
|
original: {
|
|
219
220
|
data: error.data,
|
|
220
221
|
},
|
|
@@ -230,7 +231,7 @@ function register(context) {
|
|
|
230
231
|
tsProjectVersion,
|
|
231
232
|
});
|
|
232
233
|
return errors;
|
|
233
|
-
},
|
|
234
|
+
}, ruleType === types_1.RuleType.Format ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
|
|
234
235
|
if (result) {
|
|
235
236
|
cache.errors = result;
|
|
236
237
|
cache.snapshot = newSnapshot;
|
|
@@ -241,7 +242,7 @@ function register(context) {
|
|
|
241
242
|
if (file.capabilities.diagnostic) {
|
|
242
243
|
yield arg;
|
|
243
244
|
}
|
|
244
|
-
}, async (
|
|
245
|
+
}, async (service, document) => {
|
|
245
246
|
if (token) {
|
|
246
247
|
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
247
248
|
await (0, common_1.sleep)(5); // waiting LSP event polling
|
|
@@ -251,9 +252,9 @@ function register(context) {
|
|
|
251
252
|
return;
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
const cache =
|
|
255
|
+
const serviceId = Object.keys(context.services).find(key => context.services[key] === service);
|
|
256
|
+
const serviceCache = cacheMap.get(serviceId) ?? cacheMap.set(serviceId, new Map()).get(serviceId);
|
|
257
|
+
const cache = serviceCache.get(document.uri);
|
|
257
258
|
const tsProjectVersion = api === 'provideSemanticDiagnostics' ? context.core.typescript.languageServiceHost.getProjectVersion?.() : undefined;
|
|
258
259
|
if (api === 'provideSemanticDiagnostics') {
|
|
259
260
|
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
@@ -265,13 +266,13 @@ function register(context) {
|
|
|
265
266
|
return cache.errors;
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
|
-
const errors = await
|
|
269
|
+
const errors = await service[api]?.(document, token);
|
|
269
270
|
errors?.forEach(error => {
|
|
270
271
|
error.data = {
|
|
271
272
|
uri,
|
|
272
273
|
version: newDocument.version,
|
|
273
|
-
type: '
|
|
274
|
-
|
|
274
|
+
type: 'service',
|
|
275
|
+
serviceOrRuleId: serviceId,
|
|
275
276
|
isFormat: false,
|
|
276
277
|
original: {
|
|
277
278
|
data: error.data,
|
|
@@ -281,7 +282,7 @@ function register(context) {
|
|
|
281
282
|
};
|
|
282
283
|
});
|
|
283
284
|
errorsUpdated = true;
|
|
284
|
-
|
|
285
|
+
serviceCache.set(document.uri, {
|
|
285
286
|
documentVersion: document.version,
|
|
286
287
|
errors,
|
|
287
288
|
tsProjectVersion,
|
|
@@ -7,12 +7,12 @@ const common_1 = require("../utils/common");
|
|
|
7
7
|
function register(context) {
|
|
8
8
|
return async (query, token = vscode.CancellationToken.None) => {
|
|
9
9
|
const symbolsList = [];
|
|
10
|
-
for (const
|
|
10
|
+
for (const service of Object.values(context.services)) {
|
|
11
11
|
if (token.isCancellationRequested)
|
|
12
12
|
break;
|
|
13
|
-
if (!
|
|
13
|
+
if (!service.provideWorkspaceSymbols)
|
|
14
14
|
continue;
|
|
15
|
-
const embeddedSymbols = await
|
|
15
|
+
const embeddedSymbols = await service.provideWorkspaceSymbols(query, token);
|
|
16
16
|
if (!embeddedSymbols)
|
|
17
17
|
continue;
|
|
18
18
|
const symbols = embeddedSymbols.map(symbol => transformer.asWorkspaceSymbol(symbol, loc => {
|
package/out/types.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
|
7
7
|
import { URI } from 'vscode-uri';
|
|
8
8
|
import { DocumentsAndSourceMaps } from './documents';
|
|
9
9
|
export * from 'vscode-languageserver-protocol';
|
|
10
|
+
export interface SharedModules {
|
|
11
|
+
typescript?: typeof import('typescript/lib/tsserverlibrary');
|
|
12
|
+
}
|
|
10
13
|
export interface ServiceEnvironment {
|
|
11
14
|
locale?: string;
|
|
12
15
|
rootUri: URI;
|
|
@@ -42,7 +45,7 @@ export interface ServiceContext {
|
|
|
42
45
|
/** @private */
|
|
43
46
|
documents: DocumentsAndSourceMaps;
|
|
44
47
|
/** @private */
|
|
45
|
-
|
|
48
|
+
services: {
|
|
46
49
|
[id: string]: ReturnType<Service>;
|
|
47
50
|
};
|
|
48
51
|
/** @private */
|
|
@@ -60,9 +63,7 @@ export type Result<T> = T | Thenable<T>;
|
|
|
60
63
|
export type NullableResult<T> = Result<T | undefined | null>;
|
|
61
64
|
export type SemanticToken = [number, number, number, number, number];
|
|
62
65
|
export interface Service {
|
|
63
|
-
(context: ServiceContext | undefined, modules: {
|
|
64
|
-
typescript?: typeof import('typescript/lib/tsserverlibrary');
|
|
65
|
-
} | undefined): {
|
|
66
|
+
(context: ServiceContext | undefined, modules: SharedModules | undefined): {
|
|
66
67
|
isAdditionalCompletion?: boolean;
|
|
67
68
|
triggerCharacters?: string[];
|
|
68
69
|
signatureHelpTriggerCharacters?: string[];
|
|
@@ -109,8 +110,11 @@ export interface Service {
|
|
|
109
110
|
resolveDocumentLink?(link: vscode.DocumentLink, token: vscode.CancellationToken): Result<vscode.DocumentLink>;
|
|
110
111
|
resolveInlayHint?(inlayHint: vscode.InlayHint, token: vscode.CancellationToken): Result<vscode.InlayHint>;
|
|
111
112
|
resolveReferencesCodeLensLocations?(document: TextDocument, range: vscode.Range, references: vscode.Location[], token: vscode.CancellationToken): Result<vscode.Location[]>;
|
|
112
|
-
resolveRuleContext?(context: RuleContext, ruleType: 'format' | 'syntax' | 'semantic'): Result<RuleContext>;
|
|
113
113
|
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
|
|
114
|
+
rules?: {
|
|
115
|
+
provide?: Record<any, (document: TextDocument, ruleType: RuleType) => Result<any | undefined>>;
|
|
116
|
+
resolveDiagnostic?(diagnostic: vscode.Diagnostic): vscode.Diagnostic;
|
|
117
|
+
};
|
|
114
118
|
};
|
|
115
119
|
}
|
|
116
120
|
export interface AutoInsertionContext {
|
|
@@ -121,17 +125,24 @@ export interface AutoInsertionContext {
|
|
|
121
125
|
text: string;
|
|
122
126
|
};
|
|
123
127
|
}
|
|
128
|
+
export declare enum RuleType {
|
|
129
|
+
Format = 0,
|
|
130
|
+
Syntax = 1,
|
|
131
|
+
Semantic = 2
|
|
132
|
+
}
|
|
124
133
|
export interface Rule {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
onSemantic?(ctx: RuleContext): void;
|
|
134
|
+
type?: RuleType;
|
|
135
|
+
run(ctx: RuleContext): void;
|
|
128
136
|
}
|
|
129
137
|
export interface RuleContext {
|
|
130
138
|
env: ServiceEnvironment;
|
|
131
139
|
ruleId: string;
|
|
132
140
|
document: TextDocument;
|
|
141
|
+
inject<T>(key: InjectionKey<T>): T | undefined;
|
|
133
142
|
report(error: vscode.Diagnostic, ...fixes: RuleFix[]): void;
|
|
134
143
|
}
|
|
144
|
+
export interface InjectionKey<T> extends Symbol {
|
|
145
|
+
}
|
|
135
146
|
export interface RuleFix {
|
|
136
147
|
/**
|
|
137
148
|
* Code action kind, like `quickfix` or `refactor`.
|
|
@@ -154,18 +165,12 @@ export interface RuleFix {
|
|
|
154
165
|
}
|
|
155
166
|
export interface Config {
|
|
156
167
|
languages?: {
|
|
157
|
-
[id: string]: Language
|
|
168
|
+
[id: string]: Language;
|
|
158
169
|
};
|
|
159
170
|
services?: {
|
|
160
|
-
[id: string]: Service
|
|
171
|
+
[id: string]: Service;
|
|
161
172
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
[id: string]: Rule | undefined;
|
|
165
|
-
};
|
|
166
|
-
severities?: {
|
|
167
|
-
[id: string]: vscode.DiagnosticSeverity;
|
|
168
|
-
};
|
|
169
|
-
settings?: any;
|
|
173
|
+
rules?: {
|
|
174
|
+
[id: string]: Rule;
|
|
170
175
|
};
|
|
171
176
|
}
|
package/out/types.js
CHANGED
|
@@ -14,5 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.RuleType = void 0;
|
|
17
18
|
__exportStar(require("vscode-languageserver-protocol"), exports);
|
|
19
|
+
var RuleType;
|
|
20
|
+
(function (RuleType) {
|
|
21
|
+
RuleType[RuleType["Format"] = 0] = "Format";
|
|
22
|
+
RuleType[RuleType["Syntax"] = 1] = "Syntax";
|
|
23
|
+
RuleType[RuleType["Semantic"] = 2] = "Semantic";
|
|
24
|
+
})(RuleType = exports.RuleType || (exports.RuleType = {}));
|
|
25
|
+
;
|
|
18
26
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
import
|
|
2
|
+
import { Service, ServiceContext, Rule, RuleContext, RuleType } 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: ServiceContext, uri: string, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (service: ReturnType<Service>, 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: ServiceContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (service: ReturnType<Service>, 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: ServiceContext,
|
|
7
|
+
export declare function ruleWorker<T>(context: ServiceContext, ruleType: RuleType, uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleId: 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
8
|
export declare function safeCall<T>(cb: () => Promise<T> | T, errorMsg?: string): Promise<T | undefined>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.safeCall = exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
4
4
|
const definePlugin_1 = require("./definePlugin");
|
|
5
|
+
const types_1 = require("../types");
|
|
5
6
|
async function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) {
|
|
6
7
|
return languageFeatureWorker(context, uri, undefined, (_, map, file) => {
|
|
7
8
|
if (isValidSourceMap(file, map)) {
|
|
@@ -18,8 +19,8 @@ async function languageFeatureWorker(context, uri, arg, transformArg, worker, tr
|
|
|
18
19
|
if (virtualFile) {
|
|
19
20
|
await (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, async (file, map) => {
|
|
20
21
|
for (const mappedArg of transformArg(arg, map, file)) {
|
|
21
|
-
for (const [
|
|
22
|
-
const embeddedResult = await safeCall(() => worker(
|
|
22
|
+
for (const [serviceId, service] of Object.entries(context.services)) {
|
|
23
|
+
const embeddedResult = await safeCall(() => worker(service, map.virtualFileDocument, mappedArg, map, file), 'service ' + serviceId + ' crashed on ' + map.virtualFileDocument.uri);
|
|
23
24
|
if (!embeddedResult)
|
|
24
25
|
continue;
|
|
25
26
|
const result = transform(embeddedResult, map);
|
|
@@ -38,8 +39,8 @@ async function languageFeatureWorker(context, uri, arg, transformArg, worker, tr
|
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
else if (document) {
|
|
41
|
-
for (const [
|
|
42
|
-
const embeddedResult = await safeCall(() => worker(
|
|
42
|
+
for (const [serviceId, service] of Object.entries(context.services)) {
|
|
43
|
+
const embeddedResult = await safeCall(() => worker(service, document, arg, undefined, undefined), 'service ' + serviceId + ' crashed on ' + uri);
|
|
43
44
|
if (!embeddedResult)
|
|
44
45
|
continue;
|
|
45
46
|
const result = transform(embeddedResult, undefined);
|
|
@@ -62,39 +63,26 @@ async function languageFeatureWorker(context, uri, arg, transformArg, worker, tr
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
exports.languageFeatureWorker = languageFeatureWorker;
|
|
65
|
-
async function ruleWorker(context,
|
|
66
|
+
async function ruleWorker(context, ruleType, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
|
|
66
67
|
const document = context.getTextDocument(uri);
|
|
67
68
|
const virtualFile = context.documents.getSourceByUri(uri)?.root;
|
|
69
|
+
let provided = {};
|
|
68
70
|
let results = [];
|
|
71
|
+
let ruleCtx;
|
|
69
72
|
if (virtualFile) {
|
|
70
73
|
await (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, async (file, map) => {
|
|
71
74
|
if (!isValidSourceMap(file)) {
|
|
72
75
|
return true;
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
ruleId
|
|
78
|
-
|
|
79
|
-
report: () => { },
|
|
80
|
-
};
|
|
81
|
-
for (const plugin of Object.values(context.plugins)) {
|
|
82
|
-
try {
|
|
83
|
-
if (plugin.resolveRuleContext) {
|
|
84
|
-
ruleCtx = await plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
console.warn('plugin rule context setup crashed on ' + map.virtualFileDocument.uri + ': ' + err);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
for (const ruleName in context.config.lint?.rules) {
|
|
92
|
-
const rule = context.config.lint?.rules[ruleName];
|
|
93
|
-
if (!rule) {
|
|
77
|
+
ruleCtx = createCtx(map.virtualFileDocument);
|
|
78
|
+
provided = {};
|
|
79
|
+
for (const ruleId in context.config.rules) {
|
|
80
|
+
const rule = context.config.rules[ruleId];
|
|
81
|
+
if ((rule.type ?? types_1.RuleType.Syntax) !== ruleType) {
|
|
94
82
|
continue;
|
|
95
83
|
}
|
|
96
|
-
ruleCtx.ruleId =
|
|
97
|
-
const embeddedResult = await safeCall(() => worker(
|
|
84
|
+
ruleCtx.ruleId = ruleId;
|
|
85
|
+
const embeddedResult = await safeCall(() => worker(ruleId, rule, ruleCtx), 'rule ' + ruleId + ' crashed on ' + map.virtualFileDocument.uri);
|
|
98
86
|
if (!embeddedResult)
|
|
99
87
|
continue;
|
|
100
88
|
const result = transform(embeddedResult, map);
|
|
@@ -112,30 +100,15 @@ async function ruleWorker(context, api, uri, isValidSourceMap, worker, transform
|
|
|
112
100
|
});
|
|
113
101
|
}
|
|
114
102
|
else if (document) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
ruleId
|
|
119
|
-
|
|
120
|
-
report: () => { },
|
|
121
|
-
};
|
|
122
|
-
for (const plugin of Object.values(context.plugins)) {
|
|
123
|
-
try {
|
|
124
|
-
if (plugin.resolveRuleContext) {
|
|
125
|
-
ruleCtx = await plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
console.warn('plugin rule context setup crashed on ' + document.uri + ': ' + err);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
for (const ruleName in context.config.lint?.rules) {
|
|
133
|
-
const rule = context.config.lint?.rules[ruleName];
|
|
134
|
-
if (!rule) {
|
|
103
|
+
ruleCtx = createCtx(document);
|
|
104
|
+
provided = {};
|
|
105
|
+
for (const ruleId in context.config.rules) {
|
|
106
|
+
const rule = context.config.rules[ruleId];
|
|
107
|
+
if ((rule.type ?? types_1.RuleType.Syntax) !== ruleType) {
|
|
135
108
|
continue;
|
|
136
109
|
}
|
|
137
|
-
ruleCtx.ruleId =
|
|
138
|
-
const embeddedResult = await safeCall(() => worker(
|
|
110
|
+
ruleCtx.ruleId = ruleId;
|
|
111
|
+
const embeddedResult = await safeCall(() => worker(ruleId, rule, ruleCtx), 'rule ' + ruleId + ' crashed on ' + document.uri);
|
|
139
112
|
if (!embeddedResult)
|
|
140
113
|
continue;
|
|
141
114
|
const result = transform(embeddedResult, undefined);
|
|
@@ -156,6 +129,32 @@ async function ruleWorker(context, api, uri, isValidSourceMap, worker, transform
|
|
|
156
129
|
else if (results.length > 0) {
|
|
157
130
|
return results[0];
|
|
158
131
|
}
|
|
132
|
+
function createCtx(document) {
|
|
133
|
+
return {
|
|
134
|
+
env: context.env,
|
|
135
|
+
ruleId: '',
|
|
136
|
+
document: document,
|
|
137
|
+
report: () => { },
|
|
138
|
+
inject: key => {
|
|
139
|
+
provided[key] ??= new Map();
|
|
140
|
+
const map = provided[key];
|
|
141
|
+
if (!map.has(ruleCtx.document)) {
|
|
142
|
+
for (const service of Object.values(context.services)) {
|
|
143
|
+
const provide = service.rules?.provide?.[key];
|
|
144
|
+
if (provide) {
|
|
145
|
+
try {
|
|
146
|
+
map.set(ruleCtx.document, provide(ruleCtx.document, ruleType));
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.warn('service rule context setup crashed on ' + ruleCtx.document.uri + ': ' + err);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return map.get(ruleCtx.document);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
159
158
|
}
|
|
160
159
|
exports.ruleWorker = ruleWorker;
|
|
161
160
|
async function safeCall(cb, errorMsg) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/language-service"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.5.
|
|
17
|
-
"@volar/source-map": "1.5.
|
|
16
|
+
"@volar/language-core": "1.5.2",
|
|
17
|
+
"@volar/source-map": "1.5.2",
|
|
18
18
|
"typescript-auto-import-cache": "^0.2.1",
|
|
19
19
|
"vscode-html-languageservice": "^5.0.4",
|
|
20
20
|
"vscode-json-languageservice": "^5.2.0",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"vscode-languageserver-textdocument": "^1.0.8",
|
|
23
23
|
"vscode-uri": "^3.0.7"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "e58503bf9700e96557e583f95e38a21c8f7b4a0a"
|
|
26
26
|
}
|