Skip to content

Commit 52ec2c9

Browse files
committed
feat: prefetch resolve on select
1 parent f7a951e commit 52ec2c9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lua/blink/cmp/windows/autocomplete.lua

+24-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ function autocomplete.setup()
6060
end,
6161
})
6262

63+
-- prefetch the resolved item
64+
local last_context_id = nil
65+
local last_request = nil
66+
local timer = vim.uv.new_timer()
67+
autocomplete.listen_on_select(function(item, context)
68+
local resolve = vim.schedule_wrap(function()
69+
if last_request ~= nil then last_request:cancel() end
70+
last_request = require('blink.cmp.sources.lib').resolve(item)
71+
end)
72+
73+
-- immediately resolve if the context has changed
74+
if last_context_id ~= context.id then
75+
last_context_id = context.id
76+
resolve()
77+
end
78+
79+
-- otherwise, wait for the debounce period
80+
timer:stop()
81+
timer:start(50, 0, resolve)
82+
end)
83+
6384
return autocomplete
6485
end
6586

@@ -312,10 +333,11 @@ function autocomplete.render_item_simple(ctx)
312333
{ ctx.kind_icon, ctx.icon_gap, hl_group = 'BlinkCmpKind' .. ctx.kind },
313334
{
314335
ctx.label,
315-
ctx.kind == 'Snippet' and '~' or nil,
336+
ctx.kind == 'Snippet' and '~' or '',
337+
(ctx.item.labelDetails and ctx.item.labelDetails.detail) and ctx.item.labelDetails.detail or '',
316338
fill = true,
317339
hl_group = ctx.deprecated and 'BlinkCmpLabelDeprecated' or 'BlinkCmpLabel',
318-
max_width = 50,
340+
max_width = 80,
319341
},
320342
' ',
321343
}

0 commit comments

Comments
 (0)