lsp signature (stealed from nvchad/ui)

This commit is contained in:
ant 2025-01-04 18:37:16 +01:00
parent 5c5d33736d
commit 68bf7f530c

View file

@ -58,3 +58,56 @@ vim.diagnostic.config({
-- update_in_insert = false, -- update_in_insert = false,
-- severity_sort = false, -- severity_sort = false,
}) })
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
vim.schedule(function()
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client then
local signatureProvider = client.server_capabilities.signatureHelpProvider
if signatureProvider and signatureProvider.triggerCharacters then
local M = {}
local api = vim.api
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
focusable = false,
silent = true,
max_height = 7,
})
local function check_triggeredChars(triggerChars)
local cur_line = api.nvim_get_current_line()
local pos = api.nvim_win_get_cursor(0)[2]
local prev_char = cur_line:sub(pos - 1, pos - 1)
local cur_char = cur_line:sub(pos, pos)
for _, char in ipairs(triggerChars) do
if cur_char == char or prev_char == char then
return true
end
end
end
M.setup = function(client, bufnr)
local group = api.nvim_create_augroup("LspSignature", { clear = false })
api.nvim_clear_autocmds { group = group, buffer = bufnr }
local triggerChars = client.server_capabilities.signatureHelpProvider.triggerCharacters
api.nvim_create_autocmd("TextChangedI", {
group = group,
buffer = bufnr,
callback = function()
if check_triggeredChars(triggerChars) then
vim.lsp.buf.signature_help()
end
end,
})
end
M.setup(client, args.buf)
end
end
end)
end,
})