From b77413ff8f59f380612074f0c9bd49093d8db695 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Sun, 19 Jan 2025 13:52:52 +0100 Subject: Squashed 'mut/neovim/pack/plugins/start/blink.cmp/' content from commit 1cc3b1a git-subtree-dir: mut/neovim/pack/plugins/start/blink.cmp git-subtree-split: 1cc3b1a908fbcfd15451c4772759549724f38524 --- lua/blink/cmp/completion/prefetch.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lua/blink/cmp/completion/prefetch.lua (limited to 'lua/blink/cmp/completion/prefetch.lua') diff --git a/lua/blink/cmp/completion/prefetch.lua b/lua/blink/cmp/completion/prefetch.lua new file mode 100644 index 0000000..c722a30 --- /dev/null +++ b/lua/blink/cmp/completion/prefetch.lua @@ -0,0 +1,29 @@ +-- Run `resolve` on the item ahead of time to avoid delays +-- when accepting the item or showing documentation + +local last_context_id = nil +local last_request = nil +local timer = vim.uv.new_timer() + +--- @param context blink.cmp.Context +--- @param item blink.cmp.CompletionItem +local function prefetch_resolve(context, item) + if not item then return end + + local resolve = vim.schedule_wrap(function() + if last_request ~= nil then last_request:cancel() end + last_request = require('blink.cmp.sources.lib').resolve(context, item) + end) + + -- immediately resolve if the context has changed + if last_context_id ~= context.id then + last_context_id = context.id + resolve() + end + + -- otherwise, wait for the debounce period + timer:stop() + timer:start(50, 0, resolve) +end + +return prefetch_resolve -- cgit v1.2.3