@volar/language-server 2.4.0-alpha.9 → 2.4.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/browser.d.ts +43 -21
- package/browser.js +16 -31
- package/lib/features/configurations.d.ts +8 -0
- package/lib/features/configurations.js +49 -0
- package/lib/features/editorFeatures.d.ts +2 -0
- package/lib/features/editorFeatures.js +186 -0
- package/lib/features/fileSystem.d.ts +8 -0
- package/lib/features/fileSystem.js +61 -0
- package/lib/features/fileWatcher.d.ts +9 -0
- package/lib/features/fileWatcher.js +63 -0
- package/lib/features/languageFeatures.d.ts +4 -0
- package/lib/features/languageFeatures.js +730 -0
- package/lib/features/textDocuments.d.ts +12 -0
- package/lib/features/textDocuments.js +54 -0
- package/lib/features/workspaceFolders.d.ts +10 -0
- package/lib/features/workspaceFolders.js +67 -0
- package/lib/fileSystemProviders/http.d.ts +6 -0
- package/lib/fileSystemProviders/http.js +46 -0
- package/lib/fileSystemProviders/node.d.ts +2 -0
- package/lib/fileSystemProviders/node.js +49 -0
- package/lib/project/inferredCompilerOptions.js +2 -2
- package/lib/project/simpleProject.js +7 -8
- package/lib/project/typescriptProject.d.ts +7 -4
- package/lib/project/typescriptProject.js +49 -40
- package/lib/project/typescriptProjectLs.d.ts +8 -7
- package/lib/project/typescriptProjectLs.js +140 -85
- package/lib/server.d.ts +46 -27
- package/lib/server.js +59 -479
- package/lib/types.d.ts +20 -5
- package/lib/utils/combineChangeRanges.d.ts +2 -0
- package/lib/utils/combineChangeRanges.js +28 -0
- package/lib/utils/snapshotDocument.d.ts +28 -0
- package/lib/utils/snapshotDocument.js +138 -0
- package/node.d.ts +43 -23
- package/node.js +16 -58
- package/package.json +5 -6
- package/protocol.d.ts +1 -13
- package/protocol.js +1 -16
- package/lib/register/registerEditorFeatures.d.ts +0 -2
- package/lib/register/registerEditorFeatures.js +0 -208
- package/lib/register/registerLanguageFeatures.d.ts +0 -3
- package/lib/register/registerLanguageFeatures.js +0 -435
- package/lib/schemaRequestHandlers/http.d.ts +0 -2
- package/lib/schemaRequestHandlers/http.js +0 -16
package/lib/server.js
CHANGED
|
@@ -1,490 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
3
|
exports.createServerBase = createServerBase;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let watchFilesDisposable;
|
|
31
|
-
const syncedDocumentParsedUriToUri = new Map();
|
|
32
|
-
const didChangeWatchedFilesCallbacks = new Set();
|
|
33
|
-
const didChangeConfigurationCallbacks = new Set();
|
|
34
|
-
const configurations = new Map();
|
|
35
|
-
const documentsCache = new Map();
|
|
36
|
-
const documents = new vscode.TextDocuments({
|
|
37
|
-
create(uri, languageId, version, text) {
|
|
38
|
-
const cache = documentsCache.get(uri)?.deref();
|
|
39
|
-
if (cache && cache.languageId === languageId && cache.version === version && cache.getText() === text) {
|
|
40
|
-
return cache;
|
|
41
|
-
}
|
|
42
|
-
const document = new snapshot_document_1.SnapshotDocument(uri, languageId, version, text);
|
|
43
|
-
documentsCache.set(uri, new WeakRef(document));
|
|
44
|
-
return document;
|
|
45
|
-
},
|
|
46
|
-
update(snapshot, contentChanges, version) {
|
|
47
|
-
snapshot.update(contentChanges, version);
|
|
48
|
-
return snapshot;
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
documents.listen(connection);
|
|
52
|
-
documents.onDidOpen(({ document }) => {
|
|
53
|
-
const parsedUri = vscode_uri_1.URI.parse(document.uri);
|
|
54
|
-
syncedDocumentParsedUriToUri.set(parsedUri.toString(), document.uri);
|
|
55
|
-
});
|
|
56
|
-
documents.onDidClose(e => {
|
|
57
|
-
syncedDocumentParsedUriToUri.delete(vscode_uri_1.URI.parse(e.document.uri).toString());
|
|
58
|
-
});
|
|
59
|
-
const status = {
|
|
4
|
+
const configurations_js_1 = require("./features/configurations.js");
|
|
5
|
+
const editorFeatures_js_1 = require("./features/editorFeatures.js");
|
|
6
|
+
const fileSystem_js_1 = require("./features/fileSystem.js");
|
|
7
|
+
const fileWatcher_js_1 = require("./features/fileWatcher.js");
|
|
8
|
+
const languageFeatures_js_1 = require("./features/languageFeatures.js");
|
|
9
|
+
const textDocuments_js_1 = require("./features/textDocuments.js");
|
|
10
|
+
const workspaceFolders_js_1 = require("./features/workspaceFolders.js");
|
|
11
|
+
function createServerBase(connection, env) {
|
|
12
|
+
const onInitializeCallbacks = [];
|
|
13
|
+
const onInitializedCallbacks = [];
|
|
14
|
+
const state = {
|
|
15
|
+
env,
|
|
60
16
|
connection,
|
|
61
|
-
fs: createFsWithCache(fs),
|
|
62
17
|
initializeParams: undefined,
|
|
63
|
-
initializeResult: undefined,
|
|
64
|
-
languageServicePlugins: [],
|
|
65
18
|
project: undefined,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
watchFiles,
|
|
74
|
-
getConfiguration,
|
|
75
|
-
onDidChangeConfiguration,
|
|
76
|
-
onDidChangeWatchedFiles,
|
|
77
|
-
clearPushDiagnostics,
|
|
78
|
-
refresh,
|
|
19
|
+
languageServicePlugins: undefined,
|
|
20
|
+
onInitialize(callback) {
|
|
21
|
+
onInitializeCallbacks.push(callback);
|
|
22
|
+
},
|
|
23
|
+
onInitialized(callback) {
|
|
24
|
+
onInitializedCallbacks.push(callback);
|
|
25
|
+
},
|
|
79
26
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
status.pullModelDiagnostics = options?.pullModelDiagnostics ?? false;
|
|
92
|
-
if (initializeParams.workspaceFolders?.length) {
|
|
93
|
-
for (const folder of initializeParams.workspaceFolders) {
|
|
94
|
-
status.workspaceFolders.set(vscode_uri_1.URI.parse(folder.uri), true);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (initializeParams.rootUri) {
|
|
98
|
-
status.workspaceFolders.set(vscode_uri_1.URI.parse(initializeParams.rootUri), true);
|
|
99
|
-
}
|
|
100
|
-
else if (initializeParams.rootPath) {
|
|
101
|
-
status.workspaceFolders.set(vscode_uri_1.URI.file(initializeParams.rootPath), true);
|
|
102
|
-
}
|
|
103
|
-
const capabilitiesArr = status.languageServicePlugins.map(plugin => plugin.capabilities);
|
|
104
|
-
status.initializeResult = { capabilities: {} };
|
|
105
|
-
status.initializeResult.capabilities = {
|
|
106
|
-
textDocumentSync: vscode.TextDocumentSyncKind.Incremental,
|
|
107
|
-
workspace: {
|
|
108
|
-
// #18
|
|
109
|
-
workspaceFolders: {
|
|
110
|
-
supported: true,
|
|
111
|
-
changeNotifications: true,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
selectionRangeProvider: capabilitiesArr.some(data => data.selectionRangeProvider) || undefined,
|
|
115
|
-
foldingRangeProvider: capabilitiesArr.some(data => data.foldingRangeProvider) || undefined,
|
|
116
|
-
linkedEditingRangeProvider: capabilitiesArr.some(data => data.linkedEditingRangeProvider) || undefined,
|
|
117
|
-
colorProvider: capabilitiesArr.some(data => data.colorProvider) || undefined,
|
|
118
|
-
documentSymbolProvider: capabilitiesArr.some(data => data.documentSymbolProvider) || undefined,
|
|
119
|
-
documentFormattingProvider: capabilitiesArr.some(data => data.documentFormattingProvider) || undefined,
|
|
120
|
-
documentRangeFormattingProvider: capabilitiesArr.some(data => data.documentFormattingProvider) || undefined,
|
|
121
|
-
referencesProvider: capabilitiesArr.some(data => data.referencesProvider) || undefined,
|
|
122
|
-
implementationProvider: capabilitiesArr.some(data => data.implementationProvider) || undefined,
|
|
123
|
-
definitionProvider: capabilitiesArr.some(data => data.definitionProvider) || undefined,
|
|
124
|
-
typeDefinitionProvider: capabilitiesArr.some(data => data.typeDefinitionProvider) || undefined,
|
|
125
|
-
callHierarchyProvider: capabilitiesArr.some(data => data.callHierarchyProvider) || undefined,
|
|
126
|
-
hoverProvider: capabilitiesArr.some(data => data.hoverProvider) || undefined,
|
|
127
|
-
documentHighlightProvider: capabilitiesArr.some(data => data.documentHighlightProvider) || undefined,
|
|
128
|
-
workspaceSymbolProvider: capabilitiesArr.some(data => data.workspaceSymbolProvider)
|
|
129
|
-
? { resolveProvider: capabilitiesArr.some(data => data.workspaceSymbolProvider?.resolveProvider) || undefined }
|
|
130
|
-
: undefined,
|
|
131
|
-
renameProvider: capabilitiesArr.some(data => data.renameProvider)
|
|
132
|
-
? { prepareProvider: capabilitiesArr.some(data => data.renameProvider?.prepareProvider) || undefined }
|
|
133
|
-
: undefined,
|
|
134
|
-
documentLinkProvider: capabilitiesArr.some(data => data.documentLinkProvider)
|
|
135
|
-
? { resolveProvider: capabilitiesArr.some(data => data.documentLinkProvider?.resolveProvider) || undefined }
|
|
136
|
-
: undefined,
|
|
137
|
-
codeLensProvider: capabilitiesArr.some(data => data.codeLensProvider)
|
|
138
|
-
? { resolveProvider: capabilitiesArr.some(data => data.codeLensProvider?.resolveProvider) || undefined }
|
|
139
|
-
: undefined,
|
|
140
|
-
inlayHintProvider: capabilitiesArr.some(data => data.inlayHintProvider)
|
|
141
|
-
? { resolveProvider: capabilitiesArr.some(data => data.inlayHintProvider?.resolveProvider) || undefined }
|
|
142
|
-
: undefined,
|
|
143
|
-
signatureHelpProvider: capabilitiesArr.some(data => data.signatureHelpProvider)
|
|
144
|
-
? {
|
|
145
|
-
triggerCharacters: [...new Set(capabilitiesArr.map(data => data.signatureHelpProvider?.triggerCharacters ?? []).flat())],
|
|
146
|
-
retriggerCharacters: [...new Set(capabilitiesArr.map(data => data.signatureHelpProvider?.retriggerCharacters ?? []).flat())],
|
|
147
|
-
}
|
|
148
|
-
: undefined,
|
|
149
|
-
completionProvider: capabilitiesArr.some(data => data.completionProvider)
|
|
150
|
-
? {
|
|
151
|
-
resolveProvider: capabilitiesArr.some(data => data.completionProvider?.resolveProvider) || undefined,
|
|
152
|
-
triggerCharacters: [...new Set(capabilitiesArr.map(data => data.completionProvider?.triggerCharacters ?? []).flat())],
|
|
153
|
-
}
|
|
154
|
-
: undefined,
|
|
155
|
-
semanticTokensProvider: capabilitiesArr.some(data => data.semanticTokensProvider)
|
|
156
|
-
? {
|
|
157
|
-
range: true,
|
|
158
|
-
full: false,
|
|
159
|
-
legend: {
|
|
160
|
-
tokenTypes: [...new Set(capabilitiesArr.map(data => data.semanticTokensProvider?.legend?.tokenTypes ?? []).flat())],
|
|
161
|
-
tokenModifiers: [...new Set(capabilitiesArr.map(data => data.semanticTokensProvider?.legend?.tokenModifiers ?? []).flat())],
|
|
162
|
-
},
|
|
163
|
-
}
|
|
164
|
-
: undefined,
|
|
165
|
-
codeActionProvider: capabilitiesArr.some(data => data.codeActionProvider)
|
|
166
|
-
? {
|
|
167
|
-
resolveProvider: capabilitiesArr.some(data => data.codeActionProvider?.resolveProvider) || undefined,
|
|
168
|
-
codeActionKinds: capabilitiesArr.some(data => data.codeActionProvider?.codeActionKinds)
|
|
169
|
-
? [...new Set(capabilitiesArr.map(data => data.codeActionProvider?.codeActionKinds ?? []).flat())]
|
|
170
|
-
: undefined,
|
|
171
|
-
}
|
|
172
|
-
: undefined,
|
|
173
|
-
diagnosticProvider: capabilitiesArr.some(data => data.diagnosticProvider)
|
|
174
|
-
? {
|
|
175
|
-
interFileDependencies: true,
|
|
176
|
-
workspaceDiagnostics: capabilitiesArr.some(data => data.diagnosticProvider?.workspaceDiagnostics),
|
|
177
|
-
}
|
|
178
|
-
: undefined,
|
|
179
|
-
documentOnTypeFormattingProvider: capabilitiesArr.some(data => data.documentOnTypeFormattingProvider)
|
|
180
|
-
? {
|
|
181
|
-
firstTriggerCharacter: [...new Set(capabilitiesArr.map(data => data.documentOnTypeFormattingProvider?.triggerCharacters ?? []).flat())][0],
|
|
182
|
-
moreTriggerCharacter: [...new Set(capabilitiesArr.map(data => data.documentOnTypeFormattingProvider?.triggerCharacters ?? []).flat())].slice(1),
|
|
183
|
-
}
|
|
184
|
-
: undefined,
|
|
185
|
-
executeCommandProvider: capabilitiesArr.some(data => data.executeCommandProvider)
|
|
186
|
-
? {
|
|
187
|
-
commands: [...new Set(capabilitiesArr.map(data => data.executeCommandProvider?.commands ?? []).flat())],
|
|
188
|
-
}
|
|
189
|
-
: undefined,
|
|
190
|
-
};
|
|
191
|
-
if (!status.pullModelDiagnostics && status.initializeResult.capabilities.diagnosticProvider) {
|
|
192
|
-
status.initializeResult.capabilities.diagnosticProvider = undefined;
|
|
193
|
-
activateServerPushDiagnostics(project);
|
|
194
|
-
}
|
|
195
|
-
if (capabilitiesArr.some(data => data.autoInsertionProvider)) {
|
|
196
|
-
const triggerCharacterToConfigurationSections = new Map();
|
|
197
|
-
const tryAdd = (char, section) => {
|
|
198
|
-
let sectionSet = triggerCharacterToConfigurationSections.get(char);
|
|
199
|
-
if (!sectionSet) {
|
|
200
|
-
triggerCharacterToConfigurationSections.set(char, sectionSet = new Set());
|
|
201
|
-
}
|
|
202
|
-
if (section) {
|
|
203
|
-
sectionSet.add(section);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
for (const data of capabilitiesArr) {
|
|
207
|
-
if (data.autoInsertionProvider) {
|
|
208
|
-
const { triggerCharacters, configurationSections } = data.autoInsertionProvider;
|
|
209
|
-
if (configurationSections) {
|
|
210
|
-
if (configurationSections.length !== triggerCharacters.length) {
|
|
211
|
-
throw new Error('configurationSections.length !== triggerCharacters.length');
|
|
212
|
-
}
|
|
213
|
-
for (let i = 0; i < configurationSections.length; i++) {
|
|
214
|
-
tryAdd(triggerCharacters[i], configurationSections[i]);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
for (const char of triggerCharacters) {
|
|
219
|
-
tryAdd(char);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
status.initializeResult.capabilities.experimental ??= {};
|
|
225
|
-
status.initializeResult.capabilities.experimental.autoInsertionProvider = {
|
|
226
|
-
triggerCharacters: [],
|
|
227
|
-
configurationSections: [],
|
|
228
|
-
};
|
|
229
|
-
for (const [char, sections] of triggerCharacterToConfigurationSections) {
|
|
230
|
-
if (sections.size) {
|
|
231
|
-
status.initializeResult.capabilities.experimental.autoInsertionProvider.triggerCharacters.push(char);
|
|
232
|
-
status.initializeResult.capabilities.experimental.autoInsertionProvider.configurationSections.push([...sections]);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
status.initializeResult.autoInsertionProvider.triggerCharacters.push(char);
|
|
236
|
-
status.initializeResult.autoInsertionProvider.configurationSections.push(null);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (capabilitiesArr.some(data => data.fileRenameProvider)) {
|
|
241
|
-
status.initializeResult.capabilities.experimental ??= {};
|
|
242
|
-
status.initializeResult.capabilities.experimental.fileRenameProvider = true;
|
|
243
|
-
}
|
|
244
|
-
if (capabilitiesArr.some(data => data.fileReferencesProvider)) {
|
|
245
|
-
status.initializeResult.capabilities.experimental ??= {};
|
|
246
|
-
status.initializeResult.capabilities.experimental.fileReferencesProvider = true;
|
|
247
|
-
}
|
|
248
|
-
return status.initializeResult;
|
|
249
|
-
}
|
|
250
|
-
function initialized() {
|
|
251
|
-
status.project.setup(status);
|
|
252
|
-
(0, registerEditorFeatures_js_1.registerEditorFeatures)(status);
|
|
253
|
-
(0, registerLanguageFeatures_js_1.registerLanguageFeatures)(status);
|
|
254
|
-
registerWorkspaceFoldersWatcher();
|
|
255
|
-
registerConfigurationWatcher();
|
|
256
|
-
updateHttpSettings();
|
|
257
|
-
onDidChangeConfiguration(updateHttpSettings);
|
|
258
|
-
}
|
|
259
|
-
function shutdown() {
|
|
260
|
-
status.project.reload();
|
|
261
|
-
}
|
|
262
|
-
async function updateHttpSettings() {
|
|
263
|
-
const httpSettings = await getConfiguration('http');
|
|
264
|
-
(0, request_light_1.configure)(httpSettings?.proxy, httpSettings?.proxyStrictSSL ?? false);
|
|
265
|
-
}
|
|
266
|
-
function getConfiguration(section, scopeUri) {
|
|
267
|
-
if (!status.initializeParams?.capabilities.workspace?.configuration) {
|
|
268
|
-
return Promise.resolve(undefined);
|
|
269
|
-
}
|
|
270
|
-
if (!scopeUri && status.initializeParams.capabilities.workspace?.didChangeConfiguration) {
|
|
271
|
-
if (!configurations.has(section)) {
|
|
272
|
-
configurations.set(section, getConfigurationWorker(section, scopeUri));
|
|
273
|
-
}
|
|
274
|
-
return configurations.get(section);
|
|
275
|
-
}
|
|
276
|
-
return getConfigurationWorker(section, scopeUri);
|
|
277
|
-
}
|
|
278
|
-
async function getConfigurationWorker(section, scopeUri) {
|
|
279
|
-
return (await connection.workspace.getConfiguration({ scopeUri, section })) ?? undefined /* replace null to undefined */;
|
|
280
|
-
}
|
|
281
|
-
function onDidChangeConfiguration(cb) {
|
|
282
|
-
didChangeConfigurationCallbacks.add(cb);
|
|
283
|
-
return {
|
|
284
|
-
dispose() {
|
|
285
|
-
didChangeConfigurationCallbacks.delete(cb);
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function onDidChangeWatchedFiles(cb) {
|
|
290
|
-
didChangeWatchedFilesCallbacks.add(cb);
|
|
291
|
-
return {
|
|
292
|
-
dispose: () => {
|
|
293
|
-
didChangeWatchedFilesCallbacks.delete(cb);
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function createFsWithCache(fs) {
|
|
298
|
-
const readFileCache = (0, language_service_1.createUriMap)();
|
|
299
|
-
const statCache = (0, language_service_1.createUriMap)();
|
|
300
|
-
const readDirectoryCache = (0, language_service_1.createUriMap)();
|
|
301
|
-
documents.onDidSave(({ document }) => {
|
|
302
|
-
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
303
|
-
readFileCache.set(uri, document.getText());
|
|
304
|
-
statCache.delete(uri);
|
|
305
|
-
});
|
|
306
|
-
onDidChangeWatchedFiles(({ changes }) => {
|
|
307
|
-
for (const change of changes) {
|
|
308
|
-
const changeUri = vscode_uri_1.URI.parse(change.uri);
|
|
309
|
-
const dir = vscode_uri_1.URI.parse(change.uri.substring(0, change.uri.lastIndexOf('/')));
|
|
310
|
-
if (change.type === vscode.FileChangeType.Deleted) {
|
|
311
|
-
readFileCache.set(changeUri, undefined);
|
|
312
|
-
statCache.set(changeUri, undefined);
|
|
313
|
-
readDirectoryCache.delete(dir);
|
|
314
|
-
}
|
|
315
|
-
else if (change.type === vscode.FileChangeType.Changed) {
|
|
316
|
-
readFileCache.delete(changeUri);
|
|
317
|
-
statCache.delete(changeUri);
|
|
318
|
-
}
|
|
319
|
-
else if (change.type === vscode.FileChangeType.Created) {
|
|
320
|
-
readFileCache.delete(changeUri);
|
|
321
|
-
statCache.delete(changeUri);
|
|
322
|
-
readDirectoryCache.delete(dir);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
return {
|
|
327
|
-
readFile: uri => {
|
|
328
|
-
if (!readFileCache.has(uri)) {
|
|
329
|
-
readFileCache.set(uri, fs.readFile(uri));
|
|
330
|
-
}
|
|
331
|
-
return readFileCache.get(uri);
|
|
332
|
-
},
|
|
333
|
-
stat: uri => {
|
|
334
|
-
if (!statCache.has(uri)) {
|
|
335
|
-
statCache.set(uri, fs.stat(uri));
|
|
336
|
-
}
|
|
337
|
-
return statCache.get(uri);
|
|
338
|
-
},
|
|
339
|
-
readDirectory: uri => {
|
|
340
|
-
if (!readDirectoryCache.has(uri)) {
|
|
341
|
-
readDirectoryCache.set(uri, fs.readDirectory(uri));
|
|
342
|
-
}
|
|
343
|
-
return readDirectoryCache.get(uri);
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
function registerConfigurationWatcher() {
|
|
348
|
-
const didChangeConfiguration = status.initializeParams?.capabilities.workspace?.didChangeConfiguration;
|
|
349
|
-
if (didChangeConfiguration) {
|
|
350
|
-
connection.onDidChangeConfiguration(params => {
|
|
351
|
-
configurations.clear();
|
|
352
|
-
for (const cb of didChangeConfigurationCallbacks) {
|
|
353
|
-
cb(params);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
if (didChangeConfiguration.dynamicRegistration) {
|
|
357
|
-
connection.client.register(vscode.DidChangeConfigurationNotification.type);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
async function watchFiles(patterns) {
|
|
362
|
-
const disposables = [];
|
|
363
|
-
const didChangeWatchedFiles = status.initializeParams?.capabilities.workspace?.didChangeWatchedFiles;
|
|
364
|
-
const fileOperations = status.initializeParams?.capabilities.workspace?.fileOperations;
|
|
365
|
-
if (didChangeWatchedFiles) {
|
|
366
|
-
if (watchFilesDisposableCounter === 0) {
|
|
367
|
-
watchFilesDisposable = connection.onDidChangeWatchedFiles(e => {
|
|
368
|
-
for (const cb of didChangeWatchedFilesCallbacks) {
|
|
369
|
-
cb(e);
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
watchFilesDisposableCounter++;
|
|
374
|
-
disposables.push({
|
|
375
|
-
dispose() {
|
|
376
|
-
watchFilesDisposableCounter--;
|
|
377
|
-
if (watchFilesDisposableCounter === 0) {
|
|
378
|
-
watchFilesDisposable?.dispose();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
if (didChangeWatchedFiles?.dynamicRegistration) {
|
|
384
|
-
disposables.push(await connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
385
|
-
watchers: patterns.map(pattern => ({ globPattern: pattern })),
|
|
386
|
-
}));
|
|
387
|
-
}
|
|
388
|
-
if (fileOperations?.dynamicRegistration && fileOperations.willRename) {
|
|
389
|
-
disposables.push(await connection.client.register(vscode.WillRenameFilesRequest.type, {
|
|
390
|
-
filters: patterns.map(pattern => ({ pattern: { glob: pattern } })),
|
|
391
|
-
}));
|
|
392
|
-
}
|
|
393
|
-
return fromDisposables(disposables);
|
|
394
|
-
}
|
|
395
|
-
function registerWorkspaceFoldersWatcher() {
|
|
396
|
-
if (status.initializeParams?.capabilities.workspace?.workspaceFolders) {
|
|
397
|
-
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
398
|
-
for (const folder of e.added) {
|
|
399
|
-
status.workspaceFolders.set(vscode_uri_1.URI.parse(folder.uri), true);
|
|
400
|
-
}
|
|
401
|
-
for (const folder of e.removed) {
|
|
402
|
-
status.workspaceFolders.delete(vscode_uri_1.URI.parse(folder.uri));
|
|
403
|
-
}
|
|
404
|
-
status.project.reload();
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function activateServerPushDiagnostics(project) {
|
|
409
|
-
documents.onDidChangeContent(({ document }) => {
|
|
410
|
-
pushAllDiagnostics(project, document.uri);
|
|
411
|
-
});
|
|
412
|
-
documents.onDidClose(({ document }) => {
|
|
413
|
-
connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
|
|
414
|
-
});
|
|
415
|
-
onDidChangeConfiguration(() => refresh(project));
|
|
416
|
-
}
|
|
417
|
-
function clearPushDiagnostics() {
|
|
418
|
-
if (!status.pullModelDiagnostics) {
|
|
419
|
-
for (const document of documents.all()) {
|
|
420
|
-
connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
async function refresh(project) {
|
|
425
|
-
const req = ++semanticTokensReq;
|
|
426
|
-
if (!status.pullModelDiagnostics) {
|
|
427
|
-
await pushAllDiagnostics(project);
|
|
428
|
-
}
|
|
429
|
-
const delay = 250;
|
|
430
|
-
await sleep(delay);
|
|
431
|
-
if (req === semanticTokensReq) {
|
|
432
|
-
if (status.initializeParams?.capabilities.workspace?.semanticTokens?.refreshSupport) {
|
|
433
|
-
connection.languages.semanticTokens.refresh();
|
|
434
|
-
}
|
|
435
|
-
if (status.initializeParams?.capabilities.workspace?.inlayHint?.refreshSupport) {
|
|
436
|
-
connection.languages.inlayHint.refresh();
|
|
437
|
-
}
|
|
438
|
-
if (status.pullModelDiagnostics && status.initializeParams?.capabilities.workspace?.diagnostics?.refreshSupport) {
|
|
439
|
-
connection.languages.diagnostics.refresh();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
async function pushAllDiagnostics(project, docUri) {
|
|
444
|
-
const req = ++documentUpdatedReq;
|
|
445
|
-
const delay = 250;
|
|
446
|
-
const token = {
|
|
447
|
-
get isCancellationRequested() {
|
|
448
|
-
return req !== documentUpdatedReq;
|
|
449
|
-
},
|
|
450
|
-
onCancellationRequested: vscode.Event.None,
|
|
451
|
-
};
|
|
452
|
-
const changeDoc = docUri ? documents.get(docUri) : undefined;
|
|
453
|
-
const otherDocs = [...documents.all()].filter(doc => doc !== changeDoc);
|
|
454
|
-
if (changeDoc) {
|
|
455
|
-
await sleep(delay);
|
|
456
|
-
if (token.isCancellationRequested) {
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
await pushDiagnostics(project, changeDoc.uri, changeDoc.version, token);
|
|
460
|
-
}
|
|
461
|
-
for (const doc of otherDocs) {
|
|
462
|
-
await sleep(delay);
|
|
463
|
-
if (token.isCancellationRequested) {
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
await pushDiagnostics(project, doc.uri, doc.version, token);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
async function pushDiagnostics(project, uriStr, version, cancel) {
|
|
470
|
-
const uri = vscode_uri_1.URI.parse(uriStr);
|
|
471
|
-
const languageService = await project.getLanguageService(uri);
|
|
472
|
-
const errors = await languageService.getDiagnostics(uri, cancel, result => {
|
|
473
|
-
connection.sendDiagnostics({ uri: uriStr, diagnostics: result, version });
|
|
474
|
-
});
|
|
475
|
-
connection.sendDiagnostics({ uri: uriStr, diagnostics: errors, version });
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
function sleep(ms) {
|
|
479
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
480
|
-
}
|
|
481
|
-
function fromDisposables(disposables) {
|
|
482
|
-
return {
|
|
483
|
-
dispose() {
|
|
484
|
-
for (const disposable of disposables) {
|
|
485
|
-
disposable.dispose();
|
|
486
|
-
}
|
|
27
|
+
const configurations = (0, configurations_js_1.register)(state);
|
|
28
|
+
const editorFeatures = (0, editorFeatures_js_1.register)(state);
|
|
29
|
+
const documents = (0, textDocuments_js_1.register)(state);
|
|
30
|
+
const workspaceFolders = (0, workspaceFolders_js_1.register)(state);
|
|
31
|
+
const fileWatcher = (0, fileWatcher_js_1.register)(state);
|
|
32
|
+
const languageFeatures = (0, languageFeatures_js_1.register)(state, documents, configurations);
|
|
33
|
+
const fileSystem = (0, fileSystem_js_1.register)(documents, fileWatcher);
|
|
34
|
+
const server = {
|
|
35
|
+
...state,
|
|
36
|
+
get initializeParams() {
|
|
37
|
+
return state.initializeParams;
|
|
487
38
|
},
|
|
39
|
+
get project() {
|
|
40
|
+
return state.project;
|
|
41
|
+
},
|
|
42
|
+
get languageServicePlugins() {
|
|
43
|
+
return state.languageServicePlugins;
|
|
44
|
+
},
|
|
45
|
+
initialize(params, project, languageServicePlugins) {
|
|
46
|
+
state.initializeParams = params;
|
|
47
|
+
state.project = project;
|
|
48
|
+
state.languageServicePlugins = languageServicePlugins;
|
|
49
|
+
const serverCapabilities = {};
|
|
50
|
+
onInitializeCallbacks.forEach(cb => cb(serverCapabilities));
|
|
51
|
+
return { capabilities: serverCapabilities };
|
|
52
|
+
},
|
|
53
|
+
initialized() {
|
|
54
|
+
onInitializedCallbacks.forEach(cb => cb());
|
|
55
|
+
state.project.setup(server);
|
|
56
|
+
},
|
|
57
|
+
shutdown() {
|
|
58
|
+
state.project.reload();
|
|
59
|
+
},
|
|
60
|
+
configurations,
|
|
61
|
+
editorFeatures,
|
|
62
|
+
documents,
|
|
63
|
+
workspaceFolders,
|
|
64
|
+
fileWatcher,
|
|
65
|
+
languageFeatures,
|
|
66
|
+
fileSystem,
|
|
488
67
|
};
|
|
68
|
+
return server;
|
|
489
69
|
}
|
|
490
70
|
//# sourceMappingURL=server.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InitializeParams, LanguageService, LanguageServicePlugin, ProviderResult, ServerCapabilities } from '@volar/language-service';
|
|
2
|
+
import { Connection } from 'vscode-languageserver';
|
|
2
3
|
import type { URI } from 'vscode-uri';
|
|
3
|
-
import
|
|
4
|
+
import { createServerBase } from './server';
|
|
5
|
+
export interface LanguageServerEnvironment {
|
|
6
|
+
timer: {
|
|
7
|
+
setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => void;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
4
10
|
export interface LanguageServerProject {
|
|
5
11
|
setup(server: LanguageServer): void;
|
|
6
12
|
getLanguageService(uri: URI): ProviderResult<LanguageService>;
|
|
7
13
|
getExistingLanguageServices(): ProviderResult<LanguageService[]>;
|
|
8
14
|
reload(): void;
|
|
9
15
|
}
|
|
16
|
+
export interface LanguageServerState {
|
|
17
|
+
env: LanguageServerEnvironment;
|
|
18
|
+
connection: Connection;
|
|
19
|
+
initializeParams: InitializeParams;
|
|
20
|
+
project: LanguageServerProject;
|
|
21
|
+
languageServicePlugins: LanguageServicePlugin[];
|
|
22
|
+
onInitialize(callback: (serverCapabilities: ServerCapabilities<ExperimentalFeatures>) => void): void;
|
|
23
|
+
onInitialized(callback: () => void): void;
|
|
24
|
+
}
|
|
10
25
|
export type LanguageServer = ReturnType<typeof createServerBase>;
|
|
11
|
-
export interface
|
|
26
|
+
export interface ExperimentalFeatures {
|
|
12
27
|
fileReferencesProvider?: boolean;
|
|
13
|
-
|
|
28
|
+
fileRenameEditsProvider?: boolean;
|
|
29
|
+
documentDropEditsProvider?: boolean;
|
|
14
30
|
autoInsertionProvider?: {
|
|
15
31
|
triggerCharacters: string[];
|
|
16
32
|
configurationSections?: (string[] | null)[];
|
|
17
33
|
};
|
|
18
|
-
}> {
|
|
19
34
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineChangeRanges = combineChangeRanges;
|
|
4
|
+
function combineChangeRanges(...changeRanges) {
|
|
5
|
+
let changeRange = changeRanges[0];
|
|
6
|
+
for (let i = 1; i < changeRanges.length; i++) {
|
|
7
|
+
const nextChangeRange = changeRanges[i];
|
|
8
|
+
changeRange = combineTwoChanges(changeRange, nextChangeRange);
|
|
9
|
+
}
|
|
10
|
+
return changeRange;
|
|
11
|
+
}
|
|
12
|
+
// https://tsplay.dev/mMldVN - @browsnet
|
|
13
|
+
function combineTwoChanges(a, b) {
|
|
14
|
+
const aStart = a.span.start;
|
|
15
|
+
const aEnd = a.span.start + a.span.length;
|
|
16
|
+
const aDiff = a.newLength - a.span.length;
|
|
17
|
+
const changeBegin = aStart + Math.min(a.span.length, a.newLength);
|
|
18
|
+
const rollback = (start) => start > changeBegin ? Math.max(aStart, start - aDiff) : start;
|
|
19
|
+
const bStart = rollback(b.span.start);
|
|
20
|
+
const bEnd = rollback(b.span.start + b.span.length);
|
|
21
|
+
const bDiff = b.newLength - b.span.length;
|
|
22
|
+
const start = Math.min(aStart, bStart);
|
|
23
|
+
const end = Math.max(aEnd, bEnd);
|
|
24
|
+
const length = end - start;
|
|
25
|
+
const newLength = aDiff + bDiff + length;
|
|
26
|
+
return { span: { start, length }, newLength };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=combineChangeRanges.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
+
import { Range, TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
+
export declare class SnapshotDocument implements TextDocument {
|
|
5
|
+
private document;
|
|
6
|
+
private snapshots;
|
|
7
|
+
constructor(uri: string, languageId: string, version: number, text: string);
|
|
8
|
+
get uri(): string;
|
|
9
|
+
get languageId(): string;
|
|
10
|
+
get version(): number;
|
|
11
|
+
get lineCount(): number;
|
|
12
|
+
getText(range?: Range): string;
|
|
13
|
+
positionAt(offset: number): import("vscode-languageserver-textdocument").Position;
|
|
14
|
+
offsetAt(position: vscode.Position): number;
|
|
15
|
+
/**
|
|
16
|
+
* Update the document with the given content changes and version.
|
|
17
|
+
* If all changes is incremental, calculate the change range and add a new snapshot.
|
|
18
|
+
* Otherwise, reset the changes.
|
|
19
|
+
*/
|
|
20
|
+
update(contentChanges: vscode.TextDocumentContentChangeEvent[], version: number): void;
|
|
21
|
+
getSnapshot(): ts.IScriptSnapshot;
|
|
22
|
+
private resetChanges;
|
|
23
|
+
/**
|
|
24
|
+
* Calculate the change range from the given content changes.
|
|
25
|
+
*/
|
|
26
|
+
private calculateChangeRange;
|
|
27
|
+
private clearUnreferencedVersions;
|
|
28
|
+
}
|