You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
navigator.lua/lua/navigator/hover.lua

42 lines
1.1 KiB
Lua

local lsp = vim.lsp
local util = lsp.util
local nutils = require('navigator.util')
local api = vim.api
local log = nutils.log
local M = {}
function M.handler(err, result, ctx, config)
config = config or {}
config.focus_id = ctx.method
if err then
return vim.notify('no hover info ' .. err)
end
if api.nvim_get_current_buf() ~= ctx.bufnr then
-- Ignore result since buffer changed. This happens for slow language servers.
return
end
if not (result and result.contents) then
if config.silent ~= true then
vim.notify('No hover information available')
end
return
end
local format = 'markdown'
local contents ---@type string[]
if type(result.contents) == 'table' and result.contents.kind == 'plaintext' then
format = 'plaintext'
contents = vim.split(result.contents.value or '', '\n', { trimempty = true })
else
contents = util.convert_input_to_markdown_lines(result.contents)
end
if vim.tbl_isempty(contents) then
if config.silent ~= true then
vim.notify('No information available')
end
return
end
return util.open_floating_preview(contents, format, config)
end
return M