navigator.lua/lua/navigator/hover.lua
ray-x f6b208a24c put deprecated APIs in lsp/util; I feel for_each_client is a great API to use and no idea why it been deprecated in neovim 0.10
I have a feeling that there will be lots of APIs been changed for each release of neovim. On one side, it shows project is very active; on the flip side it is lack of thinking when API been added.
2023-11-30 23:14:25 +11:00

43 lines
1.2 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(_, result, ctx, config)
config = config or {}
config.focus_id = ctx.method
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 information available')
end
vim.schedule(function()
-- fallback to signature help
vim.lsp.buf.signature_help()
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