@volar/language-server 1.11.1 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/browser.d.ts +4 -3
  2. package/browser.js +16 -6
  3. package/index.d.ts +0 -1
  4. package/lib/cancellationToken.d.ts +3 -0
  5. package/lib/{node/cancellationPipe.js → cancellationToken.js} +2 -3
  6. package/lib/config.d.ts +5 -0
  7. package/lib/config.js +32 -0
  8. package/lib/{common/configurationHost.d.ts → configurationHost.d.ts} +1 -2
  9. package/lib/project/inferredCompilerOptions.d.ts +3 -0
  10. package/lib/{common/utils → project}/inferredCompilerOptions.js +3 -3
  11. package/lib/project/simpleProject.d.ts +4 -0
  12. package/lib/project/simpleProject.js +34 -0
  13. package/lib/project/simpleProjectProvider.d.ts +25 -0
  14. package/lib/project/simpleProjectProvider.js +67 -0
  15. package/lib/project/typescriptProject.d.ts +11 -0
  16. package/lib/project/typescriptProject.js +136 -0
  17. package/lib/project/typescriptProjectProvider.d.ts +4 -0
  18. package/lib/project/typescriptProjectProvider.js +232 -0
  19. package/lib/register/registerEditorFeatures.d.ts +3 -0
  20. package/lib/register/registerEditorFeatures.js +157 -0
  21. package/lib/register/registerLanguageFeatures.d.ts +5 -0
  22. package/lib/{common/features/languageFeatures.js → register/registerLanguageFeatures.js} +17 -31
  23. package/lib/{common/schemaRequestHandlers → schemaRequestHandlers}/http.d.ts +0 -1
  24. package/lib/server.d.ts +14 -0
  25. package/lib/server.js +325 -0
  26. package/lib/setupCapabilities.d.ts +4 -0
  27. package/lib/{common/utils/registerFeatures.js → setupCapabilities.js} +6 -9
  28. package/lib/types.d.ts +39 -17
  29. package/lib/{common/utils → utils}/isFileInDir.d.ts +0 -1
  30. package/lib/{common/utils → utils}/uriMap.d.ts +1 -1
  31. package/lib/workspaceFolderManager.d.ts +16 -0
  32. package/lib/workspaceFolderManager.js +39 -0
  33. package/node.d.ts +4 -3
  34. package/node.js +18 -8
  35. package/package.json +7 -7
  36. package/protocol.d.ts +40 -12
  37. package/protocol.js +16 -1
  38. package/lib/common/documents.d.ts +0 -47
  39. package/lib/common/documents.js +0 -216
  40. package/lib/common/features/customFeatures.d.ts +0 -5
  41. package/lib/common/features/customFeatures.js +0 -138
  42. package/lib/common/features/languageFeatures.d.ts +0 -7
  43. package/lib/common/project.d.ts +0 -141
  44. package/lib/common/project.js +0 -202
  45. package/lib/common/server.d.ts +0 -15
  46. package/lib/common/server.js +0 -227
  47. package/lib/common/utils/inferredCompilerOptions.d.ts +0 -4
  48. package/lib/common/utils/registerFeatures.d.ts +0 -5
  49. package/lib/common/utils/serverConfig.d.ts +0 -3
  50. package/lib/common/utils/serverConfig.js +0 -22
  51. package/lib/common/workspaces.d.ts +0 -1824
  52. package/lib/common/workspaces.js +0 -347
  53. package/lib/node/cancellationPipe.d.ts +0 -3
  54. /package/lib/{common/configurationHost.js → configurationHost.js} +0 -0
  55. /package/lib/{common/schemaRequestHandlers → schemaRequestHandlers}/http.js +0 -0
  56. /package/lib/{common/utils → utils}/isFileInDir.js +0 -0
  57. /package/lib/{common/utils → utils}/uriMap.js +0 -0
@@ -1,347 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortTsConfigs = exports.sleep = exports.createWorkspaces = exports.rootTsConfigNames = void 0;
4
- const vscode = require("vscode-languageserver");
5
- const vscode_uri_1 = require("vscode-uri");
6
- const types_1 = require("../types");
7
- const isFileInDir_1 = require("./utils/isFileInDir");
8
- const path = require("path-browserify");
9
- const project_1 = require("./project");
10
- const inferredCompilerOptions_1 = require("./utils/inferredCompilerOptions");
11
- const uriMap_1 = require("./utils/uriMap");
12
- const language_service_1 = require("@volar/language-service");
13
- exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
14
- function createWorkspaces(context, rootUris) {
15
- const { fileNameToUri, uriToFileName, fs } = context.server.runtimeEnv;
16
- const configProjects = (0, uriMap_1.createUriMap)(fileNameToUri);
17
- const inferredProjects = (0, uriMap_1.createUriMap)(fileNameToUri);
18
- const rootTsConfigs = new Set();
19
- const searchedDirs = new Set();
20
- let semanticTokensReq = 0;
21
- let documentUpdatedReq = 0;
22
- context.workspaces.documents.onDidChangeContent(({ textDocument }) => {
23
- updateDiagnostics(textDocument.uri);
24
- });
25
- context.workspaces.documents.onDidClose(({ textDocument }) => {
26
- context.server.connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
27
- });
28
- context.server.onDidChangeWatchedFiles(({ changes }) => {
29
- const tsConfigChanges = changes.filter(change => exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
30
- for (const change of tsConfigChanges) {
31
- if (change.type === vscode.FileChangeType.Created) {
32
- rootTsConfigs.add(uriToFileName(change.uri));
33
- }
34
- else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && configProjects.uriHas(change.uri)) {
35
- if (change.type === vscode.FileChangeType.Deleted) {
36
- rootTsConfigs.delete(uriToFileName(change.uri));
37
- }
38
- const project = configProjects.uriGet(change.uri);
39
- configProjects.uriDelete(change.uri);
40
- project?.then(project => project.dispose());
41
- }
42
- }
43
- if (tsConfigChanges.length) {
44
- reloadDiagnostics();
45
- }
46
- else {
47
- updateDiagnosticsAndSemanticTokens();
48
- }
49
- });
50
- context.server.configurationHost?.onDidChangeConfiguration?.(updateDiagnosticsAndSemanticTokens);
51
- return {
52
- configProjects,
53
- inferredProjects,
54
- getProject: getProjectAndTsConfig,
55
- reloadProjects: reloadProject,
56
- add: (rootUri) => {
57
- if (!rootUris.some(uri => uri.toString() === rootUri.toString())) {
58
- rootUris.push(rootUri);
59
- }
60
- },
61
- remove: (rootUri) => {
62
- rootUris = rootUris.filter(uri => uri.toString() !== rootUri.toString());
63
- for (const uri of configProjects.uriKeys()) {
64
- const project = configProjects.uriGet(uri);
65
- project.then(project => {
66
- if (project.context.project.workspaceUri.toString() === rootUri.toString()) {
67
- configProjects.uriDelete(uri);
68
- project.dispose();
69
- }
70
- });
71
- }
72
- },
73
- };
74
- async function reloadProject() {
75
- for (const project of [...configProjects.values(), ...inferredProjects.values()]) {
76
- project.then(project => project.dispose());
77
- }
78
- configProjects.clear();
79
- inferredProjects.clear();
80
- reloadDiagnostics();
81
- }
82
- function reloadDiagnostics() {
83
- for (const doc of context.workspaces.documents.data.values()) {
84
- context.server.connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
85
- }
86
- updateDiagnosticsAndSemanticTokens();
87
- }
88
- async function updateDiagnosticsAndSemanticTokens() {
89
- const req = ++semanticTokensReq;
90
- await updateDiagnostics();
91
- const delay = 250;
92
- await sleep(delay);
93
- if (req === semanticTokensReq) {
94
- if (context.workspaces.initParams.capabilities.workspace?.semanticTokens?.refreshSupport) {
95
- context.server.connection.languages.semanticTokens.refresh();
96
- }
97
- if (context.workspaces.initParams.capabilities.workspace?.inlayHint?.refreshSupport) {
98
- context.server.connection.languages.inlayHint.refresh();
99
- }
100
- if ((context.workspaces.initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
101
- if (context.workspaces.initParams.capabilities.workspace?.diagnostics?.refreshSupport) {
102
- context.server.connection.languages.diagnostics.refresh();
103
- }
104
- }
105
- }
106
- }
107
- async function updateDiagnostics(docUri) {
108
- if ((context.workspaces.initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
109
- return;
110
- const req = ++documentUpdatedReq;
111
- const delay = 250;
112
- const cancel = context.server.runtimeEnv.getCancellationToken({
113
- get isCancellationRequested() {
114
- return req !== documentUpdatedReq;
115
- },
116
- onCancellationRequested: vscode.Event.None,
117
- });
118
- const changeDoc = docUri ? context.workspaces.documents.data.uriGet(docUri) : undefined;
119
- const otherDocs = [...context.workspaces.documents.data.values()].filter(doc => doc !== changeDoc);
120
- if (changeDoc) {
121
- await sleep(delay);
122
- if (cancel.isCancellationRequested) {
123
- return;
124
- }
125
- await sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
126
- }
127
- for (const doc of otherDocs) {
128
- await sleep(delay);
129
- if (cancel.isCancellationRequested) {
130
- break;
131
- }
132
- await sendDocumentDiagnostics(doc.uri, doc.version, cancel);
133
- }
134
- }
135
- async function sendDocumentDiagnostics(uri, version, cancel) {
136
- const project = (await getProjectAndTsConfig(uri))?.project;
137
- if (!project)
138
- return;
139
- // fix https://github.com/vuejs/language-tools/issues/2627
140
- if (context.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic) {
141
- return;
142
- }
143
- // const mode = context.initOptions.serverMode === ServerMode.PartialSemantic ? 'semantic' as const
144
- // : context.initOptions.serverMode === ServerMode.Syntactic ? 'syntactic' as const
145
- // : 'all' as const;
146
- const languageService = project.getLanguageService();
147
- const errors = await languageService.doValidation(uri, 'all', cancel, result => {
148
- context.server.connection.sendDiagnostics({ uri: uri, diagnostics: result, version });
149
- });
150
- context.server.connection.sendDiagnostics({ uri: uri, diagnostics: errors, version });
151
- }
152
- async function getProjectAndTsConfig(uri) {
153
- if (context.workspaces.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
154
- const tsconfig = await findMatchConfigs(vscode_uri_1.URI.parse(uri));
155
- if (tsconfig) {
156
- const project = await getProjectByCreate(tsconfig);
157
- return {
158
- tsconfig: tsconfig,
159
- project,
160
- };
161
- }
162
- }
163
- const workspaceUri = getWorkspaceUri(vscode_uri_1.URI.parse(uri));
164
- if (!inferredProjects.uriHas(workspaceUri.toString())) {
165
- inferredProjects.uriSet(workspaceUri.toString(), (async () => {
166
- const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.server.configurationHost);
167
- return (0, project_1.createProject)({
168
- ...context,
169
- project: {
170
- workspaceUri,
171
- rootUri: workspaceUri,
172
- tsConfig: inferOptions,
173
- },
174
- });
175
- })());
176
- }
177
- const project = await inferredProjects.uriGet(workspaceUri.toString());
178
- project.tryAddFile(uriToFileName(uri));
179
- return {
180
- tsconfig: undefined,
181
- project,
182
- };
183
- }
184
- function getWorkspaceUri(uri) {
185
- const fileName = uriToFileName(uri.toString());
186
- let _rootUris = [...rootUris]
187
- .filter(rootUri => (0, isFileInDir_1.isFileInDir)(fileName, uriToFileName(rootUri.toString())))
188
- .sort((a, b) => sortTsConfigs(fileName, uriToFileName(a.toString()), uriToFileName(b.toString())));
189
- if (!_rootUris.length) {
190
- _rootUris = [...rootUris];
191
- }
192
- if (!_rootUris.length) {
193
- _rootUris = [uri.with({ path: '/' })];
194
- }
195
- return _rootUris[0];
196
- }
197
- async function findMatchConfigs(uri) {
198
- const filePath = uriToFileName(uri.toString());
199
- let dir = path.dirname(filePath);
200
- while (true) {
201
- if (searchedDirs.has(dir)) {
202
- break;
203
- }
204
- searchedDirs.add(dir);
205
- for (const tsConfigName of exports.rootTsConfigNames) {
206
- const tsconfigPath = path.join(dir, tsConfigName);
207
- if ((await fs.stat?.(fileNameToUri(tsconfigPath)))?.type === language_service_1.FileType.File) {
208
- rootTsConfigs.add(tsconfigPath);
209
- }
210
- }
211
- dir = path.dirname(dir);
212
- }
213
- await prepareClosestootParsedCommandLine();
214
- return await findDirectIncludeTsconfig() ?? await findIndirectReferenceTsconfig();
215
- async function prepareClosestootParsedCommandLine() {
216
- let matches = [];
217
- for (const rootTsConfig of rootTsConfigs) {
218
- if ((0, isFileInDir_1.isFileInDir)(uriToFileName(uri.toString()), path.dirname(rootTsConfig))) {
219
- matches.push(rootTsConfig);
220
- }
221
- }
222
- matches = matches.sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b));
223
- if (matches.length) {
224
- await getParsedCommandLine(matches[0]);
225
- }
226
- }
227
- function findIndirectReferenceTsconfig() {
228
- return findTsconfig(async (tsconfig) => {
229
- const project = await configProjects.pathGet(tsconfig);
230
- return project?.askedFiles.uriHas(uri.toString()) ?? false;
231
- });
232
- }
233
- function findDirectIncludeTsconfig() {
234
- return findTsconfig(async (tsconfig) => {
235
- const map = (0, uriMap_1.createUriMap)(fileNameToUri);
236
- const parsedCommandLine = await getParsedCommandLine(tsconfig);
237
- for (const fileName of parsedCommandLine?.fileNames ?? []) {
238
- map.pathSet(fileName, true);
239
- }
240
- return map.uriHas(uri.toString());
241
- });
242
- }
243
- async function findTsconfig(match) {
244
- const checked = new Set();
245
- for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b))) {
246
- const project = await configProjects.pathGet(rootTsConfig);
247
- if (project) {
248
- let chains = await getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
249
- if (context.workspaces.initOptions.reverseConfigFilePriority) {
250
- chains = chains.reverse();
251
- }
252
- for (const chain of chains) {
253
- for (let i = chain.length - 1; i >= 0; i--) {
254
- const tsconfig = chain[i];
255
- if (checked.has(tsconfig))
256
- continue;
257
- checked.add(tsconfig);
258
- if (await match(tsconfig)) {
259
- return tsconfig;
260
- }
261
- }
262
- }
263
- }
264
- }
265
- }
266
- async function getReferencesChains(parsedCommandLine, tsConfig, before) {
267
- if (parsedCommandLine.projectReferences?.length) {
268
- const newChains = [];
269
- for (const projectReference of parsedCommandLine.projectReferences) {
270
- let tsConfigPath = projectReference.path.replace(/\\/g, '/');
271
- // fix https://github.com/johnsoncodehk/volar/issues/712
272
- if ((await fs.stat?.(fileNameToUri(tsConfigPath)))?.type === language_service_1.FileType.File) {
273
- const newTsConfigPath = path.join(tsConfigPath, 'tsconfig.json');
274
- const newJsConfigPath = path.join(tsConfigPath, 'jsconfig.json');
275
- if ((await fs.stat?.(fileNameToUri(newTsConfigPath)))?.type === language_service_1.FileType.File) {
276
- tsConfigPath = newTsConfigPath;
277
- }
278
- else if ((await fs.stat?.(fileNameToUri(newJsConfigPath)))?.type === language_service_1.FileType.File) {
279
- tsConfigPath = newJsConfigPath;
280
- }
281
- }
282
- const beforeIndex = before.indexOf(tsConfigPath); // cycle
283
- if (beforeIndex >= 0) {
284
- newChains.push(before.slice(0, Math.max(beforeIndex, 1)));
285
- }
286
- else {
287
- const referenceParsedCommandLine = await getParsedCommandLine(tsConfigPath);
288
- if (referenceParsedCommandLine) {
289
- for (const chain of await getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
290
- newChains.push(chain);
291
- }
292
- }
293
- }
294
- }
295
- return newChains;
296
- }
297
- else {
298
- return [[...before, tsConfig]];
299
- }
300
- }
301
- async function getParsedCommandLine(tsConfig) {
302
- const project = await getProjectByCreate(tsConfig);
303
- return project?.getParsedCommandLine();
304
- }
305
- }
306
- function getProjectByCreate(_tsConfig) {
307
- const tsConfig = _tsConfig.replace(/\\/g, '/');
308
- let project = configProjects.pathGet(tsConfig);
309
- if (!project) {
310
- const rootUri = vscode_uri_1.URI.parse(fileNameToUri(path.dirname(tsConfig)));
311
- project = (0, project_1.createProject)({
312
- ...context,
313
- project: {
314
- workspaceUri: getWorkspaceUri(rootUri),
315
- rootUri: rootUri,
316
- tsConfig,
317
- },
318
- });
319
- configProjects.pathSet(tsConfig, project);
320
- }
321
- return project;
322
- }
323
- }
324
- exports.createWorkspaces = createWorkspaces;
325
- function sleep(ms) {
326
- return new Promise(resolve => setTimeout(resolve, ms));
327
- }
328
- exports.sleep = sleep;
329
- function sortTsConfigs(file, a, b) {
330
- const inA = (0, isFileInDir_1.isFileInDir)(file, path.dirname(a));
331
- const inB = (0, isFileInDir_1.isFileInDir)(file, path.dirname(b));
332
- if (inA !== inB) {
333
- const aWeight = inA ? 1 : 0;
334
- const bWeight = inB ? 1 : 0;
335
- return bWeight - aWeight;
336
- }
337
- const aLength = a.split('/').length;
338
- const bLength = b.split('/').length;
339
- if (aLength === bLength) {
340
- const aWeight = path.basename(a) === 'tsconfig.json' ? 1 : 0;
341
- const bWeight = path.basename(b) === 'tsconfig.json' ? 1 : 0;
342
- return bWeight - aWeight;
343
- }
344
- return bLength - aLength;
345
- }
346
- exports.sortTsConfigs = sortTsConfigs;
347
- //# sourceMappingURL=workspaces.js.map
@@ -1,3 +0,0 @@
1
- import * as vscode from 'vscode-languageserver';
2
- export declare function createGetCancellationToken(_cancellationPipeName: string | undefined): (original?: vscode.CancellationToken) => vscode.CancellationToken;
3
- //# sourceMappingURL=cancellationPipe.d.ts.map
File without changes
File without changes