Skip to content

Commit d931042

Browse files
committed
Wait for filtering completion
1 parent 57101a2 commit d931042

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

lua/cmp/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ cmp.confirm = function(option, callback)
175175
return true
176176
end
177177

178-
cmp.core.filter.raw(cmp.core)
178+
vim.wait(1000, function()
179+
return not cmp.core.filter.running
180+
end)
179181
local e = cmp.core.view:get_selected_entry() or (option.select and cmp.core.view:get_first_entry() or nil)
180182
if e then
181183
cmp.core:confirm(e, {

lua/cmp/utils/async.lua

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
local async = {}
22

33
---@class cmp.AsyncThrottle
4+
---@field public running boolean
45
---@field public timeout number
56
---@field public stop function
6-
---@field public raw function
77
---@field public __call function
88

99
---@param fn function
@@ -18,29 +18,23 @@ async.throttle = function(fn, timeout)
1818
stop = function()
1919
time = nil
2020
timer:stop()
21-
end,
22-
raw = function(...)
23-
fn(...)
24-
end,
21+
end
2522
}, {
2623
__call = function(self, ...)
2724
local args = { ... }
2825

2926
if time == nil then
3027
time = vim.loop.now()
3128
end
32-
timer:stop()
3329

34-
local delta = math.max(1, self.timeout - (vim.loop.now() - time))
35-
timer:start(delta, 0, function()
36-
if not self.running then
30+
self.running = true
31+
timer:stop()
32+
timer:start(math.max(1, self.timeout - (vim.loop.now() - time)), 0, function()
33+
vim.schedule(function()
3734
time = nil
38-
self.running = true
39-
vim.schedule(function()
40-
self.running = false
41-
fn(unpack(args))
42-
end)
43-
end
35+
self.running = false
36+
fn(unpack(args))
37+
end)
4438
end)
4539
end,
4640
})

0 commit comments

Comments
 (0)