Skip to content

Commit

Permalink
feat: show completion window after accept if on trigger character
Browse files Browse the repository at this point in the history
closes #198
  • Loading branch information
Saghen committed Oct 26, 2024
1 parent 4de7b7e commit 28e0b5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/blink/cmp/accept/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ local function accept(item)
-- todo: since we apply the additional text edits after, auto imported functions will not
-- get auto brackets. If we apply them before, we have to modify the textEdit to compensate
brackets_lib.add_brackets_via_semantic_token(vim.bo.filetype, item, function()
require('blink.cmp.trigger.completion').show_if_on_trigger_character()
require('blink.cmp.trigger.signature').show_if_on_trigger_character()
text_edits_lib.apply_additional_text_edits(item)
end)
else
require('blink.cmp.trigger.completion').show_if_on_trigger_character()
require('blink.cmp.trigger.signature').show_if_on_trigger_character()
text_edits_lib.apply_additional_text_edits(item)
end
Expand Down
8 changes: 8 additions & 0 deletions lua/blink/cmp/trigger/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ function trigger.suppress_events_for_callback(cb)
and is_insert_mode
end

function trigger.show_if_on_trigger_character()
local cursor_col = vim.api.nvim_win_get_cursor(0)[2]
local char_under_cursor = vim.api.nvim_get_current_line():sub(cursor_col, cursor_col)
local is_on_trigger = vim.tbl_contains(sources.get_trigger_characters(), char_under_cursor)
if is_on_trigger then trigger.show({ trigger_character = char_under_cursor }) end
return is_on_trigger
end

--- @param opts { trigger_character?: string, send_upstream?: boolean, force?: boolean } | nil
function trigger.show(opts)
opts = opts or {}
Expand Down

0 comments on commit 28e0b5a

Please sign in to comment.