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

@@ -57,10 +57,23 @@ local function check_active_clients()
end
dirs_info = ('- Workspace folders:\n %s'):format(table.concat(wfolders, '\n '))
else
local root_dirs = {} ---@type table<string, boolean>
local timeout = 1
local timeoutmsg = ('root_dir() took > %ds'):format(timeout)
for buf, _ in pairs(client.attached_buffers) do
local dir = client._resolve_root_dir(1000, buf, client.root_dir)
root_dirs[dir or timeoutmsg] = true
end
dirs_info = string.format(
'- Root directory: %s',
client.root_dir and vim.fn.fnamemodify(client.root_dir, ':~')
) or nil
'- Root %s:\n %s',
vim.tbl_count(root_dirs) > 1 and 'directories' or 'directory',
vim
.iter(root_dirs)
:map(function(k, _)
return k == timeoutmsg and timeoutmsg or vim.fn.fnamemodify(k, ':~')
end)
:join('\n ')
)
end
report_info(table.concat({
string.format('%s (id: %d)', client.name, client.id),