mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(lsp): show notification with empty hover response (#35014)
This commit is contained in:

committed by
GitHub

parent
2495015455
commit
c3991b8ef4
@@ -61,20 +61,33 @@ function M.hover(config)
|
|||||||
|
|
||||||
-- Filter errors from results
|
-- Filter errors from results
|
||||||
local results1 = {} --- @type table<integer,lsp.Hover>
|
local results1 = {} --- @type table<integer,lsp.Hover>
|
||||||
|
local empty_response = false
|
||||||
|
|
||||||
for client_id, resp in pairs(results) do
|
for client_id, resp in pairs(results) do
|
||||||
local err, result = resp.err, resp.result
|
local err, result = resp.err, resp.result
|
||||||
if err then
|
if err then
|
||||||
lsp.log.error(err.code, err.message)
|
lsp.log.error(err.code, err.message)
|
||||||
elseif result then
|
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
|
results1[client_id] = result
|
||||||
|
else
|
||||||
|
empty_response = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(results1) then
|
if vim.tbl_isempty(results1) then
|
||||||
if config.silent ~= true then
|
if config.silent ~= true then
|
||||||
|
if empty_response then
|
||||||
|
vim.notify('Empty hover response', vim.log.levels.INFO)
|
||||||
|
else
|
||||||
vim.notify('No information available', vim.log.levels.INFO)
|
vim.notify('No information available', vim.log.levels.INFO)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -7110,4 +7110,31 @@ describe('LSP', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
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)
|
end)
|
||||||
|
Reference in New Issue
Block a user