@volar/language-service 1.4.0-alpha.0 → 1.4.0-alpha.1
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 +1 -1
- package/out/baseLanguageService.js +20 -16
- package/out/documentFeatures/colorPresentations.js +1 -2
- package/out/documentFeatures/documentColors.js +1 -2
- package/out/documentFeatures/documentSymbols.js +4 -15
- package/out/documentFeatures/foldingRanges.js +1 -2
- package/out/documentFeatures/format.js +29 -42
- package/out/documentFeatures/linkedEditingRanges.js +1 -2
- package/out/documentFeatures/selectionRanges.js +1 -2
- package/out/documents.js +1 -2
- package/out/languageFeatures/autoInsert.js +7 -6
- package/out/languageFeatures/callHierarchy.js +63 -72
- package/out/languageFeatures/codeActionResolve.js +9 -19
- package/out/languageFeatures/codeActions.js +22 -28
- package/out/languageFeatures/codeLens.js +16 -24
- package/out/languageFeatures/codeLensResolve.js +7 -17
- package/out/languageFeatures/complete.js +20 -32
- package/out/languageFeatures/completeResolve.js +5 -15
- package/out/languageFeatures/definition.js +35 -44
- package/out/languageFeatures/documentHighlights.js +30 -39
- package/out/languageFeatures/documentLinks.js +9 -17
- package/out/languageFeatures/documentSemanticTokens.js +6 -16
- package/out/languageFeatures/fileReferences.js +3 -13
- package/out/languageFeatures/fileRename.js +5 -15
- package/out/languageFeatures/hover.js +5 -9
- package/out/languageFeatures/inlayHints.js +13 -19
- package/out/languageFeatures/references.js +26 -38
- package/out/languageFeatures/rename.js +54 -68
- package/out/languageFeatures/renamePrepare.js +1 -2
- package/out/languageFeatures/signatureHelp.js +6 -7
- package/out/languageFeatures/validation.js +134 -152
- package/out/languageFeatures/workspaceSymbols.js +3 -12
- package/out/transformer/completionItem.js +8 -3
- package/out/transformer/completionList.js +6 -3
- package/out/transformer/documentSymbol.js +8 -3
- package/out/transformer/foldingRanges.js +2 -3
- package/out/transformer/hover.js +5 -2
- package/out/transformer/locationLike.js +4 -1
- package/out/transformer/textEdit.js +20 -5
- package/out/transformer/workspaceSymbol.js +4 -1
- package/out/types.d.ts +3 -3
- package/out/utils/definePlugin.js +11 -23
- package/out/utils/featureWorkers.js +126 -146
- package/package.json +4 -4
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.embeddedEditToSourceEdit = exports.mergeWorkspaceEdits = exports.register = void 0;
|
|
12
3
|
const vscode = require("vscode-languageserver-protocol");
|
|
@@ -27,68 +18,65 @@ function register(context) {
|
|
|
27
18
|
yield { position: mapped, newName };
|
|
28
19
|
}
|
|
29
20
|
;
|
|
30
|
-
}, (plugin, document, arg) =>
|
|
21
|
+
}, async (plugin, document, arg) => {
|
|
31
22
|
if (token.isCancellationRequested)
|
|
32
23
|
return;
|
|
33
24
|
const recursiveChecker = dedupe.createLocationSet();
|
|
34
25
|
let result;
|
|
35
|
-
|
|
26
|
+
await withMirrors(document, arg.position, arg.newName);
|
|
36
27
|
return result;
|
|
37
|
-
function withMirrors(document, position, newName) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
foundMirrorPosition = true;
|
|
64
|
-
yield withMirrors(mirrorMap.document, mapped[0], newName);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (!foundMirrorPosition) {
|
|
68
|
-
if (!result.changes)
|
|
69
|
-
result.changes = {};
|
|
70
|
-
if (!result.changes[editUri])
|
|
71
|
-
result.changes[editUri] = [];
|
|
72
|
-
result.changes[editUri].push(textEdit);
|
|
28
|
+
async function withMirrors(document, position, newName) {
|
|
29
|
+
if (!plugin.provideRenameEdits)
|
|
30
|
+
return;
|
|
31
|
+
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
|
|
32
|
+
return;
|
|
33
|
+
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
|
34
|
+
const workspaceEdit = await plugin.provideRenameEdits(document, position, newName, token);
|
|
35
|
+
if (!workspaceEdit)
|
|
36
|
+
return;
|
|
37
|
+
if (!result)
|
|
38
|
+
result = {};
|
|
39
|
+
if (workspaceEdit.changes) {
|
|
40
|
+
for (const editUri in workspaceEdit.changes) {
|
|
41
|
+
const textEdits = workspaceEdit.changes[editUri];
|
|
42
|
+
for (const textEdit of textEdits) {
|
|
43
|
+
let foundMirrorPosition = false;
|
|
44
|
+
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
|
|
45
|
+
const mirrorMap = context.documents.getMirrorMapByUri(editUri)?.[1];
|
|
46
|
+
if (mirrorMap) {
|
|
47
|
+
for (const mapped of mirrorMap.findMirrorPositions(textEdit.range.start)) {
|
|
48
|
+
if (!mapped[1].rename)
|
|
49
|
+
continue;
|
|
50
|
+
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
|
|
51
|
+
continue;
|
|
52
|
+
foundMirrorPosition = true;
|
|
53
|
+
await withMirrors(mirrorMap.document, mapped[0], newName);
|
|
73
54
|
}
|
|
74
55
|
}
|
|
56
|
+
if (!foundMirrorPosition) {
|
|
57
|
+
if (!result.changes)
|
|
58
|
+
result.changes = {};
|
|
59
|
+
if (!result.changes[editUri])
|
|
60
|
+
result.changes[editUri] = [];
|
|
61
|
+
result.changes[editUri].push(textEdit);
|
|
62
|
+
}
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
result.changeAnnotations
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (workspaceEdit.documentChanges) {
|
|
85
|
-
if (!result.documentChanges)
|
|
86
|
-
result.documentChanges = [];
|
|
87
|
-
result.documentChanges = result.documentChanges.concat(workspaceEdit.documentChanges);
|
|
65
|
+
}
|
|
66
|
+
if (workspaceEdit.changeAnnotations) {
|
|
67
|
+
for (const uri in workspaceEdit.changeAnnotations) {
|
|
68
|
+
if (!result.changeAnnotations)
|
|
69
|
+
result.changeAnnotations = {};
|
|
70
|
+
result.changeAnnotations[uri] = workspaceEdit.changeAnnotations[uri];
|
|
88
71
|
}
|
|
89
|
-
}
|
|
72
|
+
}
|
|
73
|
+
if (workspaceEdit.documentChanges) {
|
|
74
|
+
if (!result.documentChanges)
|
|
75
|
+
result.documentChanges = [];
|
|
76
|
+
result.documentChanges = result.documentChanges.concat(workspaceEdit.documentChanges);
|
|
77
|
+
}
|
|
90
78
|
}
|
|
91
|
-
}
|
|
79
|
+
}, (data) => {
|
|
92
80
|
return embeddedEditToSourceEdit(data, context.documents, 'rename');
|
|
93
81
|
}, (workspaceEdits) => {
|
|
94
82
|
const mainEdit = workspaceEdits[0];
|
|
@@ -134,12 +122,10 @@ function mergeWorkspaceEdits(original, ...others) {
|
|
|
134
122
|
}
|
|
135
123
|
exports.mergeWorkspaceEdits = mergeWorkspaceEdits;
|
|
136
124
|
function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
137
|
-
var _a, _b, _c, _d, _e, _f;
|
|
138
|
-
var _g, _h, _j, _k;
|
|
139
125
|
const sourceResult = {};
|
|
140
126
|
let hasResult = false;
|
|
141
127
|
for (const tsUri in tsResult.changeAnnotations) {
|
|
142
|
-
|
|
128
|
+
sourceResult.changeAnnotations ??= {};
|
|
143
129
|
const tsAnno = tsResult.changeAnnotations[tsUri];
|
|
144
130
|
if (!documents.hasVirtualFileByUri(tsUri)) {
|
|
145
131
|
sourceResult.changeAnnotations[tsUri] = tsAnno;
|
|
@@ -153,7 +139,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
153
139
|
}
|
|
154
140
|
}
|
|
155
141
|
for (const tsUri in tsResult.changes) {
|
|
156
|
-
|
|
142
|
+
sourceResult.changes ??= {};
|
|
157
143
|
if (!documents.hasVirtualFileByUri(tsUri)) {
|
|
158
144
|
sourceResult.changes[tsUri] = tsResult.changes[tsUri];
|
|
159
145
|
hasResult = true;
|
|
@@ -173,7 +159,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
173
159
|
if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
|
|
174
160
|
newText = _data.rename.apply(tsEdit.newText);
|
|
175
161
|
}
|
|
176
|
-
|
|
162
|
+
sourceResult.changes[map.sourceFileDocument.uri] ??= [];
|
|
177
163
|
sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range });
|
|
178
164
|
hasResult = true;
|
|
179
165
|
}
|
|
@@ -181,7 +167,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
181
167
|
else {
|
|
182
168
|
const range = map.toSourceRange(tsEdit.range);
|
|
183
169
|
if (range) {
|
|
184
|
-
|
|
170
|
+
sourceResult.changes[map.sourceFileDocument.uri] ??= [];
|
|
185
171
|
sourceResult.changes[map.sourceFileDocument.uri].push({ newText: tsEdit.newText, range });
|
|
186
172
|
hasResult = true;
|
|
187
173
|
}
|
|
@@ -191,14 +177,14 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
191
177
|
}
|
|
192
178
|
if (tsResult.documentChanges) {
|
|
193
179
|
for (const tsDocEdit of tsResult.documentChanges) {
|
|
194
|
-
|
|
180
|
+
sourceResult.documentChanges ??= [];
|
|
195
181
|
let sourceEdit;
|
|
196
182
|
if (vscode.TextDocumentEdit.is(tsDocEdit)) {
|
|
197
183
|
if (documents.hasVirtualFileByUri(tsDocEdit.textDocument.uri)) {
|
|
198
184
|
for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.textDocument.uri)) {
|
|
199
185
|
sourceEdit = vscode.TextDocumentEdit.create({
|
|
200
186
|
uri: map.sourceFileDocument.uri,
|
|
201
|
-
version:
|
|
187
|
+
version: versions[map.sourceFileDocument.uri] ?? null,
|
|
202
188
|
}, []);
|
|
203
189
|
for (const tsEdit of tsDocEdit.edits) {
|
|
204
190
|
if (mode === 'rename' || mode === 'fileName') {
|
|
@@ -5,10 +5,9 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (uri, position, token) => {
|
|
7
7
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => {
|
|
8
|
-
var _a;
|
|
9
8
|
if (token.isCancellationRequested)
|
|
10
9
|
return;
|
|
11
|
-
return
|
|
10
|
+
return plugin.provideRenameRange?.(document, position, token);
|
|
12
11
|
}, (item, map) => {
|
|
13
12
|
if (!map) {
|
|
14
13
|
return item;
|
|
@@ -4,22 +4,21 @@ const vscode = require("vscode-languageserver-protocol");
|
|
|
4
4
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (uri, position, signatureHelpContext, token) => {
|
|
7
|
-
signatureHelpContext
|
|
7
|
+
signatureHelpContext ??= {
|
|
8
8
|
triggerKind: vscode.SignatureHelpTriggerKind.Invoked,
|
|
9
9
|
isRetrigger: false,
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => {
|
|
12
|
-
var _a, _b;
|
|
13
12
|
if (token.isCancellationRequested)
|
|
14
13
|
return;
|
|
15
|
-
if (
|
|
14
|
+
if (signatureHelpContext?.triggerKind === vscode.SignatureHelpTriggerKind.TriggerCharacter
|
|
16
15
|
&& signatureHelpContext.triggerCharacter
|
|
17
|
-
&& !(
|
|
16
|
+
&& !(signatureHelpContext.isRetrigger
|
|
18
17
|
? plugin.signatureHelpRetriggerCharacters
|
|
19
|
-
: plugin.signatureHelpTriggerCharacters)
|
|
18
|
+
: plugin.signatureHelpTriggerCharacters)?.includes(signatureHelpContext.triggerCharacter)) {
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
|
-
return
|
|
21
|
+
return plugin.provideSignatureHelp?.(document, position, signatureHelpContext, token);
|
|
23
22
|
}, (data) => data);
|
|
24
23
|
};
|
|
25
24
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = exports.updateRange = void 0;
|
|
12
3
|
const vscode = require("vscode-languageserver-protocol");
|
|
@@ -94,13 +85,12 @@ function register(context) {
|
|
|
94
85
|
syntax_rules: new Map(),
|
|
95
86
|
format_rules: new Map(),
|
|
96
87
|
};
|
|
97
|
-
return (uri, token, mode, response) =>
|
|
98
|
-
var _a;
|
|
88
|
+
return async (uri, token, mode, response) => {
|
|
99
89
|
const newDocument = context.getTextDocument(uri);
|
|
100
90
|
if (!newDocument) {
|
|
101
91
|
return [];
|
|
102
92
|
}
|
|
103
|
-
const lastResponse =
|
|
93
|
+
const lastResponse = lastResponses.get(uri) ?? lastResponses.set(uri, {
|
|
104
94
|
semantic: { errors: [] },
|
|
105
95
|
syntactic: { errors: [] },
|
|
106
96
|
semantic_rules: { errors: [] },
|
|
@@ -114,7 +104,7 @@ function register(context) {
|
|
|
114
104
|
for (const cache of Object.values(lastResponse)) {
|
|
115
105
|
const oldSnapshot = cache.snapshot;
|
|
116
106
|
const oldDocument = cache.document;
|
|
117
|
-
const change = oldSnapshot ? newSnapshot
|
|
107
|
+
const change = oldSnapshot ? newSnapshot?.getChangeRange(oldSnapshot) : undefined;
|
|
118
108
|
cache.snapshot = newSnapshot;
|
|
119
109
|
cache.document = newDocument;
|
|
120
110
|
if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
|
|
@@ -134,177 +124,169 @@ function register(context) {
|
|
|
134
124
|
}
|
|
135
125
|
}
|
|
136
126
|
if (mode === 'all' || mode === 'syntactic') {
|
|
137
|
-
|
|
127
|
+
await lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules);
|
|
138
128
|
doResponse();
|
|
139
|
-
|
|
129
|
+
await lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules);
|
|
140
130
|
doResponse();
|
|
141
|
-
|
|
131
|
+
await worker('provideSyntacticDiagnostics', cacheMaps.syntactic, lastResponse.syntactic);
|
|
142
132
|
doResponse();
|
|
143
133
|
}
|
|
144
134
|
if (mode === 'all' || mode === 'semantic') {
|
|
145
|
-
|
|
135
|
+
await lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules);
|
|
146
136
|
doResponse();
|
|
147
|
-
|
|
137
|
+
await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic);
|
|
148
138
|
}
|
|
149
139
|
return collectErrors();
|
|
150
140
|
function doResponse() {
|
|
151
141
|
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
152
|
-
response
|
|
142
|
+
response?.(collectErrors());
|
|
153
143
|
errorsUpdated = false;
|
|
154
144
|
}
|
|
155
145
|
}
|
|
156
146
|
function collectErrors() {
|
|
157
147
|
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
158
148
|
}
|
|
159
|
-
function lintWorker(api, cacheMap, cache) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
166
|
-
yield (0, common_1.sleep)(5); // wait for LSP event polling
|
|
167
|
-
lastCheckCancelAt = Date.now();
|
|
168
|
-
}
|
|
169
|
-
if (token.isCancellationRequested) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
149
|
+
async function lintWorker(api, cacheMap, cache) {
|
|
150
|
+
const result = await (0, featureWorkers_1.ruleWorker)(context, api, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, async (ruleName, rule, ruleCtx) => {
|
|
151
|
+
if (token) {
|
|
152
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
153
|
+
await (0, common_1.sleep)(5); // wait for LSP event polling
|
|
154
|
+
lastCheckCancelAt = Date.now();
|
|
172
155
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const tsProjectVersion = (api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
176
|
-
if (api === 'onSemantic') {
|
|
177
|
-
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
178
|
-
return cache.errors;
|
|
179
|
-
}
|
|
156
|
+
if (token.isCancellationRequested) {
|
|
157
|
+
return;
|
|
180
158
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
159
|
+
}
|
|
160
|
+
const pluginCache = cacheMap.get(ruleName) ?? cacheMap.set(ruleName, new Map()).get(ruleName);
|
|
161
|
+
const cache = pluginCache.get(ruleCtx.document.uri);
|
|
162
|
+
const tsProjectVersion = (api === 'onSemantic') ? context.core.typescript.languageServiceHost.getProjectVersion?.() : undefined;
|
|
163
|
+
if (api === 'onSemantic') {
|
|
164
|
+
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
165
|
+
return cache.errors;
|
|
185
166
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
console.warn('[volar/rules-api] report() error must be a Diagnostic.');
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
error.message || (error.message = 'No message.');
|
|
194
|
-
error.source || (error.source = 'rules');
|
|
195
|
-
error.code || (error.code = ruleCtx.ruleId);
|
|
196
|
-
const severity = (_b = (_a = context.config.lint) === null || _a === void 0 ? void 0 : _a.severities) === null || _b === void 0 ? void 0 : _b[ruleCtx.ruleId];
|
|
197
|
-
if (severity !== undefined) {
|
|
198
|
-
error.severity = severity;
|
|
199
|
-
}
|
|
200
|
-
reportResults.push([error, ...fixes]);
|
|
201
|
-
};
|
|
202
|
-
try {
|
|
203
|
-
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (cache && cache.documentVersion === ruleCtx.document.version) {
|
|
170
|
+
return cache.errors;
|
|
204
171
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
172
|
+
}
|
|
173
|
+
const reportResults = [];
|
|
174
|
+
ruleCtx.report = (error, ...fixes) => {
|
|
175
|
+
if (!vscode.Diagnostic.is(error)) {
|
|
176
|
+
console.warn('[volar/rules-api] report() error must be a Diagnostic.');
|
|
177
|
+
return;
|
|
208
178
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
error.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
documentUri: ruleCtx.document.uri,
|
|
225
|
-
};
|
|
226
|
-
});
|
|
227
|
-
errorsUpdated = true;
|
|
228
|
-
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
229
|
-
pluginCache.set(ruleCtx.document.uri, {
|
|
230
|
-
documentVersion: ruleCtx.document.version,
|
|
231
|
-
errors,
|
|
232
|
-
tsProjectVersion,
|
|
233
|
-
});
|
|
234
|
-
return errors;
|
|
235
|
-
}), api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
|
|
236
|
-
if (result) {
|
|
237
|
-
cache.errors = result;
|
|
238
|
-
cache.snapshot = newSnapshot;
|
|
179
|
+
error.message ||= 'No message.';
|
|
180
|
+
error.source ||= 'rules';
|
|
181
|
+
error.code ||= ruleCtx.ruleId;
|
|
182
|
+
const severity = context.config.lint?.severities?.[ruleCtx.ruleId];
|
|
183
|
+
if (severity !== undefined) {
|
|
184
|
+
error.severity = severity;
|
|
185
|
+
}
|
|
186
|
+
reportResults.push([error, ...fixes]);
|
|
187
|
+
};
|
|
188
|
+
try {
|
|
189
|
+
await rule[api]?.(ruleCtx);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
console.warn(`[volar/rules-api] ${ruleName} ${api} error.`);
|
|
193
|
+
console.warn(err);
|
|
239
194
|
}
|
|
240
|
-
|
|
195
|
+
context.ruleFixes ??= {};
|
|
196
|
+
context.ruleFixes[ruleCtx.document.uri] ??= {};
|
|
197
|
+
context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId] ??= {};
|
|
198
|
+
reportResults?.forEach(([error, ...fixes], index) => {
|
|
199
|
+
context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId][index] = [error, fixes];
|
|
200
|
+
error.data = {
|
|
201
|
+
uri,
|
|
202
|
+
version: newDocument.version,
|
|
203
|
+
type: 'rule',
|
|
204
|
+
isFormat: api === 'onFormat',
|
|
205
|
+
pluginOrRuleId: ruleCtx.ruleId,
|
|
206
|
+
original: {
|
|
207
|
+
data: error.data,
|
|
208
|
+
},
|
|
209
|
+
ruleFixIndex: index,
|
|
210
|
+
documentUri: ruleCtx.document.uri,
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
errorsUpdated = true;
|
|
214
|
+
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
215
|
+
pluginCache.set(ruleCtx.document.uri, {
|
|
216
|
+
documentVersion: ruleCtx.document.version,
|
|
217
|
+
errors,
|
|
218
|
+
tsProjectVersion,
|
|
219
|
+
});
|
|
220
|
+
return errors;
|
|
221
|
+
}, api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
|
|
222
|
+
if (result) {
|
|
223
|
+
cache.errors = result;
|
|
224
|
+
cache.snapshot = newSnapshot;
|
|
225
|
+
}
|
|
241
226
|
}
|
|
242
|
-
function worker(api, cacheMap, cache) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
227
|
+
async function worker(api, cacheMap, cache) {
|
|
228
|
+
const result = await (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
229
|
+
if (file.capabilities.diagnostic) {
|
|
230
|
+
yield arg;
|
|
231
|
+
}
|
|
232
|
+
}, async (plugin, document) => {
|
|
233
|
+
if (token) {
|
|
234
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
235
|
+
await (0, common_1.sleep)(5); // waiting LSP event polling
|
|
236
|
+
lastCheckCancelAt = Date.now();
|
|
247
237
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (token) {
|
|
251
|
-
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
252
|
-
yield (0, common_1.sleep)(5); // waiting LSP event polling
|
|
253
|
-
lastCheckCancelAt = Date.now();
|
|
254
|
-
}
|
|
255
|
-
if (token.isCancellationRequested) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
238
|
+
if (token.isCancellationRequested) {
|
|
239
|
+
return;
|
|
258
240
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
241
|
+
}
|
|
242
|
+
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
243
|
+
const pluginCache = cacheMap.get(pluginId) ?? cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
244
|
+
const cache = pluginCache.get(document.uri);
|
|
245
|
+
const tsProjectVersion = api === 'provideSemanticDiagnostics' ? context.core.typescript.languageServiceHost.getProjectVersion?.() : undefined;
|
|
246
|
+
if (api === 'provideSemanticDiagnostics') {
|
|
247
|
+
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
248
|
+
return cache.errors;
|
|
267
249
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
if (cache && cache.documentVersion === document.version) {
|
|
253
|
+
return cache.errors;
|
|
272
254
|
}
|
|
273
|
-
const errors = yield ((_d = plugin[api]) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token));
|
|
274
|
-
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
275
|
-
error.data = {
|
|
276
|
-
uri,
|
|
277
|
-
version: newDocument.version,
|
|
278
|
-
type: 'plugin',
|
|
279
|
-
pluginOrRuleId: pluginId,
|
|
280
|
-
isFormat: false,
|
|
281
|
-
original: {
|
|
282
|
-
data: error.data,
|
|
283
|
-
},
|
|
284
|
-
ruleFixIndex: 0,
|
|
285
|
-
documentUri: document.uri,
|
|
286
|
-
};
|
|
287
|
-
});
|
|
288
|
-
errorsUpdated = true;
|
|
289
|
-
pluginCache.set(document.uri, {
|
|
290
|
-
documentVersion: document.version,
|
|
291
|
-
errors,
|
|
292
|
-
tsProjectVersion,
|
|
293
|
-
});
|
|
294
|
-
return errors;
|
|
295
|
-
}), transformErrorRange, arr => dedupe.withDiagnostics(arr.flat()));
|
|
296
|
-
if (result) {
|
|
297
|
-
cache.errors = result;
|
|
298
|
-
cache.snapshot = newSnapshot;
|
|
299
255
|
}
|
|
300
|
-
|
|
256
|
+
const errors = await plugin[api]?.(document, token);
|
|
257
|
+
errors?.forEach(error => {
|
|
258
|
+
error.data = {
|
|
259
|
+
uri,
|
|
260
|
+
version: newDocument.version,
|
|
261
|
+
type: 'plugin',
|
|
262
|
+
pluginOrRuleId: pluginId,
|
|
263
|
+
isFormat: false,
|
|
264
|
+
original: {
|
|
265
|
+
data: error.data,
|
|
266
|
+
},
|
|
267
|
+
ruleFixIndex: 0,
|
|
268
|
+
documentUri: document.uri,
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
errorsUpdated = true;
|
|
272
|
+
pluginCache.set(document.uri, {
|
|
273
|
+
documentVersion: document.version,
|
|
274
|
+
errors,
|
|
275
|
+
tsProjectVersion,
|
|
276
|
+
});
|
|
277
|
+
return errors;
|
|
278
|
+
}, transformErrorRange, arr => dedupe.withDiagnostics(arr.flat()));
|
|
279
|
+
if (result) {
|
|
280
|
+
cache.errors = result;
|
|
281
|
+
cache.snapshot = newSnapshot;
|
|
282
|
+
}
|
|
301
283
|
}
|
|
302
|
-
}
|
|
284
|
+
};
|
|
303
285
|
function transformFormatErrorRange(errors, map) {
|
|
304
286
|
const result = [];
|
|
305
287
|
for (const error of errors) {
|
|
306
288
|
// clone it to avoid modify cache
|
|
307
|
-
let _error =
|
|
289
|
+
let _error = { ...error };
|
|
308
290
|
if (map) {
|
|
309
291
|
const range = map.toSourceRange(error.range);
|
|
310
292
|
if (!range) {
|
|
@@ -320,7 +302,7 @@ function register(context) {
|
|
|
320
302
|
const result = [];
|
|
321
303
|
for (const error of errors) {
|
|
322
304
|
// clone it to avoid modify cache
|
|
323
|
-
let _error =
|
|
305
|
+
let _error = { ...error };
|
|
324
306
|
if (map) {
|
|
325
307
|
const range = map.toSourceRange(error.range, data => !!data.diagnostic);
|
|
326
308
|
if (!range) {
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = void 0;
|
|
12
3
|
const transformer = require("../transformer");
|
|
13
4
|
const vscode = require("vscode-languageserver-protocol");
|
|
14
5
|
const common_1 = require("../utils/common");
|
|
15
6
|
function register(context) {
|
|
16
|
-
return (query, token) =>
|
|
7
|
+
return async (query, token) => {
|
|
17
8
|
const symbolsList = [];
|
|
18
9
|
for (const plugin of Object.values(context.plugins)) {
|
|
19
10
|
if (token.isCancellationRequested)
|
|
20
11
|
break;
|
|
21
12
|
if (!plugin.provideWorkspaceSymbols)
|
|
22
13
|
continue;
|
|
23
|
-
const embeddedSymbols =
|
|
14
|
+
const embeddedSymbols = await plugin.provideWorkspaceSymbols(query, token);
|
|
24
15
|
if (!embeddedSymbols)
|
|
25
16
|
continue;
|
|
26
17
|
const symbols = embeddedSymbols.map(symbol => transformer.asWorkspaceSymbol(symbol, loc => {
|
|
@@ -39,7 +30,7 @@ function register(context) {
|
|
|
39
30
|
symbolsList.push(symbols);
|
|
40
31
|
}
|
|
41
32
|
return symbolsList.flat();
|
|
42
|
-
}
|
|
33
|
+
};
|
|
43
34
|
}
|
|
44
35
|
exports.register = register;
|
|
45
36
|
//# sourceMappingURL=workspaceSymbols.js.map
|