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