Skip to content

Commit

Permalink
fix: context not clearing on trigger character, path regexes
Browse files Browse the repository at this point in the history
closes Saghen#16
  • Loading branch information
Saghen authored and lopi-py committed Oct 10, 2024
1 parent 539b351 commit efb5e6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lua/blink/cmp/sources/path/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ end
function path:get_trigger_characters() return { '/', '.' } end

function path:get_completions(context, callback)
-- we use libuv, but the rest of the library expects to be synchronous
callback = vim.schedule_wrap(callback)

local lib = require('blink.cmp.sources.path.lib')

local dirname = lib.dirname(PATH_REGEX, self.opts.get_cwd, context)
Expand Down
5 changes: 4 additions & 1 deletion lua/blink/cmp/sources/path/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ local lib = {}
--- @param get_cwd fun(context: blink.cmp.Context): string
--- @param context blink.cmp.Context
function lib.dirname(path_regex, get_cwd, context)
local line_before_cursor = context.line:sub(1, context.cursor[2])
-- HACK: move this :sub logic into the context?
-- it's not obvious that you need to avoid going back a char if the start_col == end_col
local line_before_cursor =
context.line:sub(1, context.bounds.start_col - (context.bounds.start_col ~= context.bounds.end_col and 1 or 0))
local s = path_regex:match_str(line_before_cursor)
if not s then return nil end

Expand Down
10 changes: 7 additions & 3 deletions lua/blink/cmp/trigger/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ function trigger.activate_autocmds()
and not vim.tbl_contains(config.show_on_insert_blocked_trigger_characters, char_under_cursor)
local is_on_context_char = char_under_cursor:match(config.keyword_regex) ~= nil

if is_within_bounds or (is_on_trigger and trigger.context ~= nil) then
if is_within_bounds then
trigger.show()
-- check if we've gone 1 char behind the context and we're still on a context char
elseif is_on_context_char and trigger.context ~= nil and cursor_col == trigger.context.bounds.start_col - 1 then
elseif
-- check if we've gone 1 char behind the context and we're still on a context char
(is_on_context_char and trigger.context ~= nil and cursor_col == trigger.context.bounds.start_col - 1)
-- or if we've moved onto a trigger character
or (is_on_trigger and trigger.context ~= nil)
then
trigger.context = nil
trigger.show()
elseif config.show_on_insert_on_trigger_character and is_on_trigger and ev.event == 'InsertEnter' then
Expand Down

0 comments on commit efb5e6b

Please sign in to comment.