diff --git a/lua/blink/cmp/sources/path/init.lua b/lua/blink/cmp/sources/path/init.lua index bcc694e7..f11b3849 100644 --- a/lua/blink/cmp/sources/path/init.lua +++ b/lua/blink/cmp/sources/path/init.lua @@ -1,10 +1,8 @@ -- credit to https://github.com/hrsh7th/cmp-path for the original implementation -- and https://codeberg.org/FelipeLema/cmp-async-path for the async implementation +local regex = require('blink.cmp.sources.path.regex') local path = {} -local NAME_REGEX = '\\%([^/\\\\:\\*?<>\'"`\\|]\\)' -local PATH_REGEX = - assert(vim.regex(([[\%(\%(/PAT*[^/\\\\:\\*?<>\'"`\\| .~]\)\|\%(/\.\.\)\)*/\zePAT*$]]):gsub('PAT', NAME_REGEX))) function path.new(opts) local self = setmetatable({}, { __index = path }) @@ -34,7 +32,7 @@ function path:get_completions(context, callback) local lib = require('blink.cmp.sources.path.lib') - local dirname = lib.dirname(PATH_REGEX, self.opts.get_cwd, context) + local dirname = lib.dirname(self.opts.get_cwd, context) if not dirname then return callback({ is_incomplete_forward = false, is_incomplete_backward = false, items = {} }) end local include_hidden = self.opts.show_hidden_files_by_default diff --git a/lua/blink/cmp/sources/path/lib.lua b/lua/blink/cmp/sources/path/lib.lua index 0dc13b90..b108ea75 100644 --- a/lua/blink/cmp/sources/path/lib.lua +++ b/lua/blink/cmp/sources/path/lib.lua @@ -1,17 +1,17 @@ +local regex = require('blink.cmp.sources.path.regex') local lib = {} ---- @param path_regex vim.regex --- @param get_cwd fun(context: blink.cmp.Context): string --- @param context blink.cmp.Context -function lib.dirname(path_regex, get_cwd, context) +function lib.dirname(get_cwd, context) -- 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) + local s = regex.PATH:match_str(line_before_cursor) if not s then return nil end - local dirname = string.gsub(string.sub(line_before_cursor, s + 2), '%a*$', '') -- exclude '/' + local dirname = string.gsub(string.sub(line_before_cursor, s + 2), regex.NAME .. '*$', '') -- exclude '/' local prefix = string.sub(line_before_cursor, 1, s + 1) -- include '/' local buf_dirname = get_cwd(context)