mirror of
https://github.com/neovim/neovim.git
synced 2025-10-13 05:16:09 +00:00
fix(lsp): _get_workspace_folders does not handle root_dir() function (#36141)
backport #36071 * fix(lsp): type of root_dir should be annotated with string|fun|nil * feat(lsp): support root_dir as function in _get_workspace_folders * feat(lsp): let checkhealth support root_dir() function Examples: vim.lsp: Active Clients ~ - lua_ls (id: 1) - Version: <Unknown> - Root directories: ~/foo/bar ~/dev/neovim Co-authored-by: atusy <30277794+atusy@users.noreply.github.com>
This commit is contained in:
@@ -117,7 +117,7 @@ local validate = vim.validate
|
||||
--- @field on_init? elem_or_list<fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)>
|
||||
---
|
||||
--- Directory where the LSP server will base its workspaceFolders, rootUri, and rootPath on initialization.
|
||||
--- @field root_dir? string
|
||||
--- @field root_dir? string|fun(bufnr: integer, on_dir:fun(root_dir?:string))
|
||||
---
|
||||
--- Map of language server-specific settings, decided by the client. Sent to the LS if requested via
|
||||
--- `workspace/configuration`. Keys are case-sensitive.
|
||||
@@ -190,7 +190,7 @@ local validate = vim.validate
|
||||
--- @field requests table<integer,{ type: string, bufnr: integer, method: string}?>
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field root_dir string?
|
||||
--- @field root_dir? string|fun(bufnr: integer, on_dir:fun(root_dir?:string))
|
||||
---
|
||||
--- RPC client object, for low level interaction with the client.
|
||||
--- See |vim.lsp.rpc.start()|.
|
||||
@@ -1209,4 +1209,25 @@ function Client:_remove_workspace_folder(dir)
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets root_dir, waiting up to `ms_` for a potentially async `root_dir()` result.
|
||||
---
|
||||
--- @param ms_ integer
|
||||
--- @param buf integer
|
||||
--- @return string|nil
|
||||
function Client._resolve_root_dir(ms_, buf, root_dir)
|
||||
if root_dir == nil or type(root_dir) == 'string' then
|
||||
return root_dir --[[@type string|nil]]
|
||||
end
|
||||
|
||||
local dir = nil --[[@type string|nil]]
|
||||
root_dir(buf, function(d)
|
||||
dir = d
|
||||
end)
|
||||
-- root_dir() may be async, wait for a result.
|
||||
vim.wait(ms_, function()
|
||||
return not not dir
|
||||
end)
|
||||
return dir
|
||||
end
|
||||
|
||||
return Client
|
||||
|
Reference in New Issue
Block a user