Skip to content

Commit 01d5fd0

Browse files
committed
fix: documentation delays
1 parent 3927e23 commit 01d5fd0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lua/blink/cmp/windows/autocomplete.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ end
6767
---------- Visibility ----------
6868

6969
function autocomplete.open_with_items(context, items)
70+
autocomplete.context = context
7071
autocomplete.items = items
7172
autocomplete.draw()
7273

@@ -77,7 +78,7 @@ function autocomplete.open_with_items(context, items)
7778

7879
-- todo: some logic to maintain the selection if the user moved the cursor?
7980
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { 1, 0 })
80-
autocomplete.event_targets.on_select(autocomplete.get_selected_item())
81+
autocomplete.event_targets.on_select(autocomplete.get_selected_item(), context)
8182
end
8283

8384
function autocomplete.open()
@@ -144,7 +145,7 @@ function autocomplete.select_next()
144145
if current_line == line_count then return end
145146

146147
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { current_line + 1, 0 })
147-
autocomplete.event_targets.on_select(autocomplete.get_selected_item())
148+
autocomplete.event_targets.on_select(autocomplete.get_selected_item(), autocomplete.context)
148149
end
149150

150151
function autocomplete.select_prev()
@@ -154,7 +155,7 @@ function autocomplete.select_prev()
154155
if current_line == 1 then return end
155156

156157
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { math.max(current_line - 1, 1), 0 })
157-
autocomplete.event_targets.on_select(autocomplete.get_selected_item())
158+
autocomplete.event_targets.on_select(autocomplete.get_selected_item(), autocomplete.context)
158159
end
159160

160161
function autocomplete.listen_on_select(callback) autocomplete.event_targets.on_select = callback end

lua/blink/cmp/windows/documentation.lua

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
local config = require('blink.cmp.config').windows.documentation
33
local sources = require('blink.cmp.sources.lib')
44
local autocomplete = require('blink.cmp.windows.autocomplete')
5-
local utils = require('blink.cmp.utils')
65
local docs = {}
76

87
function docs.setup()
@@ -18,12 +17,19 @@ function docs.setup()
1817
if autocomplete.win:is_open() then docs.update_position() end
1918
end)
2019
if config.auto_show then
21-
autocomplete.listen_on_select(function(item)
22-
local delay = autocomplete.win:is_open() and config.update_delay_ms or config.auto_show_delay_ms
23-
if delay == 0 then
24-
return docs.show_item(item)
20+
local timer = vim.uv.new_timer()
21+
local last_context_id = nil
22+
autocomplete.listen_on_select(function(item, context)
23+
timer:stop()
24+
if docs.win:is_open() or context.id == last_context_id then
25+
timer:start(config.update_delay_ms, 0, function()
26+
vim.schedule(function() docs.show_item(item) end)
27+
end)
2528
else
26-
utils.debounce(docs.show_item, delay)(item)
29+
timer:start(config.auto_show_delay_ms, 0, function()
30+
last_context_id = context.id
31+
vim.schedule(function() docs.show_item(item) end)
32+
end)
2733
end
2834
end)
2935
end

0 commit comments

Comments
 (0)