Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit fcd91c9

Browse files
committed
simplify signature file
Signed-off-by: Tomas Slusny <[email protected]>
1 parent b573165 commit fcd91c9

File tree

1 file changed

+37
-43
lines changed

1 file changed

+37
-43
lines changed

lua/autocomplete/signature.lua

+37-43
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,6 @@ local methods = vim.lsp.protocol.Methods
33

44
local M = {}
55

6-
local state = {
7-
entry = nil,
8-
}
9-
10-
local function cursor_moved(args)
11-
local line = vim.api.nvim_get_current_line()
12-
local col = vim.api.nvim_win_get_cursor(0)[2]
13-
if col == 0 or #line == 0 then
14-
return
15-
end
16-
17-
local client = util.get_client(args.buf, methods.textDocument_signatureHelp)
18-
if not client then
19-
return
20-
end
21-
22-
local before_line = line:sub(1, col)
23-
local has_trigger_char = vim.iter(
24-
client.server_capabilities.signatureHelpProvider.triggerCharacters or {}
25-
)
26-
:filter(function(c)
27-
return string.find(before_line, '[' .. c .. ']') ~= nil
28-
end)
29-
:next() ~= nil
30-
31-
if not has_trigger_char then
32-
return
33-
end
34-
35-
util.debounce(state.entry, M.config.debounce_delay, function()
36-
vim.lsp.buf.signature_help({
37-
focusable = false,
38-
close_events = { 'CursorMoved', 'CursorMovedI', 'BufLeave', 'BufWinLeave' },
39-
border = M.config.border,
40-
max_width = M.config.width,
41-
max_height = M.config.height,
42-
anchor_bias = 'above',
43-
})
44-
end)
45-
end
46-
476
M.config = {
487
border = nil, -- Signature border style
498
width = 80, -- Max width of signature window
@@ -53,12 +12,47 @@ M.config = {
5312

5413
function M.setup(config)
5514
M.config = vim.tbl_deep_extend('force', M.config, config or {})
56-
state.entry = util.entry()
5715

16+
local entry = util.entry()
5817
vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
5918
desc = 'Auto show LSP signature help',
6019
group = vim.api.nvim_create_augroup('LspSignatureHelp', {}),
61-
callback = cursor_moved,
20+
callback = function(args)
21+
local line = vim.api.nvim_get_current_line()
22+
local col = vim.api.nvim_win_get_cursor(0)[2]
23+
if col == 0 or #line == 0 then
24+
return
25+
end
26+
27+
local client = util.get_client(args.buf, methods.textDocument_signatureHelp)
28+
if not client then
29+
return
30+
end
31+
32+
local before_line = line:sub(1, col)
33+
local has_trigger_char = vim.iter(
34+
client.server_capabilities.signatureHelpProvider.triggerCharacters or {}
35+
)
36+
:filter(function(c)
37+
return string.find(before_line, '[' .. c .. ']') ~= nil
38+
end)
39+
:next() ~= nil
40+
41+
if not has_trigger_char then
42+
return
43+
end
44+
45+
util.debounce(entry, M.config.debounce_delay, function()
46+
vim.lsp.buf.signature_help({
47+
focusable = false,
48+
close_events = { 'CursorMoved', 'CursorMovedI', 'BufLeave', 'BufWinLeave' },
49+
border = M.config.border,
50+
max_width = M.config.width,
51+
max_height = M.config.height,
52+
anchor_bias = 'above',
53+
})
54+
end)
55+
end,
6256
})
6357
end
6458

0 commit comments

Comments
 (0)