@volar/language-service 1.1.0-alpha.2 → 1.2.0-alpha.10
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 +4 -14
- package/out/baseLanguageService.js +33 -27
- package/out/documentFeatures/colorPresentations.d.ts +2 -2
- package/out/documentFeatures/documentColors.d.ts +2 -2
- package/out/documentFeatures/documentSymbols.d.ts +2 -2
- package/out/documentFeatures/foldingRanges.d.ts +2 -2
- package/out/documentFeatures/format.d.ts +2 -4
- package/out/documentFeatures/format.js +27 -124
- package/out/documentFeatures/linkedEditingRanges.d.ts +2 -2
- package/out/documentFeatures/selectionRanges.d.ts +2 -2
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -3
- package/out/languageFeatures/autoInsert.d.ts +2 -2
- package/out/languageFeatures/callHierarchy.d.ts +4 -4
- package/out/languageFeatures/callHierarchy.js +16 -17
- package/out/languageFeatures/codeActionResolve.d.ts +2 -2
- package/out/languageFeatures/codeActionResolve.js +28 -17
- package/out/languageFeatures/codeActions.d.ts +16 -7
- package/out/languageFeatures/codeActions.js +101 -21
- package/out/languageFeatures/codeLens.d.ts +11 -4
- package/out/languageFeatures/codeLens.js +31 -15
- package/out/languageFeatures/codeLensResolve.d.ts +4 -2
- package/out/languageFeatures/codeLensResolve.js +22 -8
- package/out/languageFeatures/complete.d.ts +4 -4
- package/out/languageFeatures/complete.js +39 -20
- package/out/languageFeatures/completeResolve.d.ts +2 -2
- package/out/languageFeatures/completeResolve.js +4 -17
- package/out/languageFeatures/definition.d.ts +2 -2
- package/out/languageFeatures/documentHighlights.d.ts +2 -2
- package/out/languageFeatures/documentLinks.d.ts +2 -2
- package/out/languageFeatures/documentSemanticTokens.d.ts +2 -2
- package/out/languageFeatures/fileReferences.d.ts +2 -2
- package/out/languageFeatures/fileRename.d.ts +2 -2
- package/out/languageFeatures/fileRename.js +2 -2
- package/out/languageFeatures/hover.d.ts +2 -2
- package/out/languageFeatures/inlayHints.d.ts +2 -2
- package/out/languageFeatures/references.d.ts +2 -2
- package/out/languageFeatures/rename.d.ts +3 -3
- package/out/languageFeatures/rename.js +64 -44
- package/out/languageFeatures/renamePrepare.d.ts +2 -2
- package/out/languageFeatures/signatureHelp.d.ts +2 -2
- package/out/languageFeatures/validation.d.ts +12 -2
- package/out/languageFeatures/validation.js +169 -39
- package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
- package/out/languageFeatures/workspaceSymbols.js +1 -1
- package/out/transformer/foldingRanges.js +6 -6
- package/out/types.d.ts +108 -24
- package/out/types.js +0 -1
- package/out/utils/featureWorkers.d.ts +4 -3
- package/out/utils/featureWorkers.js +120 -5
- package/package.json +9 -9
- package/out/languageFeatures/executeCommand.d.ts +0 -11
- package/out/languageFeatures/executeCommand.js +0 -32
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function register(context:
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
3
|
import { DocumentsAndSourceMaps } from '../documents';
|
|
4
|
-
export declare function register(context:
|
|
4
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
5
5
|
export declare function mergeWorkspaceEdits(original: vscode.WorkspaceEdit, ...others: vscode.WorkspaceEdit[]): void;
|
|
6
|
-
export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit,
|
|
6
|
+
export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit, documents: DocumentsAndSourceMaps, mode: 'fileName' | 'rename' | 'codeAction' | 'format', versions?: Record<string, number>): vscode.WorkspaceEdit | undefined;
|
|
@@ -87,7 +87,7 @@ function register(context) {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
}), (data) => {
|
|
90
|
-
return embeddedEditToSourceEdit(data, context.documents);
|
|
90
|
+
return embeddedEditToSourceEdit(data, context.documents, 'rename');
|
|
91
91
|
}, (workspaceEdits) => {
|
|
92
92
|
const mainEdit = workspaceEdits[0];
|
|
93
93
|
const otherEdits = workspaceEdits.slice(1);
|
|
@@ -131,18 +131,19 @@ function mergeWorkspaceEdits(original, ...others) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
exports.mergeWorkspaceEdits = mergeWorkspaceEdits;
|
|
134
|
-
function embeddedEditToSourceEdit(tsResult,
|
|
135
|
-
var _a, _b, _c;
|
|
134
|
+
function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
135
|
+
var _a, _b, _c, _d, _e, _f;
|
|
136
|
+
var _g, _h, _j, _k;
|
|
136
137
|
const sourceResult = {};
|
|
137
138
|
let hasResult = false;
|
|
138
139
|
for (const tsUri in tsResult.changeAnnotations) {
|
|
139
140
|
(_a = sourceResult.changeAnnotations) !== null && _a !== void 0 ? _a : (sourceResult.changeAnnotations = {});
|
|
140
141
|
const tsAnno = tsResult.changeAnnotations[tsUri];
|
|
141
|
-
if (!
|
|
142
|
+
if (!documents.hasVirtualFileByUri(tsUri)) {
|
|
142
143
|
sourceResult.changeAnnotations[tsUri] = tsAnno;
|
|
143
144
|
}
|
|
144
145
|
else {
|
|
145
|
-
for (const [_, map] of
|
|
146
|
+
for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
|
|
146
147
|
// TODO: check capability?
|
|
147
148
|
const uri = map.sourceFileDocument.uri;
|
|
148
149
|
sourceResult.changeAnnotations[uri] = tsAnno;
|
|
@@ -151,62 +152,81 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
151
152
|
}
|
|
152
153
|
for (const tsUri in tsResult.changes) {
|
|
153
154
|
(_b = sourceResult.changes) !== null && _b !== void 0 ? _b : (sourceResult.changes = {});
|
|
154
|
-
if (!
|
|
155
|
+
if (!documents.hasVirtualFileByUri(tsUri)) {
|
|
155
156
|
sourceResult.changes[tsUri] = tsResult.changes[tsUri];
|
|
156
157
|
hasResult = true;
|
|
157
158
|
continue;
|
|
158
159
|
}
|
|
159
|
-
for (const [_, map] of
|
|
160
|
+
for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
|
|
160
161
|
const tsEdits = tsResult.changes[tsUri];
|
|
161
162
|
for (const tsEdit of tsEdits) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
if (mode === 'rename') {
|
|
164
|
+
let _data;
|
|
165
|
+
const range = map.toSourceRange(tsEdit.range, data => {
|
|
166
|
+
_data = data;
|
|
167
|
+
return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
|
|
168
|
+
});
|
|
169
|
+
if (range) {
|
|
170
|
+
let newText = tsEdit.newText;
|
|
171
|
+
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
172
|
+
newText = _data.rename.apply(tsEdit.newText);
|
|
173
|
+
}
|
|
174
|
+
(_c = (_g = sourceResult.changes)[_h = map.sourceFileDocument.uri]) !== null && _c !== void 0 ? _c : (_g[_h] = []);
|
|
175
|
+
sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range });
|
|
176
|
+
hasResult = true;
|
|
171
177
|
}
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const range = map.toSourceRange(tsEdit.range);
|
|
181
|
+
if (range) {
|
|
182
|
+
(_d = (_j = sourceResult.changes)[_k = map.sourceFileDocument.uri]) !== null && _d !== void 0 ? _d : (_j[_k] = []);
|
|
183
|
+
sourceResult.changes[map.sourceFileDocument.uri].push({ newText: tsEdit.newText, range });
|
|
184
|
+
hasResult = true;
|
|
174
185
|
}
|
|
175
|
-
sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range });
|
|
176
|
-
hasResult = true;
|
|
177
186
|
}
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
}
|
|
181
190
|
if (tsResult.documentChanges) {
|
|
182
191
|
for (const tsDocEdit of tsResult.documentChanges) {
|
|
183
|
-
(
|
|
192
|
+
(_e = sourceResult.documentChanges) !== null && _e !== void 0 ? _e : (sourceResult.documentChanges = []);
|
|
184
193
|
let sourceEdit;
|
|
185
194
|
if (vscode.TextDocumentEdit.is(tsDocEdit)) {
|
|
186
|
-
if (
|
|
187
|
-
for (const [_, map] of
|
|
195
|
+
if (documents.hasVirtualFileByUri(tsDocEdit.textDocument.uri)) {
|
|
196
|
+
for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.textDocument.uri)) {
|
|
188
197
|
sourceEdit = vscode.TextDocumentEdit.create({
|
|
189
198
|
uri: map.sourceFileDocument.uri,
|
|
190
|
-
|
|
191
|
-
version: null, // fix https://github.com/johnsoncodehk/volar/issues/1490
|
|
199
|
+
version: (_f = versions[map.sourceFileDocument.uri]) !== null && _f !== void 0 ? _f : null,
|
|
192
200
|
}, []);
|
|
193
201
|
for (const tsEdit of tsDocEdit.edits) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (range) {
|
|
201
|
-
let newText = tsEdit.newText;
|
|
202
|
-
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
203
|
-
newText = _data.rename.apply(tsEdit.newText);
|
|
204
|
-
}
|
|
205
|
-
sourceEdit.edits.push({
|
|
206
|
-
annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
|
|
207
|
-
newText,
|
|
208
|
-
range,
|
|
202
|
+
if (mode === 'rename') {
|
|
203
|
+
let _data;
|
|
204
|
+
const range = map.toSourceRange(tsEdit.range, data => {
|
|
205
|
+
_data = data;
|
|
206
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1091
|
|
207
|
+
return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
|
|
209
208
|
});
|
|
209
|
+
if (range) {
|
|
210
|
+
let newText = tsEdit.newText;
|
|
211
|
+
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
212
|
+
newText = _data.rename.apply(tsEdit.newText);
|
|
213
|
+
}
|
|
214
|
+
sourceEdit.edits.push({
|
|
215
|
+
annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
|
|
216
|
+
newText,
|
|
217
|
+
range,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
const range = map.toSourceRange(tsEdit.range);
|
|
223
|
+
if (range) {
|
|
224
|
+
sourceEdit.edits.push({
|
|
225
|
+
annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
|
|
226
|
+
newText: tsEdit.newText,
|
|
227
|
+
range,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
210
230
|
}
|
|
211
231
|
}
|
|
212
232
|
if (!sourceEdit.edits.length) {
|
|
@@ -222,22 +242,22 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
222
242
|
sourceEdit = tsDocEdit; // TODO: remove .ts?
|
|
223
243
|
}
|
|
224
244
|
else if (vscode.RenameFile.is(tsDocEdit)) {
|
|
225
|
-
if (!
|
|
245
|
+
if (!documents.hasVirtualFileByUri(tsDocEdit.oldUri)) {
|
|
226
246
|
sourceEdit = tsDocEdit;
|
|
227
247
|
}
|
|
228
248
|
else {
|
|
229
|
-
for (const [_, map] of
|
|
249
|
+
for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.oldUri)) {
|
|
230
250
|
// TODO: check capability?
|
|
231
251
|
sourceEdit = vscode.RenameFile.create(map.sourceFileDocument.uri, tsDocEdit.newUri /* TODO: remove .ts? */, tsDocEdit.options, tsDocEdit.annotationId);
|
|
232
252
|
}
|
|
233
253
|
}
|
|
234
254
|
}
|
|
235
255
|
else if (vscode.DeleteFile.is(tsDocEdit)) {
|
|
236
|
-
if (!
|
|
256
|
+
if (!documents.hasVirtualFileByUri(tsDocEdit.uri)) {
|
|
237
257
|
sourceEdit = tsDocEdit;
|
|
238
258
|
}
|
|
239
259
|
else {
|
|
240
|
-
for (const [_, map] of
|
|
260
|
+
for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.uri)) {
|
|
241
261
|
// TODO: check capability?
|
|
242
262
|
sourceEdit = vscode.DeleteFile.create(map.sourceFileDocument.uri, tsDocEdit.options, tsDocEdit.annotationId);
|
|
243
263
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function register(context:
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function register(context:
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext) => Promise<vscode.SignatureHelp | undefined>;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
3
|
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
|
|
7
|
+
export interface PluginDiagnosticData {
|
|
8
|
+
uri: string;
|
|
9
|
+
version: number;
|
|
10
|
+
original: Pick<vscode.Diagnostic, 'data'>;
|
|
11
|
+
type: 'plugin' | 'rule';
|
|
12
|
+
isFormat: boolean;
|
|
13
|
+
pluginOrRuleId: string;
|
|
14
|
+
ruleFixIndex: number;
|
|
15
|
+
documentUri: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
@@ -10,7 +10,7 @@ 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
|
|
13
|
+
const vscode = require("vscode-languageserver-protocol");
|
|
14
14
|
const dedupe = require("../utils/dedupe");
|
|
15
15
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
16
16
|
function updateRange(range, change) {
|
|
@@ -86,32 +86,42 @@ function updatePosition(position, change, isEnd) {
|
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
function register(context) {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
const lastResponses = new Map();
|
|
90
|
+
const cacheMaps = {
|
|
91
|
+
semantic: new Map(),
|
|
92
|
+
declaration: new Map(),
|
|
93
|
+
syntactic: new Map(),
|
|
94
|
+
suggestion: new Map(),
|
|
95
|
+
semantic_rules: new Map(),
|
|
96
|
+
syntax_rules: new Map(),
|
|
97
|
+
format_rules: new Map(),
|
|
98
|
+
};
|
|
95
99
|
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
|
|
96
100
|
var _a;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const newDocument = context.getTextDocument(uri);
|
|
102
|
+
if (!newDocument) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const lastResponse = (_a = lastResponses.get(uri)) !== null && _a !== void 0 ? _a : lastResponses.set(uri, {
|
|
106
|
+
semantic: { errors: [] },
|
|
107
|
+
declaration: { errors: [] },
|
|
108
|
+
suggestion: { errors: [] },
|
|
109
|
+
syntactic: { errors: [] },
|
|
110
|
+
semantic_rules: { errors: [] },
|
|
111
|
+
syntax_rules: { errors: [] },
|
|
112
|
+
format_rules: { errors: [] },
|
|
103
113
|
}).get(uri);
|
|
104
114
|
const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
|
|
105
|
-
|
|
106
|
-
let failedToUpdateRange = false;
|
|
115
|
+
let updateCacheRangeFailed = false;
|
|
107
116
|
let errorsUpdated = false;
|
|
108
117
|
let lastCheckCancelAt = 0;
|
|
109
|
-
for (const
|
|
110
|
-
const oldSnapshot =
|
|
118
|
+
for (const cache of Object.values(lastResponse)) {
|
|
119
|
+
const oldSnapshot = cache.snapshot;
|
|
120
|
+
const oldDocument = cache.document;
|
|
111
121
|
const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
cache.snapshot = newSnapshot;
|
|
123
|
+
cache.document = newDocument;
|
|
124
|
+
if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
|
|
115
125
|
const changeRange = {
|
|
116
126
|
range: {
|
|
117
127
|
start: oldDocument.positionAt(change.span.start),
|
|
@@ -119,32 +129,121 @@ function register(context) {
|
|
|
119
129
|
},
|
|
120
130
|
newEnd: newDocument.positionAt(change.span.start + change.newLength),
|
|
121
131
|
};
|
|
122
|
-
for (const error of
|
|
132
|
+
for (const error of cache.errors) {
|
|
123
133
|
if (!updateRange(error.range, changeRange)) {
|
|
124
|
-
|
|
134
|
+
updateCacheRangeFailed = true;
|
|
125
135
|
break;
|
|
126
136
|
}
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
139
|
}
|
|
130
|
-
yield
|
|
140
|
+
yield lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules);
|
|
141
|
+
doResponse();
|
|
142
|
+
yield lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules);
|
|
143
|
+
doResponse();
|
|
144
|
+
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
145
|
+
doResponse();
|
|
146
|
+
yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion);
|
|
131
147
|
doResponse();
|
|
132
|
-
yield
|
|
148
|
+
yield lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules);
|
|
133
149
|
doResponse();
|
|
134
|
-
yield worker('onSemantic',
|
|
150
|
+
yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic);
|
|
135
151
|
doResponse();
|
|
136
|
-
yield worker('onDeclaration',
|
|
137
|
-
return
|
|
152
|
+
yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration);
|
|
153
|
+
return collectErrors();
|
|
138
154
|
function doResponse() {
|
|
139
|
-
if (errorsUpdated && !
|
|
140
|
-
response === null || response === void 0 ? void 0 : response(
|
|
155
|
+
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
156
|
+
response === null || response === void 0 ? void 0 : response(collectErrors());
|
|
141
157
|
errorsUpdated = false;
|
|
142
158
|
}
|
|
143
159
|
}
|
|
144
|
-
function
|
|
145
|
-
return Object.values(
|
|
160
|
+
function collectErrors() {
|
|
161
|
+
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
146
162
|
}
|
|
147
|
-
function
|
|
163
|
+
function lintWorker(api, cacheMap, cache) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const result = yield (0, featureWorkers_1.ruleWorker)(context, api, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
167
|
+
var _h, _j, _k, _l;
|
|
168
|
+
if (token) {
|
|
169
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
170
|
+
yield shared.sleep(5); // wait for LSP event polling
|
|
171
|
+
lastCheckCancelAt = Date.now();
|
|
172
|
+
}
|
|
173
|
+
if (token.isCancellationRequested) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const pluginCache = (_a = cacheMap.get(ruleName)) !== null && _a !== void 0 ? _a : cacheMap.set(ruleName, new Map()).get(ruleName);
|
|
178
|
+
const cache = pluginCache.get(ruleCtx.document.uri);
|
|
179
|
+
const tsProjectVersion = (api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
180
|
+
if (api === 'onSemantic') {
|
|
181
|
+
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
182
|
+
return cache.errors;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (cache && cache.documentVersion === ruleCtx.document.version) {
|
|
187
|
+
return cache.errors;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const reportResults = [];
|
|
191
|
+
ruleCtx.report = (error, ...fixes) => {
|
|
192
|
+
var _a, _b;
|
|
193
|
+
if (!vscode.Diagnostic.is(error)) {
|
|
194
|
+
console.warn('[volar/rules-api] report() error must be a Diagnostic.');
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
error.message || (error.message = 'No message.');
|
|
198
|
+
error.source || (error.source = 'rules');
|
|
199
|
+
error.code || (error.code = ruleCtx.ruleId);
|
|
200
|
+
const severity = (_b = (_a = context.config.lint) === null || _a === void 0 ? void 0 : _a.severities) === null || _b === void 0 ? void 0 : _b[ruleCtx.ruleId];
|
|
201
|
+
if (severity !== undefined) {
|
|
202
|
+
error.severity = severity;
|
|
203
|
+
}
|
|
204
|
+
reportResults.push([error, ...fixes]);
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
207
|
+
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
console.warn(`[volar/rules-api] ${ruleName} ${api} error.`);
|
|
211
|
+
console.warn(err);
|
|
212
|
+
}
|
|
213
|
+
(_e = context.ruleFixes) !== null && _e !== void 0 ? _e : (context.ruleFixes = {});
|
|
214
|
+
(_f = (_h = context.ruleFixes)[_j = ruleCtx.document.uri]) !== null && _f !== void 0 ? _f : (_h[_j] = {});
|
|
215
|
+
(_g = (_k = context.ruleFixes[ruleCtx.document.uri])[_l = ruleCtx.ruleId]) !== null && _g !== void 0 ? _g : (_k[_l] = {});
|
|
216
|
+
reportResults === null || reportResults === void 0 ? void 0 : reportResults.forEach(([error, ...fixes], index) => {
|
|
217
|
+
context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId][index] = [error, fixes];
|
|
218
|
+
error.data = {
|
|
219
|
+
uri,
|
|
220
|
+
version: newDocument.version,
|
|
221
|
+
type: 'rule',
|
|
222
|
+
isFormat: api === 'onFormat',
|
|
223
|
+
pluginOrRuleId: ruleCtx.ruleId,
|
|
224
|
+
original: {
|
|
225
|
+
data: error.data,
|
|
226
|
+
},
|
|
227
|
+
ruleFixIndex: index,
|
|
228
|
+
documentUri: ruleCtx.document.uri,
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
errorsUpdated = true;
|
|
232
|
+
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
233
|
+
pluginCache.set(ruleCtx.document.uri, {
|
|
234
|
+
documentVersion: ruleCtx.document.version,
|
|
235
|
+
errors,
|
|
236
|
+
tsProjectVersion,
|
|
237
|
+
});
|
|
238
|
+
return errors;
|
|
239
|
+
}), api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
|
|
240
|
+
if (result) {
|
|
241
|
+
cache.errors = result;
|
|
242
|
+
cache.snapshot = newSnapshot;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function worker(api, cacheMap, cache) {
|
|
148
247
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
248
|
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
150
249
|
if (file.capabilities.diagnostic) {
|
|
@@ -157,14 +256,15 @@ function register(context) {
|
|
|
157
256
|
yield shared.sleep(5); // wait for LSP event polling
|
|
158
257
|
lastCheckCancelAt = Date.now();
|
|
159
258
|
}
|
|
160
|
-
if (token.isCancellationRequested)
|
|
259
|
+
if (token.isCancellationRequested) {
|
|
161
260
|
return;
|
|
261
|
+
}
|
|
162
262
|
}
|
|
163
|
-
const pluginId = context.plugins.
|
|
263
|
+
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
164
264
|
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
165
265
|
const cache = pluginCache.get(document.uri);
|
|
166
|
-
const tsProjectVersion = (
|
|
167
|
-
if (
|
|
266
|
+
const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
267
|
+
if (api === 'onDeclaration' || api === 'onSemantic') {
|
|
168
268
|
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
169
269
|
return cache.errors;
|
|
170
270
|
}
|
|
@@ -174,7 +274,21 @@ function register(context) {
|
|
|
174
274
|
return cache.errors;
|
|
175
275
|
}
|
|
176
276
|
}
|
|
177
|
-
const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[
|
|
277
|
+
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));
|
|
278
|
+
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
279
|
+
error.data = {
|
|
280
|
+
uri,
|
|
281
|
+
version: newDocument.version,
|
|
282
|
+
type: 'plugin',
|
|
283
|
+
pluginOrRuleId: pluginId,
|
|
284
|
+
isFormat: false,
|
|
285
|
+
original: {
|
|
286
|
+
data: error.data,
|
|
287
|
+
},
|
|
288
|
+
ruleFixIndex: 0,
|
|
289
|
+
documentUri: document.uri,
|
|
290
|
+
};
|
|
291
|
+
});
|
|
178
292
|
errorsUpdated = true;
|
|
179
293
|
pluginCache.set(document.uri, {
|
|
180
294
|
documentVersion: document.version,
|
|
@@ -182,7 +296,7 @@ function register(context) {
|
|
|
182
296
|
tsProjectVersion,
|
|
183
297
|
});
|
|
184
298
|
return errors;
|
|
185
|
-
}),
|
|
299
|
+
}), transformErrorRange, arr => dedupe.withDiagnostics(arr.flat()));
|
|
186
300
|
if (result) {
|
|
187
301
|
cache.errors = result;
|
|
188
302
|
cache.snapshot = newSnapshot;
|
|
@@ -190,7 +304,23 @@ function register(context) {
|
|
|
190
304
|
});
|
|
191
305
|
}
|
|
192
306
|
});
|
|
193
|
-
function
|
|
307
|
+
function transformFormatErrorRange(errors, map) {
|
|
308
|
+
const result = [];
|
|
309
|
+
for (const error of errors) {
|
|
310
|
+
// clone it to avoid modify cache
|
|
311
|
+
let _error = Object.assign({}, error);
|
|
312
|
+
if (map) {
|
|
313
|
+
const range = map.toSourceRange(error.range);
|
|
314
|
+
if (!range) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
_error.range = range;
|
|
318
|
+
}
|
|
319
|
+
result.push(_error);
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
function transformErrorRange(errors, map) {
|
|
194
324
|
const result = [];
|
|
195
325
|
for (const error of errors) {
|
|
196
326
|
// clone it to avoid modify cache
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function register(context:
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (query: string) => Promise<vscode.SymbolInformation[]>;
|
|
@@ -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);
|
|
@@ -4,17 +4,17 @@ function transform(ranges, getOtherRange) {
|
|
|
4
4
|
var _a, _b;
|
|
5
5
|
const result = [];
|
|
6
6
|
for (const range of ranges) {
|
|
7
|
-
const
|
|
7
|
+
const otherRange = getOtherRange({
|
|
8
8
|
start: { line: range.startLine, character: (_a = range.startCharacter) !== null && _a !== void 0 ? _a : 0 },
|
|
9
9
|
end: { line: range.endLine, character: (_b = range.endCharacter) !== null && _b !== void 0 ? _b : 0 },
|
|
10
10
|
});
|
|
11
|
-
if (
|
|
12
|
-
range.startLine =
|
|
13
|
-
range.endLine =
|
|
11
|
+
if (otherRange) {
|
|
12
|
+
range.startLine = otherRange.start.line;
|
|
13
|
+
range.endLine = otherRange.end.line;
|
|
14
14
|
if (range.startCharacter !== undefined)
|
|
15
|
-
range.startCharacter =
|
|
15
|
+
range.startCharacter = otherRange.start.character;
|
|
16
16
|
if (range.endCharacter !== undefined)
|
|
17
|
-
range.endCharacter =
|
|
17
|
+
range.endCharacter = otherRange.end.character;
|
|
18
18
|
result.push(range);
|
|
19
19
|
}
|
|
20
20
|
}
|