@volar/language-service 1.2.0-alpha.1 → 1.2.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/baseLanguageService.d.ts +3 -5
- package/out/baseLanguageService.js +11 -14
- 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 +84 -151
- 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 +3 -3
- package/out/languageFeatures/callHierarchy.js +5 -3
- package/out/languageFeatures/codeActionResolve.d.ts +2 -2
- package/out/languageFeatures/codeActionResolve.js +28 -15
- package/out/languageFeatures/codeActions.d.ts +15 -6
- package/out/languageFeatures/codeActions.js +94 -22
- package/out/languageFeatures/codeLens.d.ts +11 -4
- package/out/languageFeatures/codeLens.js +25 -15
- package/out/languageFeatures/codeLensResolve.d.ts +4 -2
- package/out/languageFeatures/codeLensResolve.js +20 -12
- package/out/languageFeatures/complete.d.ts +3 -3
- package/out/languageFeatures/complete.js +20 -4
- package/out/languageFeatures/completeResolve.d.ts +2 -2
- package/out/languageFeatures/completeResolve.js +3 -14
- 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 +1 -1
- 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 +7 -3
- package/out/languageFeatures/validation.js +68 -15
- package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
- package/out/transformer/foldingRanges.js +6 -6
- package/out/types.d.ts +90 -39
- package/out/utils/featureWorkers.d.ts +4 -4
- package/out/utils/featureWorkers.js +44 -11
- package/package.json +9 -9
- package/out/languageFeatures/executeCommand.d.ts +0 -11
- package/out/languageFeatures/executeCommand.js +0 -32
- package/out/languageFeatures/validation copy.d.ts +0 -7
- package/out/languageFeatures/validation copy.js +0 -234
|
@@ -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,13 +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
7
|
export interface PluginDiagnosticData {
|
|
8
8
|
uri: string;
|
|
9
|
-
|
|
9
|
+
version: number;
|
|
10
|
+
original: Pick<vscode.Diagnostic, 'data'>;
|
|
10
11
|
type: 'plugin' | 'rule';
|
|
12
|
+
isFormat: boolean;
|
|
11
13
|
pluginOrRuleId: string;
|
|
14
|
+
ruleFixIndex: number;
|
|
15
|
+
documentUri: string;
|
|
12
16
|
}
|
|
13
|
-
export declare function register(context:
|
|
17
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
@@ -10,6 +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 vscode = require("vscode-languageserver-protocol");
|
|
13
14
|
const dedupe = require("../utils/dedupe");
|
|
14
15
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
15
16
|
function updateRange(range, change) {
|
|
@@ -92,22 +93,25 @@ function register(context) {
|
|
|
92
93
|
syntactic: new Map(),
|
|
93
94
|
suggestion: new Map(),
|
|
94
95
|
semantic_rules: new Map(),
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
syntax_rules: new Map(),
|
|
97
|
+
format_rules: new Map(),
|
|
97
98
|
};
|
|
98
99
|
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
|
|
99
100
|
var _a;
|
|
101
|
+
const newDocument = context.getTextDocument(uri);
|
|
102
|
+
if (!newDocument) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
100
105
|
const lastResponse = (_a = lastResponses.get(uri)) !== null && _a !== void 0 ? _a : lastResponses.set(uri, {
|
|
101
106
|
semantic: { errors: [] },
|
|
102
107
|
declaration: { errors: [] },
|
|
103
108
|
suggestion: { errors: [] },
|
|
104
109
|
syntactic: { errors: [] },
|
|
105
110
|
semantic_rules: { errors: [] },
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
syntax_rules: { errors: [] },
|
|
112
|
+
format_rules: { errors: [] },
|
|
108
113
|
}).get(uri);
|
|
109
114
|
const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
|
|
110
|
-
const newDocument = context.getTextDocument(uri);
|
|
111
115
|
let updateCacheRangeFailed = false;
|
|
112
116
|
let errorsUpdated = false;
|
|
113
117
|
let lastCheckCancelAt = 0;
|
|
@@ -133,9 +137,9 @@ function register(context) {
|
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
|
-
yield lintWorker('onFormat', cacheMaps.
|
|
140
|
+
yield lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules);
|
|
137
141
|
doResponse();
|
|
138
|
-
yield lintWorker('onSyntax', cacheMaps.
|
|
142
|
+
yield lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules);
|
|
139
143
|
doResponse();
|
|
140
144
|
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
141
145
|
doResponse();
|
|
@@ -158,8 +162,9 @@ function register(context) {
|
|
|
158
162
|
}
|
|
159
163
|
function lintWorker(api, cacheMap, cache) {
|
|
160
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const result = yield (0, featureWorkers_1.ruleWorker)(context, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
var _a, _b, _c, _d;
|
|
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;
|
|
163
168
|
if (token) {
|
|
164
169
|
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
165
170
|
yield shared.sleep(5); // wait for LSP event polling
|
|
@@ -184,28 +189,54 @@ function register(context) {
|
|
|
184
189
|
}
|
|
185
190
|
const reportResults = [];
|
|
186
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.');
|
|
187
198
|
error.source || (error.source = 'rules');
|
|
188
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
|
+
}
|
|
189
204
|
reportResults.push([error, ...fixes]);
|
|
190
205
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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];
|
|
194
218
|
error.data = {
|
|
195
219
|
uri,
|
|
220
|
+
version: newDocument.version,
|
|
196
221
|
type: 'rule',
|
|
222
|
+
isFormat: api === 'onFormat',
|
|
197
223
|
pluginOrRuleId: ruleCtx.ruleId,
|
|
198
|
-
|
|
224
|
+
original: {
|
|
225
|
+
data: error.data,
|
|
226
|
+
},
|
|
227
|
+
ruleFixIndex: index,
|
|
228
|
+
documentUri: ruleCtx.document.uri,
|
|
199
229
|
};
|
|
200
230
|
});
|
|
201
231
|
errorsUpdated = true;
|
|
232
|
+
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
202
233
|
pluginCache.set(ruleCtx.document.uri, {
|
|
203
234
|
documentVersion: ruleCtx.document.version,
|
|
204
235
|
errors,
|
|
205
236
|
tsProjectVersion,
|
|
206
237
|
});
|
|
207
238
|
return errors;
|
|
208
|
-
}), transformErrorRange, arr => arr.flat());
|
|
239
|
+
}), api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
|
|
209
240
|
if (result) {
|
|
210
241
|
cache.errors = result;
|
|
211
242
|
cache.snapshot = newSnapshot;
|
|
@@ -247,9 +278,15 @@ function register(context) {
|
|
|
247
278
|
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
248
279
|
error.data = {
|
|
249
280
|
uri,
|
|
281
|
+
version: newDocument.version,
|
|
250
282
|
type: 'plugin',
|
|
251
283
|
pluginOrRuleId: pluginId,
|
|
252
|
-
|
|
284
|
+
isFormat: false,
|
|
285
|
+
original: {
|
|
286
|
+
data: error.data,
|
|
287
|
+
},
|
|
288
|
+
ruleFixIndex: 0,
|
|
289
|
+
documentUri: document.uri,
|
|
253
290
|
};
|
|
254
291
|
});
|
|
255
292
|
errorsUpdated = true;
|
|
@@ -267,6 +304,22 @@ function register(context) {
|
|
|
267
304
|
});
|
|
268
305
|
}
|
|
269
306
|
});
|
|
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
|
+
}
|
|
270
323
|
function transformErrorRange(errors, map) {
|
|
271
324
|
const result = [];
|
|
272
325
|
for (const error of errors) {
|
|
@@ -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[]>;
|
|
@@ -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
|
}
|
package/out/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core';
|
|
2
|
-
import { LanguageService } from '@volar/language-service';
|
|
3
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
3
|
import type { DocumentContext, FileSystemProvider } from 'vscode-html-languageservice';
|
|
5
4
|
import type { SchemaRequestService } from 'vscode-json-languageservice';
|
|
@@ -8,7 +7,8 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
|
8
7
|
import { URI } from 'vscode-uri';
|
|
9
8
|
import { DocumentsAndSourceMaps } from './documents';
|
|
10
9
|
export * from 'vscode-languageserver-protocol';
|
|
11
|
-
export interface
|
|
10
|
+
export interface LanguageServicePluginContext {
|
|
11
|
+
config: Config;
|
|
12
12
|
typescript: {
|
|
13
13
|
module: typeof import('typescript/lib/tsserverlibrary');
|
|
14
14
|
languageServiceHost: ts.LanguageServiceHost;
|
|
@@ -16,13 +16,16 @@ 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;
|
|
22
23
|
schemaRequestService?: SchemaRequestService;
|
|
23
24
|
};
|
|
25
|
+
uriToFileName(uri: string): string;
|
|
26
|
+
fileNameToUri(fileName: string): string;
|
|
24
27
|
/** @private */
|
|
25
|
-
host:
|
|
28
|
+
host: LanguageServiceHost;
|
|
26
29
|
/** @private */
|
|
27
30
|
core: LanguageContext;
|
|
28
31
|
/** @private */
|
|
@@ -32,11 +35,15 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
|
|
|
32
35
|
[id: string]: LanguageServicePluginInstance;
|
|
33
36
|
};
|
|
34
37
|
/** @private */
|
|
35
|
-
rules: {
|
|
36
|
-
[id: string]: Rule | undefined;
|
|
37
|
-
};
|
|
38
|
-
/** @private */
|
|
39
38
|
getTextDocument(uri: string): TextDocument | undefined;
|
|
39
|
+
/** @private */
|
|
40
|
+
ruleFixes?: {
|
|
41
|
+
[uri: string]: {
|
|
42
|
+
[ruleId: string]: {
|
|
43
|
+
[ruleFixId: number]: [vscode.Diagnostic, RuleFix[]];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
40
47
|
}
|
|
41
48
|
export interface ConfigurationHost {
|
|
42
49
|
getConfiguration: (<T>(section: string, scopeUri?: string) => Promise<T | undefined>);
|
|
@@ -48,29 +55,17 @@ export interface ConfigurationHost {
|
|
|
48
55
|
export type NotNullableResult<T> = T | Thenable<T>;
|
|
49
56
|
export type NullableResult<T> = NotNullableResult<T | undefined | null>;
|
|
50
57
|
export type SemanticToken = [number, number, number, number, number];
|
|
51
|
-
export interface ExecuteCommandContext {
|
|
52
|
-
token: vscode.CancellationToken;
|
|
53
|
-
workDoneProgress: {
|
|
54
|
-
begin(title: string, percentage?: number, message?: string, cancellable?: boolean): void;
|
|
55
|
-
report(percentage: number): void;
|
|
56
|
-
report(message: string): void;
|
|
57
|
-
report(percentage: number, message: string): void;
|
|
58
|
-
done(): void;
|
|
59
|
-
};
|
|
60
|
-
showReferences(params: {
|
|
61
|
-
textDocument: vscode.TextDocumentIdentifier;
|
|
62
|
-
position: vscode.Position;
|
|
63
|
-
references: vscode.Location[];
|
|
64
|
-
}): Promise<void>;
|
|
65
|
-
applyEdit(paramOrEdit: vscode.ApplyWorkspaceEditParams | vscode.WorkspaceEdit): Promise<vscode.ApplyWorkspaceEditResult>;
|
|
66
|
-
}
|
|
67
58
|
export interface LanguageServicePlugin<T = {}> {
|
|
68
|
-
(context:
|
|
59
|
+
(context: LanguageServicePluginContext): LanguageServicePluginInstance & T;
|
|
69
60
|
}
|
|
70
61
|
export interface LanguageServicePluginInstance {
|
|
71
|
-
|
|
62
|
+
rules?: {
|
|
63
|
+
onAny?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
64
|
+
onFormat?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
65
|
+
onSyntax?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
66
|
+
onSemantic?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
67
|
+
};
|
|
72
68
|
validation?: {
|
|
73
|
-
resolveRuleContext?(context: RuleContext): void;
|
|
74
69
|
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
75
70
|
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
76
71
|
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
@@ -85,7 +80,6 @@ export interface LanguageServicePluginInstance {
|
|
|
85
80
|
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.SymbolInformation[]>;
|
|
86
81
|
findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>;
|
|
87
82
|
findWorkspaceSymbols?(query: string): NullableResult<vscode.SymbolInformation[]>;
|
|
88
|
-
doExecuteCommand?(command: string, args: any[] | undefined, context: ExecuteCommandContext): NotNullableResult<void>;
|
|
89
83
|
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
|
|
90
84
|
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
|
|
91
85
|
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
|
|
@@ -116,6 +110,10 @@ export interface LanguageServicePluginInstance {
|
|
|
116
110
|
on?(document: TextDocument): NullableResult<vscode.CodeLens[]>;
|
|
117
111
|
resolve?(codeLens: vscode.CodeLens): NotNullableResult<vscode.CodeLens>;
|
|
118
112
|
};
|
|
113
|
+
referencesCodeLens?: {
|
|
114
|
+
on?(document: TextDocument): NullableResult<vscode.Location[]>;
|
|
115
|
+
resolve?(document: TextDocument, location: vscode.Location, references: vscode.Location[]): NotNullableResult<vscode.Location[]>;
|
|
116
|
+
};
|
|
119
117
|
callHierarchy?: {
|
|
120
118
|
prepare(document: TextDocument, position: vscode.Position): NullableResult<vscode.CallHierarchyItem[]>;
|
|
121
119
|
onIncomingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyIncomingCall[]>;
|
|
@@ -144,19 +142,72 @@ export interface Rule {
|
|
|
144
142
|
onSemantic?(ctx: RuleContext): void;
|
|
145
143
|
}
|
|
146
144
|
export interface RuleContext {
|
|
145
|
+
/**
|
|
146
|
+
* Shared modules.
|
|
147
|
+
*/
|
|
148
|
+
modules: {
|
|
149
|
+
typescript?: typeof import('typescript/lib/tsserverlibrary');
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* IDE or user define locale.
|
|
153
|
+
* You can use it to localize your rule.
|
|
154
|
+
*/
|
|
155
|
+
locale?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Project root path.
|
|
158
|
+
*/
|
|
159
|
+
rootUri: URI;
|
|
160
|
+
uriToFileName(uri: string): string;
|
|
161
|
+
fileNameToUri(fileName: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Get configuration from IDE.
|
|
164
|
+
*
|
|
165
|
+
* For VSCode, it's .vscode/settings.json
|
|
166
|
+
*/
|
|
167
|
+
getConfiguration?: <T>(section: string) => Promise<T | undefined>;
|
|
168
|
+
onDidChangeConfiguration?: (cb: () => void) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Global settings from config.
|
|
171
|
+
*/
|
|
172
|
+
settings: any;
|
|
147
173
|
ruleId: string;
|
|
148
174
|
document: TextDocument;
|
|
149
|
-
report(error: vscode.Diagnostic, ...fixes:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
175
|
+
report(error: vscode.Diagnostic, ...fixes: RuleFix[]): void;
|
|
176
|
+
}
|
|
177
|
+
export interface RuleFix {
|
|
178
|
+
/**
|
|
179
|
+
* Code action kind, like `quickfix` or `refactor`.
|
|
180
|
+
*
|
|
181
|
+
* See https://code.visualstudio.com/api/references/vscode-api#CodeActionKind
|
|
182
|
+
*/
|
|
183
|
+
kinds?: vscode.CodeActionKind[];
|
|
184
|
+
/**
|
|
185
|
+
* Title of the code action.
|
|
186
|
+
*/
|
|
187
|
+
title?: string;
|
|
188
|
+
/**
|
|
189
|
+
* Edit to apply to the document.
|
|
190
|
+
*/
|
|
191
|
+
getEdits?(diagnostic: vscode.Diagnostic): NullableResult<vscode.TextEdit[]>;
|
|
192
|
+
/**
|
|
193
|
+
* Cross-file edits to apply to the workspace.
|
|
194
|
+
*/
|
|
195
|
+
getWorkspaceEdit?(diagnostic: vscode.Diagnostic): NullableResult<vscode.WorkspaceEdit>;
|
|
154
196
|
}
|
|
155
|
-
export interface
|
|
156
|
-
languages?:
|
|
157
|
-
|
|
158
|
-
|
|
197
|
+
export interface Config {
|
|
198
|
+
languages?: {
|
|
199
|
+
[id: string]: LanguageModule | undefined;
|
|
200
|
+
};
|
|
201
|
+
plugins?: {
|
|
202
|
+
[id: string]: LanguageServicePlugin | LanguageServicePluginInstance | undefined;
|
|
203
|
+
};
|
|
204
|
+
lint?: {
|
|
205
|
+
rules?: {
|
|
206
|
+
[id: string]: Rule | undefined;
|
|
207
|
+
};
|
|
208
|
+
severities?: {
|
|
209
|
+
[id: string]: vscode.DiagnosticSeverity;
|
|
210
|
+
};
|
|
211
|
+
settings?: any;
|
|
212
|
+
};
|
|
159
213
|
}
|
|
160
|
-
type ConfigValue<T> = {
|
|
161
|
-
[id: string]: T | undefined;
|
|
162
|
-
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
import type { LanguageServicePluginInstance,
|
|
2
|
+
import type { LanguageServicePluginInstance, LanguageServicePluginContext, Rule, RuleContext } from '../types';
|
|
3
3
|
import { FileRangeCapabilities, VirtualFile } from '@volar/language-service';
|
|
4
4
|
import { SourceMapWithDocuments } from '../documents';
|
|
5
|
-
export declare function documentFeatureWorker<T>(context:
|
|
6
|
-
export declare function languageFeatureWorker<T, K>(context:
|
|
7
|
-
export declare function ruleWorker<T>(context:
|
|
5
|
+
export declare function documentFeatureWorker<T>(context: LanguageServicePluginContext, uri: string, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (plugin: LanguageServicePluginInstance, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
6
|
+
export declare function languageFeatureWorker<T, K>(context: LanguageServicePluginContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (plugin: LanguageServicePluginInstance, document: TextDocument, arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined, file: VirtualFile | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
7
|
+
export declare function ruleWorker<T>(context: LanguageServicePluginContext, api: 'onSyntax' | 'onSemantic' | 'onFormat', uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleName: string, rule: Rule, ruleCtx: RuleContext) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|