blob: c722a300fcd1399cf7cbef4492687855c7bf33e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
|