Skip to content

Commit 1d3d54f

Browse files
committed
feat: immediate fuzzy on keystroke
1 parent e7362c0 commit 1d3d54f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lua/blink/cmp/init.lua

+16-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ cmp.setup = function(opts)
3434
cmp.fuzzy = require('blink.cmp.fuzzy')
3535
cmp.fuzzy.init_db(vim.fn.stdpath('data') .. '/blink/cmp/fuzzy.db')
3636

37-
cmp.trigger.listen_on_show(function(context) cmp.sources.request_completions(context) end)
38-
cmp.trigger.listen_on_hide(function()
39-
cmp.sources.cancel_completions()
40-
cmp.windows.autocomplete.close()
41-
end)
42-
cmp.sources.listen_on_completions(function(context, items)
37+
-- we store the previous items so we can immediately perform fuzzy matching on keystroke
38+
-- and then update again when the sources return new results
39+
local last_items = {}
40+
local function update_completions(context, items)
41+
if items == nil then items = last_items end
42+
last_items = items
4343
-- we avoid adding 1-4ms to insertion latency by scheduling for later
4444
vim.schedule(function()
4545
local filtered_items = cmp.fuzzy.filter_items(require('blink.cmp.util').get_query(), items)
@@ -49,7 +49,17 @@ cmp.setup = function(opts)
4949
cmp.windows.autocomplete.close()
5050
end
5151
end)
52+
end
53+
54+
cmp.trigger.listen_on_show(function(context)
55+
update_completions(context)
56+
cmp.sources.request_completions(context)
57+
end)
58+
cmp.trigger.listen_on_hide(function()
59+
cmp.sources.cancel_completions()
60+
cmp.windows.autocomplete.close()
5261
end)
62+
cmp.sources.listen_on_completions(update_completions)
5363
end
5464

5565
cmp.add_default_highlights = function()

0 commit comments

Comments
 (0)