Skip to content

fix: documentation auto show no longer working #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lua/blink/cmp/windows/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ local autocomplete = {
context = nil,
event_targets = {
on_position_update = {},
--- @type fun(item: blink.cmp.CompletionItem?, context: blink.cmp.Context)
on_select = function() end,
--- @type table<fun(item: blink.cmp.CompletionItem?, context: blink.cmp.Context)>
on_select = {},
--- @type table<fun()>
on_close = {},
--- @type table<fun()>
Expand Down Expand Up @@ -82,7 +82,8 @@ function autocomplete.open_with_items(context, items)

-- todo: some logic to maintain the selection if the user moved the cursor?
vim.api.nvim_win_set_cursor(autocomplete.win:get_win(), { 1, 0 })
autocomplete.event_targets.on_select(autocomplete.get_selected_item(), context)

autocomplete.on_select_callbacks(autocomplete.get_selected_item(), context)
end

function autocomplete.open()
Expand Down Expand Up @@ -192,7 +193,7 @@ local function select(line, skip_auto_insert)
end)
end

autocomplete.event_targets.on_select(selected_item, autocomplete.context)
autocomplete.on_select_callbacks(selected_item, autocomplete.context)
end

--- @params opts? { skip_auto_insert?: boolean }
Expand Down Expand Up @@ -235,7 +236,15 @@ function autocomplete.select_prev(opts)
select(line, opts and opts.skip_auto_insert)
end

function autocomplete.listen_on_select(callback) autocomplete.event_targets.on_select = callback end
function autocomplete.listen_on_select(callback) table.insert(autocomplete.event_targets.on_select, callback) end

--- @param item? blink.cmp.CompletionItem
--- @param context blink.cmp.Context
function autocomplete.on_select_callbacks(item, context)
for _, callback in ipairs(autocomplete.event_targets.on_select) do
callback(item, context)
end
end

---------- Rendering ----------

Expand Down