mirror of
https://github.com/pnx/dotfiles
synced 2026-06-16 19:30:01 +02:00
nvim: support multiple servers on LSP hover.
This commit is contained in:
parent
3decda3d31
commit
544108ee13
2 changed files with 40 additions and 1 deletions
|
|
@ -105,6 +105,12 @@ vim.diagnostic.config({
|
|||
}
|
||||
})
|
||||
|
||||
|
||||
-- LSP
|
||||
|
||||
-- Provide a custom hover implementation
|
||||
vim.lsp.buf.hover = require("user.utils.lsp").hover
|
||||
|
||||
-------------------------------------------------------
|
||||
-- Extras
|
||||
-------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,6 +1,39 @@
|
|||
|
||||
local M = {}
|
||||
|
||||
-- Hover that supports responses from multiple language servers.
|
||||
function M.hover()
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
|
||||
vim.lsp.buf_request_all(0, 'textDocument/hover', params, function(responses)
|
||||
local sections = {}
|
||||
for _, response in pairs(responses) do
|
||||
if response.result then
|
||||
local result = response.result
|
||||
local section = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
|
||||
sections = vim.list_extend(sections, { section })
|
||||
end
|
||||
end
|
||||
|
||||
local markdown_lines = {}
|
||||
for i, content in ipairs(sections) do
|
||||
markdown_lines = vim.list_extend(markdown_lines, content)
|
||||
if i < #sections then
|
||||
table.insert(markdown_lines, "---")
|
||||
end
|
||||
end
|
||||
|
||||
markdown_lines = table.concat(markdown_lines, "\n")
|
||||
markdown_lines = vim.split(markdown_lines, "\n", { trimempty = true })
|
||||
if vim.tbl_isempty(markdown_lines) then
|
||||
return
|
||||
end
|
||||
|
||||
vim.lsp.util.open_floating_preview(markdown_lines, 'markdown', {
|
||||
focus_id = "lsp_hover"
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
function M.document_highlight(bufnr)
|
||||
local group = vim.api.nvim_create_augroup('lsp_document_highlight', { clear = false })
|
||||
vim.api.nvim_clear_autocmds({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue