If we have multiple providers with hover capability for the same buffer, the hover will ramdonly display one of them (same with vim.lsp.hover).
I found a way to work around this by implementing a custom provider that takes the server_name as argument, using it to both print the title and request textDocument/hover for a single client each time.
The trick was to create and register a new provider on server attach, to be able to split the results while keeping a reference to the name.
Since this happens on on_attach event, I'm not sure it can be easily included in the original code, but it would be nice to have.
Here is the implementation and result:
local util = vim.lsp.util
local get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients
local LSPServerHover = function(server_name)
return {
name = string.format('LSP[%s]', server_name),
priority = 1002, -- above diagnostics
enabled = function(bufnr)
return #get_clients({ bufnr = bufnr, name = server_name, method = 'textDocument/hover' }) > 0
end,
execute = function(opts, done)
local params = util.make_position_params()
local client = get_clients({ bufnr = opts.bufnr, name = server_name, method = 'textDocument/hover' })[1]
client.request('textDocument/hover', params, function(err, result)
if result and result.contents and result.contents.value then
local value = result.contents.value
done({ lines = vim.split(value, '\n', true), filetype = 'markdown' })
else
print(err)
done()
end
end)
end,
}
end
If we have multiple providers with
hover
capability for the same buffer, the hover will ramdonly display one of them (same withvim.lsp.hover
).I found a way to work around this by implementing a custom provider that takes the
server_name
as argument, using it to both print the title and requesttextDocument/hover
for a single client each time. The trick was to create and register a new provider on server attach, to be able to split the results while keeping a reference to the name.Since this happens on
on_attach
event, I'm not sure it can be easily included in the original code, but it would be nice to have.Here is the implementation and result:
https://github.com/paulodiovani/dotfiles/blob/4eb17e19b113b32f3fd6da2c7357d26958056edb/home/user/.config/nvim/lua/completion.lua#L5-L29
Screenshots:
First posted on https://github.com/neovim/nvim-lspconfig/issues/3282#issuecomment-2307786225