@volar/language-service 2.4.0-alpha.18 → 2.4.0-alpha.19
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.
|
@@ -3,10 +3,6 @@ import type * as vscode from 'vscode-languageserver-protocol';
|
|
|
3
3
|
import { URI } from 'vscode-uri';
|
|
4
4
|
import type { LanguageServiceContext } from '../types';
|
|
5
5
|
import { DocumentsAndMap } from '../utils/featureWorkers';
|
|
6
|
-
export declare function updateRange(range: vscode.Range, change: {
|
|
7
|
-
range: vscode.Range;
|
|
8
|
-
newEnd: vscode.Position;
|
|
9
|
-
}): vscode.Range | undefined;
|
|
10
6
|
export interface ServiceDiagnosticData {
|
|
11
7
|
uri: string;
|
|
12
8
|
version: number;
|
|
@@ -21,3 +17,7 @@ export declare const errorMarkups: Map<URI, {
|
|
|
21
17
|
}[]>;
|
|
22
18
|
export declare function register(context: LanguageServiceContext): (uri: URI, response?: (result: vscode.Diagnostic[]) => void, token?: vscode.CancellationToken) => Promise<vscode.Diagnostic[]>;
|
|
23
19
|
export declare function transformDiagnostic(context: LanguageServiceContext, error: vscode.Diagnostic, docs: DocumentsAndMap | undefined, filter: (data: CodeInformation) => boolean): vscode.Diagnostic | undefined;
|
|
20
|
+
export declare function updateRange(range: vscode.Range, change: {
|
|
21
|
+
range: vscode.Range;
|
|
22
|
+
newEnd: vscode.Position;
|
|
23
|
+
}): vscode.Range | undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.errorMarkups = void 0;
|
|
4
|
-
exports.updateRange = updateRange;
|
|
5
4
|
exports.register = register;
|
|
6
5
|
exports.transformDiagnostic = transformDiagnostic;
|
|
6
|
+
exports.updateRange = updateRange;
|
|
7
7
|
const language_core_1 = require("@volar/language-core");
|
|
8
8
|
const vscode_uri_1 = require("vscode-uri");
|
|
9
9
|
const cancellation_1 = require("../utils/cancellation");
|
|
@@ -11,77 +11,6 @@ const common_1 = require("../utils/common");
|
|
|
11
11
|
const dedupe = require("../utils/dedupe");
|
|
12
12
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
13
13
|
const uriMap_1 = require("../utils/uriMap");
|
|
14
|
-
function updateRange(range, change) {
|
|
15
|
-
if (!updatePosition(range.start, change, false)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (!updatePosition(range.end, change, true)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (range.end.line === range.start.line && range.end.character <= range.start.character) {
|
|
22
|
-
range.end.character++;
|
|
23
|
-
}
|
|
24
|
-
return range;
|
|
25
|
-
}
|
|
26
|
-
function updatePosition(position, change, isEnd) {
|
|
27
|
-
if (change.range.end.line > position.line) {
|
|
28
|
-
if (change.newEnd.line > position.line) {
|
|
29
|
-
// No change
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
else if (change.newEnd.line === position.line) {
|
|
33
|
-
position.character = Math.min(position.character, change.newEnd.character);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
else if (change.newEnd.line < position.line) {
|
|
37
|
-
position.line = change.newEnd.line;
|
|
38
|
-
position.character = change.newEnd.character;
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else if (change.range.end.line === position.line) {
|
|
43
|
-
const characterDiff = change.newEnd.character - change.range.end.character;
|
|
44
|
-
if (position.character >= change.range.end.character) {
|
|
45
|
-
if (change.newEnd.line !== change.range.end.line) {
|
|
46
|
-
position.line = change.newEnd.line;
|
|
47
|
-
position.character = change.newEnd.character + position.character - change.range.end.character;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
|
|
51
|
-
position.character += characterDiff;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const offset = change.range.end.character - position.character;
|
|
55
|
-
if (-characterDiff > offset) {
|
|
56
|
-
position.character += characterDiff + offset;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
if (change.newEnd.line === change.range.end.line) {
|
|
64
|
-
const offset = change.range.end.character - position.character;
|
|
65
|
-
if (-characterDiff > offset) {
|
|
66
|
-
position.character += characterDiff + offset;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (change.newEnd.line < change.range.end.line) {
|
|
70
|
-
position.line = change.newEnd.line;
|
|
71
|
-
position.character = change.newEnd.character;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// No change
|
|
75
|
-
}
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (change.range.end.line < position.line) {
|
|
80
|
-
position.line += change.newEnd.line - change.range.end.line;
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
14
|
exports.errorMarkups = (0, uriMap_1.createUriMap)();
|
|
86
15
|
function register(context) {
|
|
87
16
|
const lastResponses = (0, uriMap_1.createUriMap)();
|
|
@@ -136,11 +65,11 @@ function register(context) {
|
|
|
136
65
|
}
|
|
137
66
|
}
|
|
138
67
|
}
|
|
139
|
-
await worker('
|
|
140
|
-
|
|
141
|
-
await worker('
|
|
68
|
+
await worker('syntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
69
|
+
processResponse();
|
|
70
|
+
await worker('semantic', cacheMaps.semantic, lastResponse.semantic);
|
|
142
71
|
return collectErrors();
|
|
143
|
-
function
|
|
72
|
+
function processResponse() {
|
|
144
73
|
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
145
74
|
response?.(collectErrors());
|
|
146
75
|
errorsUpdated = false;
|
|
@@ -149,8 +78,12 @@ function register(context) {
|
|
|
149
78
|
function collectErrors() {
|
|
150
79
|
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
151
80
|
}
|
|
152
|
-
async function worker(
|
|
81
|
+
async function worker(kind, cacheMap, cache) {
|
|
153
82
|
const result = await (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)), async (plugin, document) => {
|
|
83
|
+
const interFileDependencies = plugin[0].capabilities.diagnosticProvider?.interFileDependencies;
|
|
84
|
+
if (kind === 'semantic' !== interFileDependencies) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
154
87
|
if (Date.now() - lastCheckCancelAt >= 10) {
|
|
155
88
|
await (0, common_1.sleep)(10); // waiting LSP event polling
|
|
156
89
|
lastCheckCancelAt = Date.now();
|
|
@@ -161,10 +94,10 @@ function register(context) {
|
|
|
161
94
|
const pluginIndex = context.plugins.indexOf(plugin);
|
|
162
95
|
const pluginCache = cacheMap.get(pluginIndex) ?? cacheMap.set(pluginIndex, new Map()).get(pluginIndex);
|
|
163
96
|
const cache = pluginCache.get(document.uri);
|
|
164
|
-
if (
|
|
97
|
+
if (!interFileDependencies && cache && cache.documentVersion === document.version) {
|
|
165
98
|
return cache.errors;
|
|
166
99
|
}
|
|
167
|
-
const errors = await plugin[1]
|
|
100
|
+
const errors = await plugin[1].provideDiagnostics?.(document, token) || [];
|
|
168
101
|
errors.forEach(error => {
|
|
169
102
|
error.data = {
|
|
170
103
|
uri: uri.toString(),
|
|
@@ -236,4 +169,75 @@ function transformDiagnostic(context, error, docs, filter) {
|
|
|
236
169
|
}
|
|
237
170
|
return _error;
|
|
238
171
|
}
|
|
172
|
+
function updateRange(range, change) {
|
|
173
|
+
if (!updatePosition(range.start, change, false)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (!updatePosition(range.end, change, true)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (range.end.line === range.start.line && range.end.character <= range.start.character) {
|
|
180
|
+
range.end.character++;
|
|
181
|
+
}
|
|
182
|
+
return range;
|
|
183
|
+
}
|
|
184
|
+
function updatePosition(position, change, isEnd) {
|
|
185
|
+
if (change.range.end.line > position.line) {
|
|
186
|
+
if (change.newEnd.line > position.line) {
|
|
187
|
+
// No change
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
else if (change.newEnd.line === position.line) {
|
|
191
|
+
position.character = Math.min(position.character, change.newEnd.character);
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
else if (change.newEnd.line < position.line) {
|
|
195
|
+
position.line = change.newEnd.line;
|
|
196
|
+
position.character = change.newEnd.character;
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (change.range.end.line === position.line) {
|
|
201
|
+
const characterDiff = change.newEnd.character - change.range.end.character;
|
|
202
|
+
if (position.character >= change.range.end.character) {
|
|
203
|
+
if (change.newEnd.line !== change.range.end.line) {
|
|
204
|
+
position.line = change.newEnd.line;
|
|
205
|
+
position.character = change.newEnd.character + position.character - change.range.end.character;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
|
|
209
|
+
position.character += characterDiff;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const offset = change.range.end.character - position.character;
|
|
213
|
+
if (-characterDiff > offset) {
|
|
214
|
+
position.character += characterDiff + offset;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
if (change.newEnd.line === change.range.end.line) {
|
|
222
|
+
const offset = change.range.end.character - position.character;
|
|
223
|
+
if (-characterDiff > offset) {
|
|
224
|
+
position.character += characterDiff + offset;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if (change.newEnd.line < change.range.end.line) {
|
|
228
|
+
position.line = change.newEnd.line;
|
|
229
|
+
position.character = change.newEnd.character;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// No change
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else if (change.range.end.line < position.line) {
|
|
238
|
+
position.line += change.newEnd.line - change.range.end.line;
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
239
243
|
//# sourceMappingURL=provideDiagnostics.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -128,10 +128,12 @@ export interface LanguageServicePlugin<P = any> {
|
|
|
128
128
|
resolveProvider?: boolean;
|
|
129
129
|
};
|
|
130
130
|
diagnosticProvider?: {
|
|
131
|
-
|
|
131
|
+
interFileDependencies: boolean;
|
|
132
|
+
workspaceDiagnostics: boolean;
|
|
132
133
|
};
|
|
133
134
|
fileReferencesProvider?: boolean;
|
|
134
|
-
|
|
135
|
+
fileRenameEditsProvider?: boolean;
|
|
136
|
+
documentDropEditsProvider?: boolean;
|
|
135
137
|
};
|
|
136
138
|
create(context: LanguageServiceContext): LanguageServicePluginInstance<P>;
|
|
137
139
|
}
|
|
@@ -176,7 +178,6 @@ export interface LanguageServicePluginInstance<P = any> {
|
|
|
176
178
|
provideDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken): NullableProviderResult<SemanticToken[]>;
|
|
177
179
|
provideWorkspaceSymbols?(query: string, token: vscode.CancellationToken): NullableProviderResult<vscode.WorkspaceSymbol[]>;
|
|
178
180
|
provideDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Diagnostic[]>;
|
|
179
|
-
provideSemanticDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Diagnostic[]>;
|
|
180
181
|
provideWorkspaceDiagnostics?(token: vscode.CancellationToken): NullableProviderResult<vscode.WorkspaceDocumentDiagnosticReport[]>;
|
|
181
182
|
provideFileReferences?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Location[]>;
|
|
182
183
|
provideReferencesCodeLensRanges?(document: TextDocument, token: vscode.CancellationToken): NullableProviderResult<vscode.Range[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "2.4.0-alpha.
|
|
3
|
+
"version": "2.4.0-alpha.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"directory": "packages/language-service"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.4.0-alpha.
|
|
15
|
+
"@volar/language-core": "2.4.0-alpha.19",
|
|
16
16
|
"vscode-languageserver-protocol": "^3.17.5",
|
|
17
17
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
18
18
|
"vscode-uri": "^3.0.8"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "cbb14a44f72c365c1e8d52eff9580fb4e9765f15"
|
|
21
21
|
}
|