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.pull/296/head
parent
98540ed2a8
commit
f6b208a24c
@ -1,59 +1,42 @@
|
|||||||
local lsp = vim.lsp
|
local lsp = vim.lsp
|
||||||
local util = lsp.util
|
local util = lsp.util
|
||||||
local nutils = require('navigator.util')
|
local nutils = require('navigator.util')
|
||||||
|
local api = vim.api
|
||||||
local log = nutils.log
|
local log = nutils.log
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.handler(_, result, ctx, config)
|
function M.handler(_, result, ctx, config)
|
||||||
config = config or {}
|
config = config or {}
|
||||||
config.focus_id = ctx.method
|
config.focus_id = ctx.method
|
||||||
config.zindex = 53
|
if api.nvim_get_current_buf() ~= ctx.bufnr then
|
||||||
if not (result and result.contents) then
|
-- Ignore result since buffer changed. This happens for slow language servers.
|
||||||
-- vim.notify('No information available')
|
|
||||||
vim.schedule(function()
|
|
||||||
vim.lsp.buf.signature_help()
|
|
||||||
end)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local ft = vim.bo.ft
|
if not (result and result.contents) then
|
||||||
-- require('navigator.util').log(result)
|
if config.silent ~= true then
|
||||||
local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
|
vim.notify('No information available')
|
||||||
markdown_lines = nutils.trim_empty_lines(markdown_lines)
|
end
|
||||||
if vim.tbl_isempty(markdown_lines) then
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
-- fallback to signature help
|
||||||
vim.lsp.buf.signature_help()
|
vim.lsp.buf.signature_help()
|
||||||
end)
|
end)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local format = 'markdown'
|
||||||
local opts = {}
|
local contents ---@type string[]
|
||||||
opts.wrap = true -- wrapping by default
|
if type(result.contents) == 'table' and result.contents.kind == 'plaintext' then
|
||||||
opts.stylize_markdown = true
|
format = 'plaintext'
|
||||||
opts.focus = true
|
contents = vim.split(result.contents.value or '', '\n', { trimempty = true })
|
||||||
local contents = markdown_lines
|
|
||||||
if vim.fn.has('nvim-0.10') == 0 then
|
|
||||||
contents = util._trim(markdown_lines, opts) -- function removed in 0.10
|
|
||||||
else
|
|
||||||
contents = markdown_lines
|
|
||||||
end
|
|
||||||
|
|
||||||
-- applies the syntax and sets the lines to the buffer
|
|
||||||
local bufnr, winnr = util.open_floating_preview(contents, 'markdown', config)
|
|
||||||
|
|
||||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', true)
|
|
||||||
contents = lsp.util.stylize_markdown(bufnr, contents, opts)
|
|
||||||
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
|
|
||||||
if _NgConfigValues.lsp.hover.keymaps then
|
|
||||||
for key, v in pairs(_NgConfigValues.lsp.hover.keymaps) do
|
|
||||||
if v[ft] == nil or v[ft] == true then
|
|
||||||
local f = v.default or function() end
|
|
||||||
vim.keymap.set('n', key, f, { noremap = true, silent = true, buffer = bufnr })
|
|
||||||
else
|
else
|
||||||
local f = v[ft]
|
contents = util.convert_input_to_markdown_lines(result.contents)
|
||||||
vim.keymap.set('n', key, f, { noremap = true, silent = true, buffer = bufnr })
|
|
||||||
end
|
end
|
||||||
|
if vim.tbl_isempty(contents) then
|
||||||
|
if config.silent ~= true then
|
||||||
|
vim.notify('No information available')
|
||||||
end
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
return bufnr, winnr
|
return util.open_floating_preview(contents, format, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue