diff --git a/lua/blink/cmp/completion/init.lua b/lua/blink/cmp/completion/init.lua index d504e7db..59dba49b 100644 --- a/lua/blink/cmp/completion/init.lua +++ b/lua/blink/cmp/completion/init.lua @@ -47,7 +47,7 @@ function completion.setup() end end - if not triggering_source_returned_items then return end + if not triggering_source_returned_items then return list.hide() end end list.show(event.context, event.items) diff --git a/lua/blink/cmp/completion/trigger/init.lua b/lua/blink/cmp/completion/trigger/init.lua index 2625d2d4..dbec2b12 100644 --- a/lua/blink/cmp/completion/trigger/init.lua +++ b/lua/blink/cmp/completion/trigger/init.lua @@ -65,7 +65,7 @@ function trigger.activate() local function on_cursor_moved(event, is_ignored) -- we were told to ignore the cursor moved event, so we update the context -- but don't send an on_show event upstream - if is_ignored and event == 'CursorMovedI' then + if is_ignored and event == 'CursorMoved' then if trigger.context ~= nil then trigger.show({ send_upstream = false }) end return end @@ -73,22 +73,19 @@ function trigger.activate() local cursor = context.get_cursor() local cursor_col = cursor[2] local char_under_cursor = context.get_line():sub(cursor_col, cursor_col) - local is_on_trigger_for_show = trigger.is_trigger_character(char_under_cursor) - local is_on_trigger_for_show_on_insert = trigger.is_trigger_character(char_under_cursor, true) local is_on_keyword_char = keyword_regex:match_str(char_under_cursor) ~= nil local insert_enter_on_trigger_character = config.show_on_trigger_character and config.show_on_insert_on_trigger_character - and is_on_trigger_for_show_on_insert and event == 'InsertEnter' + and trigger.is_trigger_character(char_under_cursor, true) -- check if we're still within the bounds of the query used for the context if trigger.context ~= nil and trigger.context:within_query_bounds(cursor) then trigger.show() -- check if we've entered insert mode on a trigger character - -- or if we've moved onto a trigger character (by accepting for example) - elseif insert_enter_on_trigger_character or (is_on_trigger_for_show and trigger.context ~= nil) then + elseif insert_enter_on_trigger_character then trigger.context = nil trigger.show({ trigger_character = char_under_cursor }) diff --git a/lua/blink/cmp/lib/buffer_events.lua b/lua/blink/cmp/lib/buffer_events.lua index 536fa38f..6cb63038 100644 --- a/lua/blink/cmp/lib/buffer_events.lua +++ b/lua/blink/cmp/lib/buffer_events.lua @@ -18,7 +18,7 @@ --- @class blink.cmp.BufferEventsListener --- @field on_char_added fun(char: string, is_ignored: boolean) ---- @field on_cursor_moved fun(event: 'CursorMovedI' | 'InsertEnter', is_ignored: boolean) +--- @field on_cursor_moved fun(event: 'CursorMoved' | 'InsertEnter', is_ignored: boolean) --- @field on_insert_leave fun() --- @type blink.cmp.BufferEvents @@ -72,9 +72,10 @@ function buffer_events:listen(opts) if last_char ~= '' then return end if not require('blink.cmp.config').enabled() then return end - if snippet.active() and not self.show_in_snippet and not self.has_context() then return end + if not self.show_in_snippet and not self.has_context() and snippet.active() then return end - opts.on_cursor_moved(ev.event, is_ignored) + local event = ev.event == 'CursorMovedI' and 'CursorMoved' or ev.event + opts.on_cursor_moved(event, is_ignored) end, }) diff --git a/lua/blink/cmp/lib/cmdline_events.lua b/lua/blink/cmp/lib/cmdline_events.lua index 88280ab7..071d554f 100644 --- a/lua/blink/cmp/lib/cmdline_events.lua +++ b/lua/blink/cmp/lib/cmdline_events.lua @@ -9,7 +9,7 @@ --- @class blink.cmp.CmdlineEventsListener --- @field on_char_added fun(char: string, is_ignored: boolean) ---- @field on_cursor_moved fun(event: 'CursorMovedI' | 'InsertEnter', is_ignored: boolean) +--- @field on_cursor_moved fun(event: 'CursorMoved' | 'InsertEnter', is_ignored: boolean) --- @field on_leave fun() --- @type blink.cmp.CmdlineEvents @@ -75,7 +75,7 @@ function cmdline_events:listen(opts) local is_ignored = self.ignore_next_cursor_moved self.ignore_next_cursor_moved = false - opts.on_cursor_moved('CursorMovedI', is_ignored) + opts.on_cursor_moved('CursorMoved', is_ignored) end) timer:start(16, 0, callback) diff --git a/lua/blink/cmp/signature/trigger.lua b/lua/blink/cmp/signature/trigger.lua index 95c1a573..f0040dce 100644 --- a/lua/blink/cmp/signature/trigger.lua +++ b/lua/blink/cmp/signature/trigger.lua @@ -45,17 +45,14 @@ function trigger.activate() }) trigger.buffer_events:listen({ on_char_added = function(char) - local is_on_trigger = trigger.is_trigger_character(char) - local is_on_retrigger = trigger.is_trigger_character(char, true) - -- ignore if disabled if not require('blink.cmp.config').enabled() then return trigger.hide() -- character forces a trigger according to the sources, refresh the existing context if it exists - elseif is_on_trigger then + elseif trigger.is_trigger_character(char) then return trigger.show({ trigger_character = char }) -- character forces a re-trigger according to the sources, show if we have a context - elseif is_on_retrigger and trigger.context ~= nil then + elseif trigger.is_trigger_character(char, true) and trigger.context ~= nil then return trigger.show() end end, @@ -66,7 +63,7 @@ function trigger.activate() if config.show_on_insert_on_trigger_character and is_on_trigger and event == 'InsertEnter' then trigger.show({ trigger_character = char_under_cursor }) - elseif event == 'CursorMovedI' and trigger.context ~= nil then + elseif event == 'CursorMoved' and trigger.context ~= nil then trigger.show() end end,