mirror of
https://github.com/ray-x/navigator.lua
synced 2024-11-05 12:00:21 +00:00
f6b208a24c
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.
43 lines
1.2 KiB
Lua
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
|