Skip to content

Commit 26b62a5

Browse files
committed
feat(completion): update signature help without delay if currently shown
Details: - This improves experience when cursor jumps in Insert mode (like during snippet session) compared to only accounting for user typing. Resolve #1680
1 parent 18520ad commit 26b62a5

9 files changed

+103
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- FEATURE: both info and signature help windows now use tree-sitter highlighting:
3939
- Info window uses "markdown" parser (works best on Neovim>=0.10 as its parser is built-in). Special markdown characters are concealed (i.e. hidden) which might result into seemingly unnecessary whitespace as dimensions are computed not accounting for that.
4040
- Signature help uses same parser as in current filetype.
41+
- FEATURE: update signature help without delay if it is already shown. This helps to keep signature help up to date after cursor jumps in Insert mode (like during snippet session).
4142
- FEATURE: add support for item defaults in `CompletionList` response.
4243
- BREAKING FEATURE: rework how LSP completion items are converted to Neovim's completion items:
4344
- Show `detail` highlighted as buffer's language at the start of info window, but only if `detail` provides information not already present in `documentation`. It was previously used as extra text in the popup menu (via `menu` field), but this doesn't quite follow LSP specification: `detail` and `documentation` fields can be delayed up until `completionItem/resolve` request which implies they should be treated similarly.

doc/mini-completion.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ Features:
3131

3232
- Automatic display in floating window of completion item info (via
3333
'completionItem/resolve' request) and signature help (with highlighting
34-
of active parameter if LSP server provides such information). After opening,
35-
window for signature help is fixed and is closed when there is nothing to
36-
show, text is different or when leaving Insert mode.
37-
Scroll in either info/signature window (`<C-f>` / `<C-b>` by default).
34+
of active parameter if LSP server provides such information).
35+
Signature help is shown if character to cursor's left is a dedicated trigger
36+
character (configured in `signatureHelpProvider.triggerCharacters` of LSP
37+
server capabilities) and updated without delay if is currently opened.
38+
Already shown window for signature help is fixed and is closed when there
39+
is nothing to show, its text is different, or when leaving Insert mode.
40+
Scroll in either info/signature window with `<C-f>` / `<C-b>` (by default).
3841

3942
- Automatic actions are done after some configurable amount of delay. This
4043
reduces computational load and allows fast typing (completion and

lua/mini/completion.lua

+14-10
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
---
3232
--- - Automatic display in floating window of completion item info (via
3333
--- 'completionItem/resolve' request) and signature help (with highlighting
34-
--- of active parameter if LSP server provides such information). After opening,
35-
--- window for signature help is fixed and is closed when there is nothing to
36-
--- show, text is different or when leaving Insert mode.
37-
--- Scroll in either info/signature window (`<C-f>` / `<C-b>` by default).
34+
--- of active parameter if LSP server provides such information).
35+
--- Signature help is shown if character to cursor's left is a dedicated trigger
36+
--- character (configured in `signatureHelpProvider.triggerCharacters` of LSP
37+
--- server capabilities) and updated without delay if is currently opened.
38+
--- Already shown window for signature help is fixed and is closed when there
39+
--- is nothing to show, its text is different, or when leaving Insert mode.
40+
--- Scroll in either info/signature window with `<C-f>` / `<C-b>` (by default).
3841
---
3942
--- - Automatic actions are done after some configurable amount of delay. This
4043
--- reduces computational load and allows fast typing (completion and
@@ -225,8 +228,8 @@
225228
-- - On `CursorMovedI` start auto signature (if there is any active LSP
226229
-- client) with similar to completion timer pattern. Better event might
227230
-- be `InsertCharPre` but there are issues with 'autopair-type' plugins.
228-
-- - Check if character left to cursor is appropriate (')' or LSP's
229-
-- signature help trigger characters). If not, do nothing.
231+
-- Update immediately if already shown or after delay if character to the
232+
-- left is signature help trigger (after delay has passed).
230233
-- - If timer is activated, send 'textDocument/signatureHelp' request to
231234
-- all LSP clients. On callback, process their results. Window is opened
232235
-- if not already with the same text (its characteristics are computed
@@ -787,11 +790,12 @@ H.auto_signature = function()
787790
H.signature.timer:stop()
788791
if not H.has_lsp_clients('signatureHelpProvider') then return end
789792

790-
local left_char = H.get_left_char()
791-
local char_is_trigger = left_char == ')' or H.is_lsp_trigger(left_char, 'signature')
792-
if not char_is_trigger then return end
793+
local is_shown = H.is_valid_win(H.signature.win_id)
794+
local left_char_is_trigger = H.is_lsp_trigger(H.get_left_char(), 'signature')
795+
if not (is_shown or left_char_is_trigger) then return end
793796

794-
H.signature.timer:start(H.get_config().delay.signature, 0, vim.schedule_wrap(H.show_signature_window))
797+
local delay = is_shown and 0 or H.get_config().delay.signature
798+
H.signature.timer:start(delay, 0, vim.schedule_wrap(H.show_signature_window))
795799
end
796800

797801
H.on_completedonepre = function()

tests/dir-completion/mock-months-lsp.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ Months.requests = {
169169
local _, active_param_id = after_open_paren:gsub('%,', '%,')
170170

171171
-- Compute what is displayed in signature help: text and parameter info
172-
-- (for highlighting) based on latest word
173-
local word = line:match('%S+$')
172+
-- (for highlighting) based on latest function call
173+
local word = line:match('(%S+%()[^%(]*$')
174174
local label, parameters
175175
if word == 'long(' then
176176
label = string.rep('a ', 1000)

tests/screenshots/tests-test_completion.lua---Signature-help---updates-highlighting-of-active-parameter-003

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
-|---------|---------|---------|
2-
1|abc(1,2,
2+
1|abc(1,222,
33
2|~ ┌ Signature ────────┐
44
3|~ │abc(param1, param2)│
55
4|~ └───────────────────┘
66
5|~
7-
6|[No Name] [+] 1,9 All
7+
6|[No Name] [+] 1,11 All
88
7|-- INSERT --
99

1010
-|---------|---------|---------|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-|---------|---------|---------|
2+
1|abc(1,222,
3+
2|~ ┌ Signature ────────┐
4+
3|~ │abc(param1, param2)│
5+
4|~ └───────────────────┘
6+
5|~
7+
6|[No Name] [+] 1,8 All
8+
7|-- INSERT --
9+
10+
-|---------|---------|---------|
11+
1|000000000000000000000000000000
12+
2|111123333333333322222222211111
13+
3|111124444444444445555554211111
14+
4|111122222222222222222222211111
15+
5|111111111111111111111111111111
16+
6|666666666666666666666666666666
17+
7|777777777777888888888888888888
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-|---------|---------|---------|-----
2+
1|multiline(
3+
2|abc(111, 2┌ Signature ───────────┐
4+
3|~ │multiline( arg1, arg2)│
5+
4|~ └──────────────────────┘
6+
5|~
7+
6|~
8+
7|[No Name] [+] 1,11 All
9+
8|-- INSERT --
10+
11+
-|---------|---------|---------|-----
12+
1|00000000000000000000000000000000000
13+
2|00000000001222222222221111111111110
14+
3|33333333331444444444444444444444413
15+
4|33333333331111111111111111111111113
16+
5|33333333333333333333333333333333333
17+
6|33333333333333333333333333333333333
18+
7|55555555555555555555555555555555555
19+
8|66666666666677777777777777777777777
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-|---------|---------|---------|-----
2+
1|multiline(
3+
2|abc(111, 222)
4+
3|~ ┌ Signature ────────┐
5+
4|~ │abc(param1, param2)│
6+
5|~ └───────────────────┘
7+
6|~
8+
7|[No Name] [+] 2,12 All
9+
8|-- INSERT --
10+
11+
-|---------|---------|---------|-----
12+
1|00000000000000000000000000000000000
13+
2|00000000000000000000000000000000000
14+
3|11111111111233333333333222222222111
15+
4|11111111111244444444444455555542111
16+
5|11111111111222222222222222222222111
17+
6|11111111111111111111111111111111111
18+
7|66666666666666666666666666666666666
19+
8|77777777777788888888888888888888888

tests/test_completion.lua

+22-2
Original file line numberDiff line numberDiff line change
@@ -1271,14 +1271,34 @@ T['Signature help']['updates highlighting of active parameter'] = function()
12711271
sleep(default_signature_delay + small_time)
12721272
child.expect_screenshot()
12731273

1274+
-- Should update without configurable delay as window is already shown
12741275
type_keys('1,')
1275-
sleep(default_signature_delay + small_time)
1276+
sleep(small_time)
12761277
child.expect_screenshot()
12771278

12781279
-- As there are only two parameters, nothing should be highlighted
1279-
type_keys('2,')
1280+
type_keys('222,')
1281+
sleep(small_time)
1282+
child.expect_screenshot()
1283+
1284+
-- Should update if cursor is moved without typing (like during snippet jump)
1285+
set_cursor(1, 7)
1286+
sleep(small_time)
1287+
child.expect_screenshot()
1288+
end
1289+
1290+
T['Signature help']['updates without delay with different window'] = function()
1291+
child.set_size(8, 35)
1292+
set_lines({ 'multiline(', 'abc(111, 222)' })
1293+
child.cmd('startinsert')
1294+
set_cursor(1, 10)
1295+
12801296
sleep(default_signature_delay + small_time)
12811297
child.expect_screenshot()
1298+
1299+
set_cursor(2, 11)
1300+
sleep(small_time)
1301+
child.expect_screenshot()
12821302
end
12831303

12841304
local validate_signature_window_config = function(keys, win_config)

0 commit comments

Comments
 (0)