@@ -3,47 +3,6 @@ local methods = vim.lsp.protocol.Methods
3
3
4
4
local M = {}
5
5
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
-
47
6
M .config = {
48
7
border = nil , -- Signature border style
49
8
width = 80 , -- Max width of signature window
@@ -53,12 +12,47 @@ M.config = {
53
12
54
13
function M .setup (config )
55
14
M .config = vim .tbl_deep_extend (' force' , M .config , config or {})
56
- state .entry = util .entry ()
57
15
16
+ local entry = util .entry ()
58
17
vim .api .nvim_create_autocmd ({ ' CursorMovedI' , ' InsertEnter' }, {
59
18
desc = ' Auto show LSP signature help' ,
60
19
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 ,
62
56
})
63
57
end
64
58
0 commit comments