@volar/language-server 1.4.0-alpha.8 → 1.4.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.
@@ -11,6 +11,8 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
11
11
  let lastCodeLensLs;
12
12
  let lastCodeActionLs;
13
13
  let lastCallHierarchyLs;
14
+ let lastDocumentLinkLs;
15
+ let lastInlayHintLs;
14
16
  connection.onDocumentFormatting(async (params, token) => {
15
17
  return worker(params.textDocument.uri, token, service => {
16
18
  return service.format(params.textDocument.uri, params.options, undefined, undefined, token);
@@ -180,9 +182,13 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
180
182
  });
181
183
  connection.onDocumentLinks(async (params, token) => {
182
184
  return await worker(params.textDocument.uri, token, service => {
185
+ lastDocumentLinkLs = service;
183
186
  return service.findDocumentLinks(params.textDocument.uri, token);
184
187
  });
185
188
  });
189
+ connection.onDocumentLinkResolve(async (link, token) => {
190
+ return await lastDocumentLinkLs.doDocumentLinkResolve(link, token);
191
+ });
186
192
  connection.onWorkspaceSymbol(async (params, token) => {
187
193
  let results = [];
188
194
  for (const _workspace of projects.workspaces.values()) {
@@ -247,15 +253,14 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
247
253
  });
248
254
  connection.languages.inlayHint.on(async (params, token) => {
249
255
  return worker(params.textDocument.uri, token, async (service) => {
256
+ lastInlayHintLs = service;
250
257
  return service.getInlayHints(params.textDocument.uri, params.range, token);
251
258
  });
252
259
  });
253
- // TODO: connection.languages.inlayHint.resolve
260
+ connection.languages.inlayHint.resolve(async (hint, token) => {
261
+ return await lastInlayHintLs.doInlayHintResolve(hint, token);
262
+ });
254
263
  connection.workspace.onWillRenameFiles(async (params, token) => {
255
- const config = await connection.workspace.getConfiguration('volar.updateImportsOnFileMove.enabled');
256
- if (!config) {
257
- return null;
258
- }
259
264
  const _edits = await Promise.all(params.files.map(async (file) => {
260
265
  return await worker(file.oldUri, token, service => {
261
266
  return service.getEditsForFileRename(file.oldUri, file.newUri, token) ?? null;
@@ -12,7 +12,7 @@ export interface ProjectContext {
12
12
  }
13
13
  export type Project = ReturnType<typeof createProject>;
14
14
  export declare function createProject(context: ProjectContext): Promise<{
15
- tsConfig: ts.CompilerOptions | path.PosixPath;
15
+ tsConfig: path.PosixPath | ts.CompilerOptions;
16
16
  scripts: {
17
17
  clear: () => void;
18
18
  values: () => IterableIterator<{
@@ -71,7 +71,7 @@ export declare function createProject(context: ProjectContext): Promise<{
71
71
  findDocumentSymbols: (uri: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.DocumentSymbol[] | undefined>;
72
72
  findDocumentColors: (uri: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.ColorInformation[] | undefined>;
73
73
  getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.ColorPresentation[] | undefined>;
74
- doValidation: (uri: string, mode: "all" | "semantic" | "syntactic", token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
74
+ doValidation: (uri: string, mode: "semantic" | "all" | "syntactic", token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
75
75
  findReferences: (uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.Location[] | undefined>;
76
76
  findFileReferences: (uri: string, token?: embeddedLS.CancellationToken | undefined) => embeddedLS.NullableResult<embeddedLS.Location[]>;
77
77
  findDefinition: (uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.LocationLink[] | undefined>;
@@ -91,9 +91,11 @@ export declare function createProject(context: ProjectContext): Promise<{
91
91
  doCodeLensResolve: (item: embeddedLS.CodeLens, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.CodeLens>;
92
92
  findDocumentHighlights: (uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.DocumentHighlight[] | undefined>;
93
93
  findDocumentLinks: (uri: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.DocumentLink[]>;
94
+ doDocumentLinkResolve: (item: embeddedLS.CodeLens, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.CodeLens>;
94
95
  findWorkspaceSymbols: (query: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.WorkspaceSymbol[]>;
95
96
  doAutoInsert: (uri: string, position: embeddedLS.Position, autoInsertContext: embeddedLS.AutoInsertionContext, token?: embeddedLS.CancellationToken | undefined) => Promise<NonNullable<string | embeddedLS.TextEdit | null | undefined> | undefined>;
96
97
  getInlayHints: (uri: string, range: embeddedLS.Range, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.InlayHint[] | undefined>;
98
+ doInlayHintResolve: (item: embeddedLS.InlayHint, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.InlayHint>;
97
99
  callHierarchy: {
98
100
  doPrepare(uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined): Promise<embeddedLS.CallHierarchyItem[] | undefined>;
99
101
  getIncomingCalls(item: embeddedLS.CallHierarchyItem, token: embeddedLS.CancellationToken): Promise<embeddedLS.CallHierarchyIncomingCall[]>;
@@ -117,7 +119,7 @@ export declare function createProject(context: ProjectContext): Promise<{
117
119
  findDocumentSymbols: (uri: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.DocumentSymbol[] | undefined>;
118
120
  findDocumentColors: (uri: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.ColorInformation[] | undefined>;
119
121
  getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.ColorPresentation[] | undefined>;
120
- doValidation: (uri: string, mode: "all" | "semantic" | "syntactic", token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
122
+ doValidation: (uri: string, mode: "semantic" | "all" | "syntactic", token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
121
123
  findReferences: (uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.Location[] | undefined>;
122
124
  findFileReferences: (uri: string, token?: embeddedLS.CancellationToken | undefined) => embeddedLS.NullableResult<embeddedLS.Location[]>;
123
125
  findDefinition: (uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.LocationLink[] | undefined>;
@@ -137,9 +139,11 @@ export declare function createProject(context: ProjectContext): Promise<{
137
139
  doCodeLensResolve: (item: embeddedLS.CodeLens, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.CodeLens>;
138
140
  findDocumentHighlights: (uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.DocumentHighlight[] | undefined>;
139
141
  findDocumentLinks: (uri: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.DocumentLink[]>;
142
+ doDocumentLinkResolve: (item: embeddedLS.CodeLens, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.CodeLens>;
140
143
  findWorkspaceSymbols: (query: string, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.WorkspaceSymbol[]>;
141
144
  doAutoInsert: (uri: string, position: embeddedLS.Position, autoInsertContext: embeddedLS.AutoInsertionContext, token?: embeddedLS.CancellationToken | undefined) => Promise<NonNullable<string | embeddedLS.TextEdit | null | undefined> | undefined>;
142
145
  getInlayHints: (uri: string, range: embeddedLS.Range, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.InlayHint[] | undefined>;
146
+ doInlayHintResolve: (item: embeddedLS.InlayHint, token?: embeddedLS.CancellationToken | undefined) => Promise<embeddedLS.InlayHint>;
143
147
  callHierarchy: {
144
148
  doPrepare(uri: string, position: embeddedLS.Position, token?: embeddedLS.CancellationToken | undefined): Promise<embeddedLS.CallHierarchyItem[] | undefined>;
145
149
  getIncomingCalls(item: embeddedLS.CallHierarchyItem, token: embeddedLS.CancellationToken): Promise<embeddedLS.CallHierarchyIncomingCall[]>;
@@ -57,11 +57,9 @@ async function createProject(context) {
57
57
  if (!languageService) {
58
58
  let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.workspace.rootUri.path, context.workspace.workspaces.initOptions.configFilePath) : {}) ?? {};
59
59
  const options = {
60
+ modules: { typescript: context.workspace.workspaces.ts },
60
61
  uriToFileName,
61
62
  fileNameToUri,
62
- getOpenedTextDocumentLanguageId: uri => {
63
- return context.workspace.workspaces.documents.data.uriGet(uri)?.languageId;
64
- },
65
63
  locale: context.workspace.workspaces.initParams.locale,
66
64
  rootUri: context.rootUri,
67
65
  capabilities: context.workspace.workspaces.initParams.capabilities,
@@ -90,7 +88,7 @@ async function createProject(context) {
90
88
  };
91
89
  for (const plugin of context.workspace.workspaces.plugins) {
92
90
  if (plugin.resolveConfig) {
93
- config = plugin.resolveConfig(config, { typescript: lsCtx.project.workspace.workspaces.ts }, lsCtx);
91
+ config = plugin.resolveConfig(config, lsCtx);
94
92
  }
95
93
  }
96
94
  languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
@@ -170,9 +168,6 @@ async function createProject(context) {
170
168
  getCompilationSettings: () => parsedCommandLine.options,
171
169
  getScriptVersion,
172
170
  getScriptSnapshot,
173
- getTypeScriptModule: context.workspace.workspaces.ts ? () => {
174
- return context.workspace.workspaces.ts;
175
- } : undefined,
176
171
  getScriptLanguageId: (fileName) => {
177
172
  return context.workspace.workspaces.documents.data.pathGet(fileName)?.languageId;
178
173
  },
@@ -300,10 +295,7 @@ function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
300
295
  return ref;
301
296
  }
302
297
  if (ref[0] === '/') { // resolve absolute path against the current workspace folder
303
- const folderUri = rootUri;
304
- if (folderUri) {
305
- return folderUri + ref.substr(1);
306
- }
298
+ return rootUri + ref;
307
299
  }
308
300
  const baseUri = vscode_uri_1.URI.parse(base);
309
301
  const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
@@ -26,7 +26,9 @@ function startCommonLanguageServer(connection, getCtx) {
26
26
  initParams = _params;
27
27
  options = initParams.initializationOptions;
28
28
  context = getCtx(options);
29
- plugins = context.plugins.map(plugin => plugin(options));
29
+ plugins = context.plugins.map(plugin => plugin(options, {
30
+ typescript: options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined
31
+ }));
30
32
  documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
31
33
  if (options.l10n) {
32
34
  await l10n.config({ uri: options.l10n.location });
@@ -54,13 +56,12 @@ function startCommonLanguageServer(connection, getCtx) {
54
56
  };
55
57
  configurationHost = initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
56
58
  let lsPlugins = {};
57
- const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
58
59
  for (const root of roots) {
59
60
  if (root.scheme === 'file') {
60
61
  let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
61
62
  for (const plugin of plugins) {
62
63
  if (plugin.resolveConfig) {
63
- config = plugin.resolveConfig(config, { typescript: ts });
64
+ config = plugin.resolveConfig(config, undefined);
64
65
  }
65
66
  }
66
67
  if (config.plugins) {
@@ -98,7 +99,6 @@ function startCommonLanguageServer(connection, getCtx) {
98
99
  });
99
100
  }
100
101
  if (options.serverMode !== types_1.ServerMode.Syntactic
101
- && !options.disableFileWatcher
102
102
  && initParams.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration) {
103
103
  const exts = plugins.map(plugin => plugin.watchFileExtensions).flat();
104
104
  if (exts.length) {
@@ -48,7 +48,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
48
48
  }
49
49
  server.documentHighlightProvider = true;
50
50
  server.documentLinkProvider = {
51
- resolveProvider: false, // TODO
51
+ resolveProvider: true,
52
52
  };
53
53
  server.codeLensProvider = {
54
54
  resolveProvider: true,
@@ -72,7 +72,9 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
72
72
  ],
73
73
  resolveProvider: true,
74
74
  };
75
- server.inlayHintProvider = true;
75
+ server.inlayHintProvider = {
76
+ resolveProvider: true,
77
+ };
76
78
  const exts = plugins.map(plugin => plugin.watchFileExtensions).flat();
77
79
  if (exts.length) {
78
80
  server.workspace = {