Skip to content

Commit 6290abd

Browse files
authoredOct 27, 2024
fix: documentation auto show no longer working (#202)
1 parent 465dc89 commit 6290abd

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

‎lua/blink/cmp/windows/autocomplete.lua

+14-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ local autocomplete = {
2020
context = nil,
2121
event_targets = {
2222
on_position_update = {},
23-
--- @type fun(item: blink.cmp.CompletionItem?, context: blink.cmp.Context)
24-
on_select = function() end,
23+
--- @type table<fun(item: blink.cmp.CompletionItem?, context: blink.cmp.Context)>
24+
on_select = {},
2525
--- @type table<fun()>
2626
on_close = {},
2727
--- @type table<fun()>
@@ -82,7 +82,8 @@ function autocomplete.open_with_items(context, items)
8282

8383
-- todo: some logic to maintain the selection if the user moved the cursor?
8484
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { 1, 0 })
85-
autocomplete.event_targets.on_select(autocomplete.get_selected_item(), context)
85+
86+
autocomplete.on_select_callbacks(autocomplete.get_selected_item(), context)
8687
end
8788

8889
function autocomplete.open()
@@ -192,7 +193,7 @@ local function select(line, skip_auto_insert)
192193
end)
193194
end
194195

195-
autocomplete.event_targets.on_select(selected_item, autocomplete.context)
196+
autocomplete.on_select_callbacks(selected_item, autocomplete.context)
196197
end
197198

198199
--- @params opts? { skip_auto_insert?: boolean }
@@ -235,7 +236,15 @@ function autocomplete.select_prev(opts)
235236
select(line, opts and opts.skip_auto_insert)
236237
end
237238

238-
function autocomplete.listen_on_select(callback) autocomplete.event_targets.on_select = callback end
239+
function autocomplete.listen_on_select(callback) table.insert(autocomplete.event_targets.on_select, callback) end
240+
241+
--- @param item? blink.cmp.CompletionItem
242+
--- @param context blink.cmp.Context
243+
function autocomplete.on_select_callbacks(item, context)
244+
for _, callback in ipairs(autocomplete.event_targets.on_select) do
245+
callback(item, context)
246+
end
247+
end
239248

240249
---------- Rendering ----------
241250

0 commit comments

Comments
 (0)
Please sign in to comment.