neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit c3991b8ef4f086b479ae3bc0f65aecaa07271a0a
parent 2495015455f74d3e4f0cce8023941deddf0be189
Author: Maria José Solano <majosolano99@gmail.com>
Date:   Sun, 20 Jul 2025 13:58:40 -0700

fix(lsp): show notification with empty hover response (#35014)


Diffstat:
Mruntime/lua/vim/lsp/buf.lua | 19++++++++++++++++---
Mtest/functional/plugin/lsp_spec.lua | 27+++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua @@ -61,19 +61,32 @@ function M.hover(config) -- Filter errors from results local results1 = {} --- @type table<integer,lsp.Hover> + local empty_response = false for client_id, resp in pairs(results) do local err, result = resp.err, resp.result if err then lsp.log.error(err.code, err.message) - elseif result then - results1[client_id] = result + elseif result and result.contents then + -- Make sure the response is not empty + if + (type(result.contents) == 'table' and #(vim.tbl_get(result.contents, 'value') or '') > 0) + or type(result.contents == 'string') and #result.contents > 0 + then + results1[client_id] = result + else + empty_response = true + end end end if vim.tbl_isempty(results1) then if config.silent ~= true then - vim.notify('No information available', vim.log.levels.INFO) + if empty_response then + vim.notify('Empty hover response', vim.log.levels.INFO) + else + vim.notify('No information available', vim.log.levels.INFO) + end end return end diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua @@ -7110,4 +7110,31 @@ describe('LSP', function() ) end) end) + + describe('vim.lsp.buf.hover()', function() + it('handles empty contents', function() + exec_lua(create_server_definition) + exec_lua(function() + local server = _G._create_server({ + capabilities = { + hoverProvider = true, + }, + handlers = { + ['textDocument/hover'] = function(_, _, callback) + local res = { + contents = { + kind = 'markdown', + value = '', + }, + } + callback(nil, res) + end, + }, + }) + vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + end) + + eq('Empty hover response', n.exec_capture('lua vim.lsp.buf.hover()')) + end) + end) end)