@volar/language-server 2.2.5 → 2.3.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sleep = exports.registerLanguageFeatures = void 0;
4
4
  const embedded = require("@volar/language-service");
5
5
  const vscode = require("vscode-languageserver");
6
+ const vscode_uri_1 = require("vscode-uri");
6
7
  const protocol_1 = require("../../protocol");
7
8
  function registerLanguageFeatures(server) {
8
9
  let lastCompleteUri;
@@ -13,55 +14,65 @@ function registerLanguageFeatures(server) {
13
14
  let lastDocumentLinkLs;
14
15
  let lastInlayHintLs;
15
16
  server.connection.onDocumentFormatting(async (params, token) => {
16
- return worker(params.textDocument.uri, token, service => {
17
- return service.format(params.textDocument.uri, params.options, undefined, undefined, token);
17
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
18
+ return worker(uri, token, languageService => {
19
+ return languageService.format(uri, params.options, undefined, undefined, token);
18
20
  });
19
21
  });
20
22
  server.connection.onDocumentRangeFormatting(async (params, token) => {
21
- return worker(params.textDocument.uri, token, service => {
22
- return service.format(params.textDocument.uri, params.options, params.range, undefined, token);
23
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
24
+ return worker(uri, token, languageService => {
25
+ return languageService.format(uri, params.options, params.range, undefined, token);
23
26
  });
24
27
  });
25
28
  server.connection.onDocumentOnTypeFormatting(async (params, token) => {
26
- return worker(params.textDocument.uri, token, service => {
27
- return service.format(params.textDocument.uri, params.options, undefined, params, token);
29
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
30
+ return worker(uri, token, languageService => {
31
+ return languageService.format(uri, params.options, undefined, params, token);
28
32
  });
29
33
  });
30
34
  server.connection.onSelectionRanges(async (params, token) => {
31
- return worker(params.textDocument.uri, token, service => {
32
- return service.getSelectionRanges(params.textDocument.uri, params.positions, token);
35
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
36
+ return worker(uri, token, languageService => {
37
+ return languageService.getSelectionRanges(uri, params.positions, token);
33
38
  });
34
39
  });
35
40
  server.connection.onFoldingRanges(async (params, token) => {
36
- return worker(params.textDocument.uri, token, service => {
37
- return service.getFoldingRanges(params.textDocument.uri, token);
41
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
42
+ return worker(uri, token, languageService => {
43
+ return languageService.getFoldingRanges(uri, token);
38
44
  });
39
45
  });
40
46
  server.connection.languages.onLinkedEditingRange(async (params, token) => {
41
- return worker(params.textDocument.uri, token, service => {
42
- return service.findLinkedEditingRanges(params.textDocument.uri, params.position, token);
47
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
48
+ return worker(uri, token, languageService => {
49
+ return languageService.findLinkedEditingRanges(uri, params.position, token);
43
50
  });
44
51
  });
45
52
  server.connection.onDocumentSymbol(async (params, token) => {
46
- return worker(params.textDocument.uri, token, service => {
47
- return service.findDocumentSymbols(params.textDocument.uri, token);
53
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
54
+ return worker(uri, token, languageService => {
55
+ return languageService.findDocumentSymbols(uri, token);
48
56
  });
49
57
  });
50
58
  server.connection.onDocumentColor(async (params, token) => {
51
- return worker(params.textDocument.uri, token, service => {
52
- return service.findDocumentColors(params.textDocument.uri, token);
59
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
60
+ return worker(uri, token, languageService => {
61
+ return languageService.findDocumentColors(uri, token);
53
62
  });
54
63
  });
55
64
  server.connection.onColorPresentation(async (params, token) => {
56
- return worker(params.textDocument.uri, token, service => {
57
- return service.getColorPresentations(params.textDocument.uri, params.color, params.range, token);
65
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
66
+ return worker(uri, token, languageService => {
67
+ return languageService.getColorPresentations(uri, params.color, params.range, token);
58
68
  });
59
69
  });
60
70
  server.connection.onCompletion(async (params, token) => {
61
- return worker(params.textDocument.uri, token, async (service) => {
71
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
72
+ return worker(uri, token, async (languageService) => {
62
73
  lastCompleteUri = params.textDocument.uri;
63
- lastCompleteLs = service;
64
- const list = await service.doComplete(params.textDocument.uri, params.position, params.context, token);
74
+ lastCompleteLs = languageService;
75
+ const list = await languageService.doComplete(uri, params.position, params.context, token);
65
76
  for (const item of list.items) {
66
77
  fixTextEdit(item);
67
78
  }
@@ -76,18 +87,21 @@ function registerLanguageFeatures(server) {
76
87
  return item;
77
88
  });
78
89
  server.connection.onHover(async (params, token) => {
79
- return worker(params.textDocument.uri, token, service => {
80
- return service.doHover(params.textDocument.uri, params.position, token);
90
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
91
+ return worker(uri, token, languageService => {
92
+ return languageService.doHover(uri, params.position, token);
81
93
  });
82
94
  });
83
95
  server.connection.onSignatureHelp(async (params, token) => {
84
- return worker(params.textDocument.uri, token, service => {
85
- return service.getSignatureHelp(params.textDocument.uri, params.position, params.context, token);
96
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
97
+ return worker(uri, token, languageService => {
98
+ return languageService.getSignatureHelp(uri, params.position, params.context, token);
86
99
  });
87
100
  });
88
101
  server.connection.onPrepareRename(async (params, token) => {
89
- return worker(params.textDocument.uri, token, async (service) => {
90
- const result = await service.prepareRename(params.textDocument.uri, params.position, token);
102
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
103
+ return worker(uri, token, async (languageService) => {
104
+ const result = await languageService.prepareRename(uri, params.position, token);
91
105
  if (result && 'message' in result) {
92
106
  return new vscode.ResponseError(0, result.message);
93
107
  }
@@ -95,23 +109,26 @@ function registerLanguageFeatures(server) {
95
109
  });
96
110
  });
97
111
  server.connection.onRenameRequest(async (params, token) => {
98
- return worker(params.textDocument.uri, token, service => {
99
- return service.doRename(params.textDocument.uri, params.position, params.newName, token);
112
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
113
+ return worker(uri, token, languageService => {
114
+ return languageService.doRename(uri, params.position, params.newName, token);
100
115
  });
101
116
  });
102
117
  server.connection.onCodeLens(async (params, token) => {
103
- return worker(params.textDocument.uri, token, async (service) => {
104
- lastCodeLensLs = service;
105
- return service.doCodeLens(params.textDocument.uri, token);
118
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
119
+ return worker(uri, token, async (languageService) => {
120
+ lastCodeLensLs = languageService;
121
+ return languageService.doCodeLens(uri, token);
106
122
  });
107
123
  });
108
124
  server.connection.onCodeLensResolve(async (codeLens, token) => {
109
125
  return await lastCodeLensLs?.doCodeLensResolve(codeLens, token) ?? codeLens;
110
126
  });
111
127
  server.connection.onCodeAction(async (params, token) => {
112
- return worker(params.textDocument.uri, token, async (service) => {
113
- lastCodeActionLs = service;
114
- let codeActions = await service.doCodeActions(params.textDocument.uri, params.range, params.context, token) ?? [];
128
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
129
+ return worker(uri, token, async (languageService) => {
130
+ lastCodeActionLs = languageService;
131
+ let codeActions = await languageService.doCodeActions(uri, params.range, params.context, token) ?? [];
115
132
  for (const codeAction of codeActions) {
116
133
  if (codeAction.data && typeof codeAction.data === 'object') {
117
134
  codeAction.data.uri = params.textDocument.uri;
@@ -130,39 +147,46 @@ function registerLanguageFeatures(server) {
130
147
  return await lastCodeActionLs.doCodeActionResolve(codeAction, token) ?? codeAction;
131
148
  });
132
149
  server.connection.onReferences(async (params, token) => {
133
- return worker(params.textDocument.uri, token, service => {
134
- return service.findReferences(params.textDocument.uri, params.position, { includeDeclaration: true }, token);
150
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
151
+ return worker(uri, token, languageService => {
152
+ return languageService.findReferences(uri, params.position, { includeDeclaration: true }, token);
135
153
  });
136
154
  });
137
155
  server.connection.onRequest(protocol_1.FindFileReferenceRequest.type, async (params, token) => {
138
- return worker(params.textDocument.uri, token, service => {
139
- return service.findFileReferences(params.textDocument.uri, token);
156
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
157
+ return worker(uri, token, languageService => {
158
+ return languageService.findFileReferences(uri, token);
140
159
  });
141
160
  });
142
161
  server.connection.onImplementation(async (params, token) => {
143
- return worker(params.textDocument.uri, token, service => {
144
- return service.findImplementations(params.textDocument.uri, params.position, token);
162
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
163
+ return worker(uri, token, languageService => {
164
+ return languageService.findImplementations(uri, params.position, token);
145
165
  });
146
166
  });
147
167
  server.connection.onDefinition(async (params, token) => {
148
- return worker(params.textDocument.uri, token, service => {
149
- return service.findDefinition(params.textDocument.uri, params.position, token);
168
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
169
+ return worker(uri, token, languageService => {
170
+ return languageService.findDefinition(uri, params.position, token);
150
171
  });
151
172
  });
152
173
  server.connection.onTypeDefinition(async (params, token) => {
153
- return worker(params.textDocument.uri, token, service => {
154
- return service.findTypeDefinition(params.textDocument.uri, params.position, token);
174
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
175
+ return worker(uri, token, languageService => {
176
+ return languageService.findTypeDefinition(uri, params.position, token);
155
177
  });
156
178
  });
157
179
  server.connection.onDocumentHighlight(async (params, token) => {
158
- return worker(params.textDocument.uri, token, service => {
159
- return service.findDocumentHighlights(params.textDocument.uri, params.position, token);
180
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
181
+ return worker(uri, token, languageService => {
182
+ return languageService.findDocumentHighlights(uri, params.position, token);
160
183
  });
161
184
  });
162
185
  server.connection.onDocumentLinks(async (params, token) => {
163
- return await worker(params.textDocument.uri, token, service => {
164
- lastDocumentLinkLs = service;
165
- return service.findDocumentLinks(params.textDocument.uri, token);
186
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
187
+ return await worker(uri, token, languageService => {
188
+ lastDocumentLinkLs = languageService;
189
+ return languageService.findDocumentLinks(uri, token);
166
190
  });
167
191
  });
168
192
  server.connection.onDocumentLinkResolve(async (link, token) => {
@@ -170,18 +194,19 @@ function registerLanguageFeatures(server) {
170
194
  });
171
195
  server.connection.onWorkspaceSymbol(async (params, token) => {
172
196
  let results = [];
173
- for (const project of await server.projects.all.call(server)) {
197
+ for (const languageService of await server.project.getExistingLanguageServices(server)) {
174
198
  if (token.isCancellationRequested) {
175
199
  return;
176
200
  }
177
- results = results.concat(await project.getLanguageService().findWorkspaceSymbols(params.query, token));
201
+ results = results.concat(await languageService.findWorkspaceSymbols(params.query, token));
178
202
  }
179
203
  return results;
180
204
  });
181
205
  server.connection.languages.callHierarchy.onPrepare(async (params, token) => {
182
- return await worker(params.textDocument.uri, token, async (service) => {
183
- lastCallHierarchyLs = service;
184
- return service.callHierarchy.doPrepare(params.textDocument.uri, params.position, token);
206
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
207
+ return await worker(uri, token, async (languageService) => {
208
+ lastCallHierarchyLs = languageService;
209
+ return languageService.callHierarchy.doPrepare(uri, params.position, token);
185
210
  }) ?? [];
186
211
  });
187
212
  server.connection.languages.callHierarchy.onIncomingCalls(async (params, token) => {
@@ -191,18 +216,21 @@ function registerLanguageFeatures(server) {
191
216
  return await lastCallHierarchyLs?.callHierarchy.getOutgoingCalls(params.item, token) ?? [];
192
217
  });
193
218
  server.connection.languages.semanticTokens.on(async (params, token, _, resultProgress) => {
194
- return await worker(params.textDocument.uri, token, async (service) => {
195
- return await service?.getSemanticTokens(params.textDocument.uri, undefined, server.semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
219
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
220
+ return await worker(uri, token, async (languageService) => {
221
+ return await languageService?.getSemanticTokens(uri, undefined, server.initializeResult.capabilities.semanticTokensProvider.legend, token, tokens => resultProgress?.report(tokens));
196
222
  }) ?? { data: [] };
197
223
  });
198
224
  server.connection.languages.semanticTokens.onRange(async (params, token, _, resultProgress) => {
199
- return await worker(params.textDocument.uri, token, async (service) => {
200
- return await service?.getSemanticTokens(params.textDocument.uri, params.range, server.semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
225
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
226
+ return await worker(uri, token, async (languageService) => {
227
+ return await languageService?.getSemanticTokens(uri, params.range, server.initializeResult.capabilities.semanticTokensProvider.legend, token, tokens => resultProgress?.report(tokens));
201
228
  }) ?? { data: [] };
202
229
  });
203
230
  server.connection.languages.diagnostics.on(async (params, token, _workDoneProgressReporter, resultProgressReporter) => {
204
- const result = await worker(params.textDocument.uri, token, service => {
205
- return service.doValidation(params.textDocument.uri, token, errors => {
231
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
232
+ const result = await worker(uri, token, languageService => {
233
+ return languageService.doValidation(uri, token, errors => {
206
234
  // resultProgressReporter is undefined in vscode
207
235
  resultProgressReporter?.report({
208
236
  relatedDocuments: {
@@ -220,9 +248,10 @@ function registerLanguageFeatures(server) {
220
248
  };
221
249
  });
222
250
  server.connection.languages.inlayHint.on(async (params, token) => {
223
- return worker(params.textDocument.uri, token, async (service) => {
224
- lastInlayHintLs = service;
225
- return service.getInlayHints(params.textDocument.uri, params.range, token);
251
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
252
+ return worker(uri, token, async (languageService) => {
253
+ lastInlayHintLs = languageService;
254
+ return languageService.getInlayHints(uri, params.range, token);
226
255
  });
227
256
  });
228
257
  server.connection.languages.inlayHint.resolve(async (hint, token) => {
@@ -230,8 +259,10 @@ function registerLanguageFeatures(server) {
230
259
  });
231
260
  server.connection.workspace.onWillRenameFiles(async (params, token) => {
232
261
  const _edits = await Promise.all(params.files.map(async (file) => {
233
- return await worker(file.oldUri, token, service => {
234
- return service.getEditsForFileRename(file.oldUri, file.newUri, token) ?? null;
262
+ const oldUri = vscode_uri_1.URI.parse(file.oldUri);
263
+ const newUri = vscode_uri_1.URI.parse(file.newUri);
264
+ return await worker(oldUri, token, languageService => {
265
+ return languageService.getEditsForFileRename(oldUri, newUri, token) ?? null;
235
266
  }) ?? null;
236
267
  }));
237
268
  const edits = _edits.filter((edit) => !!edit);
@@ -242,8 +273,9 @@ function registerLanguageFeatures(server) {
242
273
  return null;
243
274
  });
244
275
  server.connection.onRequest(protocol_1.AutoInsertRequest.type, async (params, token) => {
245
- return worker(params.textDocument.uri, token, service => {
246
- return service.doAutoInsert(params.textDocument.uri, params.selection, params.change, token);
276
+ const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
277
+ return worker(uri, token, languageService => {
278
+ return languageService.doAutoInsert(uri, params.selection, params.change, token);
247
279
  });
248
280
  });
249
281
  function worker(uri, token, cb) {
@@ -254,19 +286,13 @@ function registerLanguageFeatures(server) {
254
286
  resolve(undefined);
255
287
  return;
256
288
  }
257
- const languageService = (await server.projects.get.call(server, uri)).getLanguageService();
258
- try { // handle TS cancel throw
259
- const result = await cb(languageService);
260
- if (token.isCancellationRequested) {
261
- resolve(undefined);
262
- return;
263
- }
264
- resolve(result);
265
- }
266
- catch {
289
+ const languageService = (await server.project.getLanguageService(server, uri));
290
+ const result = await cb(languageService);
291
+ if (token.isCancellationRequested) {
267
292
  resolve(undefined);
268
293
  return;
269
294
  }
295
+ resolve(result);
270
296
  }, 0);
271
297
  });
272
298
  }
@@ -1 +1,2 @@
1
- export default function handler(uri: string): Promise<string | undefined>;
1
+ import type { URI } from 'vscode-uri';
2
+ export default function handler(uri: URI): Promise<string | undefined>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const request_light_1 = require("request-light");
4
4
  function handler(uri) {
5
5
  const headers = { 'Accept-Encoding': 'gzip, deflate' };
6
- return (0, request_light_1.xhr)({ url: uri, followRedirects: 5, headers }).then(response => {
6
+ return (0, request_light_1.xhr)({ url: uri.toString(true), followRedirects: 5, headers }).then(response => {
7
7
  if (response.status !== 200) {
8
8
  return;
9
9
  }
package/lib/server.d.ts CHANGED
@@ -2,35 +2,22 @@ import { FileSystem, LanguageServicePlugin } from '@volar/language-service';
2
2
  import { SnapshotDocument } from '@volar/snapshot-document';
3
3
  import * as vscode from 'vscode-languageserver';
4
4
  import { URI } from 'vscode-uri';
5
- import type { InitializationOptions, ServerProjectProvider, VolarInitializeParams } from './types.js';
6
- import { UriConverter } from './uri.js';
5
+ import type { Project, VolarInitializeResult } from './types.js';
7
6
  export * from '@volar/snapshot-document';
8
- export declare function createServerBase(connection: vscode.Connection, getFs: (options: InitializationOptions, uriConverter: UriConverter) => FileSystem): {
7
+ export declare function createServerBase(connection: vscode.Connection, fs: FileSystem): {
9
8
  connection: vscode.Connection;
10
- initializeParams: VolarInitializeParams;
11
- languageServicePlugins: LanguageServicePlugin<any>[];
12
- projects: ServerProjectProvider;
13
9
  fs: FileSystem;
14
- semanticTokensLegend: vscode.SemanticTokensLegend;
10
+ initializeParams: vscode.InitializeParams;
11
+ initializeResult: VolarInitializeResult;
12
+ languageServicePlugins: LanguageServicePlugin<any>[];
13
+ project: Project;
15
14
  pullModelDiagnostics: boolean;
16
15
  documents: vscode.TextDocuments<SnapshotDocument>;
17
- uriConverter: {
18
- uriToFileName: (uri: string, parsed?: URI | undefined) => string;
19
- fileNameToUri: (fileName: string) => string;
20
- };
21
- workspaceFolders: {
22
- clear: () => void;
23
- values: () => IterableIterator<boolean>;
24
- keys: () => Generator<URI, void, unknown>;
25
- delete: (uri: URI) => boolean;
26
- get: (uri: URI) => boolean | undefined;
27
- has: (uri: URI) => boolean;
28
- set: (uri: URI, item: boolean) => Map<string, boolean>;
29
- };
30
- initialize: (initializeParams: VolarInitializeParams, languageServicePlugins: LanguageServicePlugin[], projects: ServerProjectProvider, options?: {
31
- semanticTokensLegend?: vscode.SemanticTokensLegend;
16
+ workspaceFolders: Map<URI, boolean>;
17
+ getSyncedDocumentKey: (uri: URI) => string | undefined;
18
+ initialize: (initializeParams: vscode.InitializeParams, languageServicePlugins: LanguageServicePlugin[], languageServices: Project, options?: {
32
19
  pullModelDiagnostics?: boolean;
33
- }) => vscode.InitializeResult<any>;
20
+ }) => VolarInitializeResult;
34
21
  initialized: () => void;
35
22
  shutdown: () => Promise<void>;
36
23
  watchFiles: (patterns: string[]) => void;
@@ -42,5 +29,5 @@ export declare function createServerBase(connection: vscode.Connection, getFs: (
42
29
  dispose: () => void;
43
30
  };
44
31
  clearPushDiagnostics: () => void;
45
- refresh: (projects: ServerProjectProvider) => Promise<void>;
32
+ refresh: (projects: Project) => Promise<void>;
46
33
  };