Skip to content

Commit 2f47401

Browse files
committed
feat(lsp): Don't show clients with empty diagnostic content in hover
*Problem*: LSP clients that produced no diagnostic results are being shown in the diagnostics hover (e.g. the client name is shown with no results). *Solution*: This PR hides clients with no diagnostic content by default, with a boolean option `keep_empty` added to retain the existing behaviour.
1 parent 43f3c4a commit 2f47401

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

runtime/doc/lsp.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,9 @@ the current buffer.
15791579

15801580

15811581
Fields: ~
1582-
{silent}? (`boolean`)
1582+
{silent}? (`boolean`)
1583+
• {keep_empty}? (`boolean`) Show clients in hover that produced no
1584+
diagnostics.
15831585

15841586
*vim.lsp.buf.signature_help.Opts*
15851587
Extends: |vim.lsp.util.open_floating_preview.Opts|

runtime/lua/vim/lsp/buf.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local hover_ns = api.nvim_create_namespace('nvim.lsp.hover_range')
2727

2828
--- @class vim.lsp.buf.hover.Opts : vim.lsp.util.open_floating_preview.Opts
2929
--- @field silent? boolean
30+
--- @field keep_empty? boolean Show clients in hover that produced no diagnostics.
3031

3132
--- Displays hover information about the symbol under the cursor in a floating
3233
--- window. The window will be dismissed on cursor move.
@@ -61,11 +62,16 @@ function M.hover(config)
6162
local results1 = {} --- @type table<integer,lsp.Hover>
6263

6364
for client_id, resp in pairs(results) do
65+
--- @type lsp.ResponseError, lsp.Hover
6466
local err, result = resp.err, resp.result
6567
if err then
6668
lsp.log.error(err.code, err.message)
6769
elseif result then
68-
results1[client_id] = result
70+
local contents = result.contents
71+
if config.keep_empty == true or
72+
contents.kind or contents.language or contents[1] then
73+
results1[client_id] = result
74+
end
6975
end
7076
end
7177

0 commit comments

Comments
 (0)