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:
Justin M. Keyes
2025-10-11 21:25:54 -04:00
committed by GitHub
parent 4e4428dee8
commit 21540d21ca
5 changed files with 151 additions and 10 deletions

View File

@@ -54,7 +54,7 @@ function lsp._unsupported_method(method)
end
---@private
---@param workspace_folders string|lsp.WorkspaceFolder[]?
---@param workspace_folders string|lsp.WorkspaceFolder[]|fun(bufnr: integer, on_dir:fun(root_dir?:string))?
---@return lsp.WorkspaceFolder[]?
function lsp._get_workspace_folders(workspace_folders)
if type(workspace_folders) == 'table' then
@@ -66,6 +66,15 @@ function lsp._get_workspace_folders(workspace_folders)
name = workspace_folders,
},
}
elseif type(workspace_folders) == 'function' then
local name = lsp.client._resolve_root_dir(1000, 0, workspace_folders)
return name
and {
{
uri = vim.uri_from_fname(name),
name = name,
},
}
end
end