@@ -5,51 +5,8 @@ local M = {}
5
5
6
6
local state = {
7
7
entry = nil ,
8
- ns = nil ,
9
8
}
10
9
11
- local function signature_handler (client , result , bufnr )
12
- local triggers = client .server_capabilities .signatureHelpProvider .triggerCharacters
13
- local ft = vim .bo [bufnr ].filetype
14
- if not result .signatures or # result .signatures == 0 then
15
- return
16
- end
17
- local lines , hl = vim .lsp .util .convert_signature_help_to_markdown_lines (result , ft , triggers )
18
- if not lines or # lines == 0 then
19
- return
20
- end
21
-
22
- local fbuf = vim .lsp .util .open_floating_preview (lines , ' markdown' , {
23
- focusable = false ,
24
- close_events = { ' CursorMoved' , ' CursorMovedI' , ' BufLeave' , ' BufWinLeave' },
25
- border = M .config .border ,
26
- max_width = M .config .width ,
27
- max_height = M .config .height ,
28
- anchor_bias = ' above' ,
29
- })
30
-
31
- -- Highlight the active parameter.
32
- if hl then
33
- if vim .fn .has (' nvim-0.11.0' ) == 1 then
34
- vim .highlight .range (
35
- fbuf ,
36
- state .ns ,
37
- ' LspSignatureActiveParameter' ,
38
- { hl [1 ], hl [2 ] },
39
- { hl [3 ], hl [4 ] }
40
- )
41
- else
42
- vim .api .nvim_buf_add_highlight (
43
- fbuf ,
44
- state .ns ,
45
- ' PmenuSel' ,
46
- vim .startswith (lines [1 ], ' ```' ) and 1 or 0 ,
47
- unpack (hl )
48
- )
49
- end
50
- end
51
- end
52
-
53
10
local function cursor_moved (args )
54
11
local line = vim .api .nvim_get_current_line ()
55
12
local col = vim .api .nvim_win_get_cursor (0 )[2 ]
@@ -63,35 +20,28 @@ local function cursor_moved(args)
63
20
end
64
21
65
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
66
30
67
- -- Try to find signature help trigger character in current line
68
- for _ , c in ipairs (client .server_capabilities .signatureHelpProvider .triggerCharacters or {}) do
69
- if string.find (before_line , ' [' .. c .. ' ]' ) then
70
- local params = vim .lsp .util .make_position_params (
71
- vim .api .nvim_get_current_win (),
72
- client .offset_encoding
73
- )
74
- params .context = {
75
- isRetrigger = true ,
76
- triggerKind = vim .lsp .protocol .CompletionTriggerKind .TriggerCharacter ,
77
- triggerCharacter = c ,
78
- }
79
-
80
- util .debounce (state .entry , M .config .debounce_delay , function ()
81
- return util .request (
82
- client ,
83
- methods .textDocument_signatureHelp ,
84
- params ,
85
- function (result )
86
- signature_handler (client , result , args .buf )
87
- end ,
88
- args .buf
89
- )
90
- end )
91
-
92
- return
93
- end
31
+ if not has_trigger_char then
32
+ return
94
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 )
95
45
end
96
46
97
47
M .config = {
@@ -103,13 +53,11 @@ M.config = {
103
53
104
54
function M .setup (config )
105
55
M .config = vim .tbl_deep_extend (' force' , M .config , config or {})
106
- state .ns = vim .api .nvim_create_namespace (' LspSignatureHelp' )
107
56
state .entry = util .entry ()
108
- local group = vim .api .nvim_create_augroup (' LspSignatureHelp' , {})
109
57
110
58
vim .api .nvim_create_autocmd ({ ' CursorMovedI' , ' InsertEnter' }, {
111
59
desc = ' Auto show LSP signature help' ,
112
- group = group ,
60
+ group = vim . api . nvim_create_augroup ( ' LspSignatureHelp ' , {}) ,
113
61
callback = cursor_moved ,
114
62
})
115
63
end
0 commit comments