fix(lsp): handle nil root_dir in health check (#29007)

The root directory could show up as something like:

    Root directory: ~/path/to/cwd/v:null

Despite being `nil`
This commit is contained in:
Mathias Fußenegger 2024-05-25 21:22:41 +02:00 committed by GitHub
parent 520c2657bb
commit f03b1622ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 4 deletions

View File

@ -996,7 +996,7 @@ Lua module: vim.lsp.client *lsp-client*
if the client supports workspace folders. It if the client supports workspace folders. It
can be `null` if the client supports workspace can be `null` if the client supports workspace
folders but none are configured. folders but none are configured.
• {root_dir} (`string`) • {root_dir} (`string?`)
• {attached_buffers} (`table<integer,true>`) • {attached_buffers} (`table<integer,true>`)
• {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`) • {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`)
Table of command name to function which is Table of command name to function which is

View File

@ -182,7 +182,7 @@ local validate = vim.validate
--- It can be `null` if the client supports workspace folders but none are --- It can be `null` if the client supports workspace folders but none are
--- configured. --- configured.
--- @field workspace_folders lsp.WorkspaceFolder[]? --- @field workspace_folders lsp.WorkspaceFolder[]?
--- @field root_dir string --- @field root_dir string?
--- ---
--- @field attached_buffers table<integer,true> --- @field attached_buffers table<integer,true>
--- ---
@ -470,7 +470,6 @@ function Client.create(config)
_on_exit_cbs = ensure_list(config.on_exit), _on_exit_cbs = ensure_list(config.on_exit),
_on_attach_cbs = ensure_list(config.on_attach), _on_attach_cbs = ensure_list(config.on_attach),
_on_error_cb = config.on_error, _on_error_cb = config.on_error,
_root_dir = config.root_dir,
_trace = get_trace(config.trace), _trace = get_trace(config.trace),
--- Contains $/progress report messages. --- Contains $/progress report messages.

View File

@ -41,7 +41,10 @@ local function check_active_clients()
end end
report_info(table.concat({ report_info(table.concat({
string.format('%s (id: %d)', client.name, client.id), string.format('%s (id: %d)', client.name, client.id),
string.format(' Root directory: %s', vim.fn.fnamemodify(client.root_dir, ':~')), string.format(
' Root directory: %s',
client.root_dir and vim.fn.fnamemodify(client.root_dir, ':~') or nil
),
string.format(' Command: %s', cmd), string.format(' Command: %s', cmd),
string.format(' Settings: %s', vim.inspect(client.settings, { newline = '\n ' })), string.format(' Settings: %s', vim.inspect(client.settings, { newline = '\n ' })),
string.format( string.format(