Skip to content

Commit 15cb871

Browse files
committed
fix: context not clearing on trigger character, path regexes
closes #16
1 parent 506ea74 commit 15cb871

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

lua/blink/cmp/sources/path/init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ end
2929
function path:get_trigger_characters() return { '/', '.' } end
3030

3131
function path:get_completions(context, callback)
32+
-- we use libuv, but the rest of the library expects to be synchronous
33+
callback = vim.schedule_wrap(callback)
34+
3235
local lib = require('blink.cmp.sources.path.lib')
3336

3437
local dirname = lib.dirname(PATH_REGEX, self.opts.get_cwd, context)

lua/blink/cmp/sources/path/lib.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ local lib = {}
44
--- @param get_cwd fun(context: blink.cmp.Context): string
55
--- @param context blink.cmp.Context
66
function lib.dirname(path_regex, get_cwd, context)
7-
local line_before_cursor = context.line:sub(1, context.cursor[2])
7+
-- HACK: move this :sub logic into the context?
8+
-- it's not obvious that you need to avoid going back a char if the start_col == end_col
9+
local line_before_cursor =
10+
context.line:sub(1, context.bounds.start_col - (context.bounds.start_col ~= context.bounds.end_col and 1 or 0))
811
local s = path_regex:match_str(line_before_cursor)
912
if not s then return nil end
1013

lua/blink/cmp/trigger/completion.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ function trigger.activate_autocmds()
6363
and not vim.tbl_contains(config.show_on_insert_blocked_trigger_characters, char_under_cursor)
6464
local is_on_context_char = char_under_cursor:match(config.keyword_regex) ~= nil
6565

66-
if is_within_bounds or (is_on_trigger and trigger.context ~= nil) then
66+
if is_within_bounds then
6767
trigger.show()
68-
-- check if we've gone 1 char behind the context and we're still on a context char
69-
elseif is_on_context_char and trigger.context ~= nil and cursor_col == trigger.context.bounds.start_col - 1 then
68+
elseif
69+
-- check if we've gone 1 char behind the context and we're still on a context char
70+
(is_on_context_char and trigger.context ~= nil and cursor_col == trigger.context.bounds.start_col - 1)
71+
-- or if we've moved onto a trigger character
72+
or (is_on_trigger and trigger.context ~= nil)
73+
then
7074
trigger.context = nil
7175
trigger.show()
7276
elseif config.show_on_insert_on_trigger_character and is_on_trigger and ev.event == 'InsertEnter' then

0 commit comments

Comments
 (0)