@volar/language-service 1.0.24 → 1.1.0-1.2.0-alpha.1.0
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 -11
- package/out/baseLanguageService.js +33 -23
- package/out/documentFeatures/documentSymbols.js +2 -4
- package/out/documentFeatures/format.js +4 -4
- package/out/languageFeatures/callHierarchy.d.ts +2 -2
- package/out/languageFeatures/callHierarchy.js +14 -17
- package/out/languageFeatures/codeActionResolve.js +3 -5
- package/out/languageFeatures/codeActions.d.ts +2 -2
- package/out/languageFeatures/codeActions.js +12 -4
- package/out/languageFeatures/codeLens.d.ts +4 -4
- package/out/languageFeatures/codeLens.js +16 -10
- package/out/languageFeatures/codeLensResolve.js +10 -4
- package/out/languageFeatures/complete.d.ts +2 -2
- package/out/languageFeatures/complete.js +23 -20
- package/out/languageFeatures/completeResolve.js +3 -5
- package/out/languageFeatures/executeCommand.d.ts +1 -1
- package/out/languageFeatures/executeCommand.js +1 -1
- package/out/languageFeatures/fileRename.js +2 -2
- package/out/languageFeatures/renamePrepare.js +1 -6
- package/out/languageFeatures/validation copy.d.ts +7 -0
- package/out/languageFeatures/validation copy.js +234 -0
- package/out/languageFeatures/validation.d.ts +6 -0
- package/out/languageFeatures/validation.js +116 -39
- package/out/languageFeatures/workspaceSymbols.js +1 -1
- package/out/types.d.ts +37 -6
- package/out/types.js +0 -1
- package/out/utils/common.d.ts +0 -2
- package/out/utils/common.js +1 -28
- package/out/utils/featureWorkers.d.ts +2 -1
- package/out/utils/featureWorkers.js +87 -5
- package/package.json +7 -7
|
@@ -0,0 +1,234 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.register = exports.updateRange = void 0;
|
|
12
|
+
const shared = require("@volar/shared");
|
|
13
|
+
const dedupe = require("../utils/dedupe");
|
|
14
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
15
|
+
function updateRange(range, change) {
|
|
16
|
+
if (!updatePosition(range.start, change, false)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!updatePosition(range.end, change, true)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (range.end.line === range.start.line && range.end.character <= range.start.character) {
|
|
23
|
+
range.end.character++;
|
|
24
|
+
}
|
|
25
|
+
return range;
|
|
26
|
+
}
|
|
27
|
+
exports.updateRange = updateRange;
|
|
28
|
+
function updatePosition(position, change, isEnd) {
|
|
29
|
+
if (change.range.end.line > position.line) {
|
|
30
|
+
if (change.newEnd.line > position.line) {
|
|
31
|
+
// No change
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
else if (change.newEnd.line === position.line) {
|
|
35
|
+
position.character = Math.min(position.character, change.newEnd.character);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
else if (change.newEnd.line < position.line) {
|
|
39
|
+
position.line = change.newEnd.line;
|
|
40
|
+
position.character = change.newEnd.character;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (change.range.end.line === position.line) {
|
|
45
|
+
const characterDiff = change.newEnd.character - change.range.end.character;
|
|
46
|
+
if (position.character >= change.range.end.character) {
|
|
47
|
+
if (change.newEnd.line !== change.range.end.line) {
|
|
48
|
+
position.line = change.newEnd.line;
|
|
49
|
+
position.character = change.newEnd.character + position.character - change.range.end.character;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
|
|
53
|
+
position.character += characterDiff;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const offset = change.range.end.character - position.character;
|
|
57
|
+
if (-characterDiff > offset) {
|
|
58
|
+
position.character += characterDiff + offset;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (change.newEnd.line === change.range.end.line) {
|
|
66
|
+
const offset = change.range.end.character - position.character;
|
|
67
|
+
if (-characterDiff > offset) {
|
|
68
|
+
position.character += characterDiff + offset;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (change.newEnd.line < change.range.end.line) {
|
|
72
|
+
position.line = change.newEnd.line;
|
|
73
|
+
position.character = change.newEnd.character;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// No change
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (change.range.end.line < position.line) {
|
|
82
|
+
position.line += change.newEnd.line - change.range.end.line;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
function register(context) {
|
|
88
|
+
const responseCache = new Map();
|
|
89
|
+
const cacheMaps = {
|
|
90
|
+
semantic: new Map(),
|
|
91
|
+
declaration: new Map(),
|
|
92
|
+
syntactic: new Map(),
|
|
93
|
+
suggestion: new Map(),
|
|
94
|
+
};
|
|
95
|
+
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
var _a;
|
|
97
|
+
const lastResponse = (_a = responseCache.get(uri)) !== null && _a !== void 0 ? _a : responseCache.set(uri, {
|
|
98
|
+
semantic: { errors: [] },
|
|
99
|
+
declaration: { errors: [] },
|
|
100
|
+
suggestion: { errors: [] },
|
|
101
|
+
syntactic: { errors: [] },
|
|
102
|
+
}).get(uri);
|
|
103
|
+
const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
|
|
104
|
+
const newDocument = context.getTextDocument(uri);
|
|
105
|
+
let updateCacheRangeFailed = false;
|
|
106
|
+
let errorsUpdated = false;
|
|
107
|
+
let lastCheckCancelAt = 0;
|
|
108
|
+
for (const cache of Object.values(lastResponse)) {
|
|
109
|
+
const oldSnapshot = cache.snapshot;
|
|
110
|
+
const oldDocument = cache.document;
|
|
111
|
+
const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
|
|
112
|
+
cache.snapshot = newSnapshot;
|
|
113
|
+
cache.document = newDocument;
|
|
114
|
+
if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
|
|
115
|
+
const changeRange = {
|
|
116
|
+
range: {
|
|
117
|
+
start: oldDocument.positionAt(change.span.start),
|
|
118
|
+
end: oldDocument.positionAt(change.span.start + change.span.length),
|
|
119
|
+
},
|
|
120
|
+
newEnd: newDocument.positionAt(change.span.start + change.newLength),
|
|
121
|
+
};
|
|
122
|
+
for (const error of cache.errors) {
|
|
123
|
+
if (!updateRange(error.range, changeRange)) {
|
|
124
|
+
updateCacheRangeFailed = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
131
|
+
doResponse();
|
|
132
|
+
yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion);
|
|
133
|
+
doResponse();
|
|
134
|
+
yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic);
|
|
135
|
+
doResponse();
|
|
136
|
+
yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration);
|
|
137
|
+
return collectErrors();
|
|
138
|
+
function doResponse() {
|
|
139
|
+
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
140
|
+
response === null || response === void 0 ? void 0 : response(collectErrors());
|
|
141
|
+
errorsUpdated = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function collectErrors() {
|
|
145
|
+
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
146
|
+
}
|
|
147
|
+
function worker(api, cacheMap, cache) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
150
|
+
if (file.capabilities.diagnostic) {
|
|
151
|
+
yield arg;
|
|
152
|
+
}
|
|
153
|
+
}, (plugin, document) => __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
var _a, _b, _c, _d, _e;
|
|
155
|
+
if (token) {
|
|
156
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
157
|
+
yield shared.sleep(5); // wait for LSP event polling
|
|
158
|
+
lastCheckCancelAt = Date.now();
|
|
159
|
+
}
|
|
160
|
+
if (token.isCancellationRequested)
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const pluginId = context.plugins.indexOf(plugin);
|
|
164
|
+
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
165
|
+
const cache = pluginCache.get(document.uri);
|
|
166
|
+
const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
167
|
+
if (api === 'onDeclaration' || api === 'onSemantic') {
|
|
168
|
+
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
169
|
+
return cache.errors;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (cache && cache.documentVersion === document.version) {
|
|
174
|
+
return cache.errors;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
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));
|
|
178
|
+
errorsUpdated = true;
|
|
179
|
+
pluginCache.set(document.uri, {
|
|
180
|
+
documentVersion: document.version,
|
|
181
|
+
errors,
|
|
182
|
+
tsProjectVersion,
|
|
183
|
+
});
|
|
184
|
+
return errors;
|
|
185
|
+
}), (errors, map) => transformErrorRange(map, errors), arr => dedupe.withDiagnostics(arr.flat()));
|
|
186
|
+
if (result) {
|
|
187
|
+
cache.errors = result;
|
|
188
|
+
cache.snapshot = newSnapshot;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
function transformErrorRange(map, errors) {
|
|
194
|
+
const result = [];
|
|
195
|
+
for (const error of errors) {
|
|
196
|
+
// clone it to avoid modify cache
|
|
197
|
+
let _error = Object.assign({}, error);
|
|
198
|
+
if (map) {
|
|
199
|
+
const range = map.toSourceRange(error.range, data => !!data.diagnostic);
|
|
200
|
+
if (!range) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
_error.range = range;
|
|
204
|
+
}
|
|
205
|
+
if (_error.relatedInformation) {
|
|
206
|
+
const relatedInfos = [];
|
|
207
|
+
for (const info of _error.relatedInformation) {
|
|
208
|
+
if (context.documents.hasVirtualFileByUri(info.location.uri)) {
|
|
209
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(info.location.uri)) {
|
|
210
|
+
const range = map.toSourceRange(info.location.range, data => !!data.diagnostic);
|
|
211
|
+
if (range) {
|
|
212
|
+
relatedInfos.push({
|
|
213
|
+
location: {
|
|
214
|
+
uri: map.sourceFileDocument.uri,
|
|
215
|
+
range,
|
|
216
|
+
},
|
|
217
|
+
message: info.message,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
relatedInfos.push(info);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
_error.relatedInformation = relatedInfos;
|
|
227
|
+
}
|
|
228
|
+
result.push(_error);
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.register = register;
|
|
234
|
+
//# sourceMappingURL=validation%20copy.js.map
|
|
@@ -4,4 +4,10 @@ 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 interface PluginDiagnosticData {
|
|
8
|
+
uri: string;
|
|
9
|
+
originalData: any;
|
|
10
|
+
type: 'plugin' | 'rule';
|
|
11
|
+
pluginOrRuleId: string;
|
|
12
|
+
}
|
|
7
13
|
export declare function register(context: LanguageServiceRuntimeContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
@@ -10,7 +10,6 @@ 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_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
14
13
|
const dedupe = require("../utils/dedupe");
|
|
15
14
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
16
15
|
function updateRange(range, change) {
|
|
@@ -86,32 +85,39 @@ function updatePosition(position, change, isEnd) {
|
|
|
86
85
|
return false;
|
|
87
86
|
}
|
|
88
87
|
function register(context) {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const lastResponses = new Map();
|
|
89
|
+
const cacheMaps = {
|
|
90
|
+
semantic: new Map(),
|
|
91
|
+
declaration: new Map(),
|
|
92
|
+
syntactic: new Map(),
|
|
93
|
+
suggestion: new Map(),
|
|
94
|
+
semantic_rules: new Map(),
|
|
95
|
+
syntactic_rules: new Map(),
|
|
96
|
+
formatic_rules: new Map(),
|
|
97
|
+
};
|
|
95
98
|
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
|
|
96
99
|
var _a;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const lastResponse = (_a = lastResponses.get(uri)) !== null && _a !== void 0 ? _a : lastResponses.set(uri, {
|
|
101
|
+
semantic: { errors: [] },
|
|
102
|
+
declaration: { errors: [] },
|
|
103
|
+
suggestion: { errors: [] },
|
|
104
|
+
syntactic: { errors: [] },
|
|
105
|
+
semantic_rules: { errors: [] },
|
|
106
|
+
syntactic_rules: { errors: [] },
|
|
107
|
+
formatic_rules: { errors: [] },
|
|
103
108
|
}).get(uri);
|
|
104
109
|
const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
|
|
105
|
-
const newDocument =
|
|
106
|
-
let
|
|
110
|
+
const newDocument = context.getTextDocument(uri);
|
|
111
|
+
let updateCacheRangeFailed = false;
|
|
107
112
|
let errorsUpdated = false;
|
|
108
113
|
let lastCheckCancelAt = 0;
|
|
109
|
-
for (const
|
|
110
|
-
const oldSnapshot =
|
|
114
|
+
for (const cache of Object.values(lastResponse)) {
|
|
115
|
+
const oldSnapshot = cache.snapshot;
|
|
116
|
+
const oldDocument = cache.document;
|
|
111
117
|
const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
cache.snapshot = newSnapshot;
|
|
119
|
+
cache.document = newDocument;
|
|
120
|
+
if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
|
|
115
121
|
const changeRange = {
|
|
116
122
|
range: {
|
|
117
123
|
start: oldDocument.positionAt(change.span.start),
|
|
@@ -119,32 +125,94 @@ function register(context) {
|
|
|
119
125
|
},
|
|
120
126
|
newEnd: newDocument.positionAt(change.span.start + change.newLength),
|
|
121
127
|
};
|
|
122
|
-
for (const error of
|
|
128
|
+
for (const error of cache.errors) {
|
|
123
129
|
if (!updateRange(error.range, changeRange)) {
|
|
124
|
-
|
|
130
|
+
updateCacheRangeFailed = true;
|
|
125
131
|
break;
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
|
-
yield
|
|
136
|
+
yield lintWorker('onFormat', cacheMaps.formatic_rules, lastResponse.formatic_rules);
|
|
131
137
|
doResponse();
|
|
132
|
-
yield
|
|
138
|
+
yield lintWorker('onSyntax', cacheMaps.syntactic_rules, lastResponse.syntactic_rules);
|
|
133
139
|
doResponse();
|
|
134
|
-
yield worker('
|
|
140
|
+
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
135
141
|
doResponse();
|
|
136
|
-
yield worker('
|
|
137
|
-
|
|
142
|
+
yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion);
|
|
143
|
+
doResponse();
|
|
144
|
+
yield lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules);
|
|
145
|
+
doResponse();
|
|
146
|
+
yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic);
|
|
147
|
+
doResponse();
|
|
148
|
+
yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration);
|
|
149
|
+
return collectErrors();
|
|
138
150
|
function doResponse() {
|
|
139
|
-
if (errorsUpdated && !
|
|
140
|
-
response === null || response === void 0 ? void 0 : response(
|
|
151
|
+
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
152
|
+
response === null || response === void 0 ? void 0 : response(collectErrors());
|
|
141
153
|
errorsUpdated = false;
|
|
142
154
|
}
|
|
143
155
|
}
|
|
144
|
-
function
|
|
145
|
-
return Object.values(
|
|
156
|
+
function collectErrors() {
|
|
157
|
+
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
146
158
|
}
|
|
147
|
-
function
|
|
159
|
+
function lintWorker(api, cacheMap, cache) {
|
|
160
|
+
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;
|
|
163
|
+
if (token) {
|
|
164
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
165
|
+
yield shared.sleep(5); // wait for LSP event polling
|
|
166
|
+
lastCheckCancelAt = Date.now();
|
|
167
|
+
}
|
|
168
|
+
if (token.isCancellationRequested) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const pluginCache = (_a = cacheMap.get(ruleName)) !== null && _a !== void 0 ? _a : cacheMap.set(ruleName, new Map()).get(ruleName);
|
|
173
|
+
const cache = pluginCache.get(ruleCtx.document.uri);
|
|
174
|
+
const tsProjectVersion = (api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
175
|
+
if (api === 'onSemantic') {
|
|
176
|
+
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
177
|
+
return cache.errors;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
if (cache && cache.documentVersion === ruleCtx.document.version) {
|
|
182
|
+
return cache.errors;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const reportResults = [];
|
|
186
|
+
ruleCtx.report = (error, ...fixes) => {
|
|
187
|
+
error.source || (error.source = 'rules');
|
|
188
|
+
error.code || (error.code = ruleCtx.ruleId);
|
|
189
|
+
reportResults.push([error, ...fixes]);
|
|
190
|
+
};
|
|
191
|
+
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
|
|
192
|
+
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
193
|
+
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
194
|
+
error.data = {
|
|
195
|
+
uri,
|
|
196
|
+
type: 'rule',
|
|
197
|
+
pluginOrRuleId: ruleCtx.ruleId,
|
|
198
|
+
originalData: error.data,
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
errorsUpdated = true;
|
|
202
|
+
pluginCache.set(ruleCtx.document.uri, {
|
|
203
|
+
documentVersion: ruleCtx.document.version,
|
|
204
|
+
errors,
|
|
205
|
+
tsProjectVersion,
|
|
206
|
+
});
|
|
207
|
+
return errors;
|
|
208
|
+
}), transformErrorRange, arr => arr.flat());
|
|
209
|
+
if (result) {
|
|
210
|
+
cache.errors = result;
|
|
211
|
+
cache.snapshot = newSnapshot;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function worker(api, cacheMap, cache) {
|
|
148
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
217
|
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
150
218
|
if (file.capabilities.diagnostic) {
|
|
@@ -157,14 +225,15 @@ function register(context) {
|
|
|
157
225
|
yield shared.sleep(5); // wait for LSP event polling
|
|
158
226
|
lastCheckCancelAt = Date.now();
|
|
159
227
|
}
|
|
160
|
-
if (token.isCancellationRequested)
|
|
228
|
+
if (token.isCancellationRequested) {
|
|
161
229
|
return;
|
|
230
|
+
}
|
|
162
231
|
}
|
|
163
|
-
const pluginId = context.plugins.
|
|
232
|
+
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
164
233
|
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
165
234
|
const cache = pluginCache.get(document.uri);
|
|
166
|
-
const tsProjectVersion = (
|
|
167
|
-
if (
|
|
235
|
+
const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
236
|
+
if (api === 'onDeclaration' || api === 'onSemantic') {
|
|
168
237
|
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
169
238
|
return cache.errors;
|
|
170
239
|
}
|
|
@@ -174,7 +243,15 @@ function register(context) {
|
|
|
174
243
|
return cache.errors;
|
|
175
244
|
}
|
|
176
245
|
}
|
|
177
|
-
const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[
|
|
246
|
+
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));
|
|
247
|
+
errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
|
|
248
|
+
error.data = {
|
|
249
|
+
uri,
|
|
250
|
+
type: 'plugin',
|
|
251
|
+
pluginOrRuleId: pluginId,
|
|
252
|
+
originalData: error.data,
|
|
253
|
+
};
|
|
254
|
+
});
|
|
178
255
|
errorsUpdated = true;
|
|
179
256
|
pluginCache.set(document.uri, {
|
|
180
257
|
documentVersion: document.version,
|
|
@@ -182,7 +259,7 @@ function register(context) {
|
|
|
182
259
|
tsProjectVersion,
|
|
183
260
|
});
|
|
184
261
|
return errors;
|
|
185
|
-
}),
|
|
262
|
+
}), transformErrorRange, arr => dedupe.withDiagnostics(arr.flat()));
|
|
186
263
|
if (result) {
|
|
187
264
|
cache.errors = result;
|
|
188
265
|
cache.snapshot = newSnapshot;
|
|
@@ -190,7 +267,7 @@ function register(context) {
|
|
|
190
267
|
});
|
|
191
268
|
}
|
|
192
269
|
});
|
|
193
|
-
function transformErrorRange(
|
|
270
|
+
function transformErrorRange(errors, map) {
|
|
194
271
|
const result = [];
|
|
195
272
|
for (const error of errors) {
|
|
196
273
|
// clone it to avoid modify cache
|
|
@@ -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);
|
package/out/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { LanguageContext, LanguageServiceHost } from '@volar/language-core';
|
|
1
|
+
import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core';
|
|
2
|
+
import { LanguageService } from '@volar/language-service';
|
|
2
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
4
|
import type { DocumentContext, FileSystemProvider } from 'vscode-html-languageservice';
|
|
4
5
|
import type { SchemaRequestService } from 'vscode-json-languageservice';
|
|
@@ -6,7 +7,6 @@ import type * as vscode from 'vscode-languageserver-protocol';
|
|
|
6
7
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
7
8
|
import { URI } from 'vscode-uri';
|
|
8
9
|
import { DocumentsAndSourceMaps } from './documents';
|
|
9
|
-
import { LanguageService } from '@volar/language-service';
|
|
10
10
|
export * from 'vscode-languageserver-protocol';
|
|
11
11
|
export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost = LanguageServiceHost> {
|
|
12
12
|
typescript: {
|
|
@@ -17,7 +17,7 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
|
|
|
17
17
|
env: {
|
|
18
18
|
rootUri: URI;
|
|
19
19
|
configurationHost?: ConfigurationHost;
|
|
20
|
-
documentContext
|
|
20
|
+
documentContext: DocumentContext;
|
|
21
21
|
fileSystemProvider?: FileSystemProvider;
|
|
22
22
|
schemaRequestService?: SchemaRequestService;
|
|
23
23
|
};
|
|
@@ -28,7 +28,13 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
|
|
|
28
28
|
/** @private */
|
|
29
29
|
documents: DocumentsAndSourceMaps;
|
|
30
30
|
/** @private */
|
|
31
|
-
plugins:
|
|
31
|
+
plugins: {
|
|
32
|
+
[id: string]: LanguageServicePluginInstance;
|
|
33
|
+
};
|
|
34
|
+
/** @private */
|
|
35
|
+
rules: {
|
|
36
|
+
[id: string]: Rule | undefined;
|
|
37
|
+
};
|
|
32
38
|
/** @private */
|
|
33
39
|
getTextDocument(uri: string): TextDocument | undefined;
|
|
34
40
|
}
|
|
@@ -58,10 +64,13 @@ export interface ExecuteCommandContext {
|
|
|
58
64
|
}): Promise<void>;
|
|
59
65
|
applyEdit(paramOrEdit: vscode.ApplyWorkspaceEditParams | vscode.WorkspaceEdit): Promise<vscode.ApplyWorkspaceEditResult>;
|
|
60
66
|
}
|
|
61
|
-
export
|
|
67
|
+
export interface LanguageServicePlugin<T = {}> {
|
|
68
|
+
(context: LanguageServiceRuntimeContext, service: LanguageService): LanguageServicePluginInstance & T;
|
|
69
|
+
}
|
|
62
70
|
export interface LanguageServicePluginInstance {
|
|
63
71
|
setup?(context: LanguageServiceRuntimeContext): void;
|
|
64
72
|
validation?: {
|
|
73
|
+
resolveRuleContext?(context: RuleContext): void;
|
|
65
74
|
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
66
75
|
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
67
76
|
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
@@ -76,7 +85,7 @@ export interface LanguageServicePluginInstance {
|
|
|
76
85
|
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.SymbolInformation[]>;
|
|
77
86
|
findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>;
|
|
78
87
|
findWorkspaceSymbols?(query: string): NullableResult<vscode.SymbolInformation[]>;
|
|
79
|
-
doExecuteCommand?(command: string, args: any[], context: ExecuteCommandContext): NotNullableResult<void>;
|
|
88
|
+
doExecuteCommand?(command: string, args: any[] | undefined, context: ExecuteCommandContext): NotNullableResult<void>;
|
|
80
89
|
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
|
|
81
90
|
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
|
|
82
91
|
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
|
|
@@ -129,3 +138,25 @@ export interface LanguageServicePluginInstance {
|
|
|
129
138
|
*/
|
|
130
139
|
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
|
|
131
140
|
}
|
|
141
|
+
export interface Rule {
|
|
142
|
+
onFormat?(ctx: RuleContext): void;
|
|
143
|
+
onSyntax?(ctx: RuleContext): void;
|
|
144
|
+
onSemantic?(ctx: RuleContext): void;
|
|
145
|
+
}
|
|
146
|
+
export interface RuleContext {
|
|
147
|
+
ruleId: string;
|
|
148
|
+
document: TextDocument;
|
|
149
|
+
report(error: vscode.Diagnostic, ...fixes: {
|
|
150
|
+
kinds?: string[];
|
|
151
|
+
getCodeActions(): NullableResult<vscode.CodeAction[]>;
|
|
152
|
+
resolveCodeAction?(codeAction: vscode.CodeAction): NotNullableResult<vscode.CodeAction>;
|
|
153
|
+
}[]): void;
|
|
154
|
+
}
|
|
155
|
+
export interface LanguageServiceConfig {
|
|
156
|
+
languages?: ConfigValue<LanguageModule>;
|
|
157
|
+
plugins?: ConfigValue<LanguageServicePlugin>;
|
|
158
|
+
rules?: ConfigValue<Rule>;
|
|
159
|
+
}
|
|
160
|
+
type ConfigValue<T> = {
|
|
161
|
+
[id: string]: T | undefined;
|
|
162
|
+
};
|
package/out/types.js
CHANGED
package/out/utils/common.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
2
|
export declare function getOverlapRange(range1Start: number, range1End: number, range2Start: number, range2End: number): {
|
|
4
3
|
start: number;
|
|
5
4
|
end: number;
|
|
6
5
|
} | undefined;
|
|
7
6
|
export declare function isInsideRange(parent: vscode.Range, child: vscode.Range): boolean;
|
|
8
|
-
export declare function getWordRange(wordPattern: RegExp, position: vscode.Position, document: TextDocument): vscode.Range | undefined;
|
|
9
7
|
export declare function stringToSnapshot(str: string): ts.IScriptSnapshot;
|
package/out/utils/common.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.stringToSnapshot = exports.
|
|
2
|
+
exports.stringToSnapshot = exports.isInsideRange = exports.getOverlapRange = void 0;
|
|
3
3
|
function getOverlapRange(range1Start, range1End, range2Start, range2End) {
|
|
4
4
|
const start = Math.max(range1Start, range2Start);
|
|
5
5
|
const end = Math.min(range1End, range2End);
|
|
@@ -23,33 +23,6 @@ function isInsideRange(parent, child) {
|
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
25
|
exports.isInsideRange = isInsideRange;
|
|
26
|
-
function getWordRange(wordPattern, position, document) {
|
|
27
|
-
const lineStart = {
|
|
28
|
-
line: position.line,
|
|
29
|
-
character: 0,
|
|
30
|
-
};
|
|
31
|
-
const lineEnd = {
|
|
32
|
-
line: position.line + 1,
|
|
33
|
-
character: 0,
|
|
34
|
-
};
|
|
35
|
-
const offset = document.offsetAt(position);
|
|
36
|
-
const lineStartOffset = document.offsetAt(lineStart);
|
|
37
|
-
const lineText = document.getText({ start: lineStart, end: lineEnd });
|
|
38
|
-
for (const match of lineText.matchAll(wordPattern)) {
|
|
39
|
-
if (match.index === undefined)
|
|
40
|
-
continue;
|
|
41
|
-
const matchStart = match.index + lineStartOffset;
|
|
42
|
-
const matchEnd = matchStart + match[0].length;
|
|
43
|
-
if (offset >= matchStart && offset <= matchEnd) {
|
|
44
|
-
return {
|
|
45
|
-
start: document.positionAt(matchStart),
|
|
46
|
-
end: document.positionAt(matchEnd),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
exports.getWordRange = getWordRange;
|
|
53
26
|
function stringToSnapshot(str) {
|
|
54
27
|
return {
|
|
55
28
|
getText: (start, end) => str.substring(start, end),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
import type { LanguageServicePluginInstance, LanguageServiceRuntimeContext } from '../types';
|
|
2
|
+
import type { LanguageServicePluginInstance, LanguageServiceRuntimeContext, Rule, RuleContext } 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: LanguageServiceRuntimeContext, 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
6
|
export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, 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: LanguageServiceRuntimeContext, 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>;
|