more updates for nvim 0.10 nightly

pull/296/head
ray-x 5 months ago
parent 4dbf5e1ef3
commit 40d1907f57

@ -491,11 +491,6 @@ function M.setup(attach_opts)
if hassig then
sig.setup(_NgConfigValues.signature_help_cfg or {})
end
else
vim.lsp.handlers['textDocument/signatureHelp'] =
vim.lsp.with(require('navigator.signature').signature_handler, {
border = { '', '', '', '', '', '', '', '' },
})
end
api.nvim_create_autocmd({ 'BufWritePre' }, {
@ -511,11 +506,11 @@ function M.setup(attach_opts)
if _NgConfigValues.border == 'double' then
border_style = double
end
if _NgConfigValues.lsp.hover then
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(require('navigator.hover').handler, {
border = border_style,
})
end
-- if _NgConfigValues.lsp.hover then
-- vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(require('navigator.hover').handler, {
-- border = border_style,
-- })
-- end
if cap.documentFormattingProvider then
log('formatting enabled setup hdl')
vim.lsp.handlers['textDocument/formatting'] = require('navigator.formatting').format_hdl

@ -1,69 +0,0 @@
local util = require "navigator.util"
local log = util.log
--- navigator signature
local match_parameter = function(result)
local signatures = result.signatures
if #signatures < 1 then
return result
end
local signature = signatures[1]
local activeParameter = result.activeParameter or signature.activeParameter
if activeParameter == nil then
return result
end
if signature.parameters == nil then
return
end
if #signature.parameters < 2 or activeParameter + 1 > #signature.parameters then
return result
end
local nextParameter = signature.parameters[activeParameter + 1]
local label = signature.label
if type(nextParameter.label) == "table" then -- label = {2, 4} c style
local range = nextParameter.label
label = label:sub(1, range[1]) .. [[`]] .. label:sub(range[1] + 1, range[2]) .. [[`]]
.. label:sub(range[2] + 1, #label + 1)
signature.label = label
else
if type(nextParameter.label) == "string" then -- label = 'par1 int'
local i, j = label:find(nextParameter.label, 1, true)
if i ~= nil then
label = label:sub(1, i - 1) .. [[`]] .. label:sub(i, j) .. [[`]] .. label:sub(j + 1, #label + 1)
signature.label = label
end
end
end
end
local signature_handler = function(err, result, ctx, config)
if config == nil then
log("config nil")
end
if err then
vim.notify("signature help error: ".. vim.inspect(err) .. vim.inspect(result), ctx, config, vim.log.levels.WARN)
end
config = config or {}
if config.border == nil then
config.border = _NgConfigValues.border
end
if not (result and result.signatures and result.signatures[1]) then
return
end
match_parameter(result)
local lines = vim.lsp.util.convert_signature_help_to_markdown_lines(result)
if vim.tbl_isempty(lines) then
return
end
local syntax = vim.lsp.util.try_trim_markdown_code_blocks(lines)
config.focus_id = ctx.bufnr .. "lsp_signature"
vim.lsp.util.open_floating_preview(lines, syntax, config)
end
return {signature_handler = signature_handler}

@ -563,4 +563,36 @@ function M.sub_match(str)
return str
end
function M.try_trim_markdown_code_blocks(lines)
local language_id = lines[1]:match('^```(.*)')
if language_id then
local has_inner_code_fence = false
for i = 2, (#lines - 1) do
local line = lines[i]
if line:sub(1, 3) == '```' then
has_inner_code_fence = true
break
end
end
-- No inner code fences + starting with code fence = hooray.
if not has_inner_code_fence then
table.remove(lines, 1)
table.remove(lines)
return language_id
end
end
return 'markdown'
end
function M.trim_empty_lines(lines)
local new_list = {}
for i, str in ipairs(lines) do
if str ~= '' and str then
table.insert(new_list, str)
end
end
return new_list
end
return M

Loading…
Cancel
Save