Skip to content

Commit

Permalink
fix: path completion in Windows using backward slash (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
marovira authored Feb 4, 2025
1 parent cdd52ac commit 575784f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lua/blink/cmp/sources/path/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function path.new(opts)
return self
end

function path:get_trigger_characters() return { '/', '.' } 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
Expand Down
25 changes: 19 additions & 6 deletions lua/blink/cmp/sources/path/regex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@
-- Not allowed: ~/example foo
local NAME_WITH_SPACE_REGEX = '\\%([^/\\\\:\\*?<>\'"`\\|]\\)'
local NAME_REGEX = '\\%([^/\\\\:\\*?<>\'"`\\| ]\\)'
local PATH_REGEX = assert(
vim.regex(
([[\%(\%(/PAT1*[^/\\\\:\\*?<>\'"`\\| .~]\)\|\%(/\.\.\)\)*/\zePAT2*$]])
:gsub('PAT1', NAME_WITH_SPACE_REGEX)
:gsub('PAT2', NAME_REGEX)
local IS_WIN = vim.uv.os_uname().sysname == 'Windows_NT'
local PATH_REGEX

if IS_WIN then
PATH_REGEX = assert(
vim.regex(
([[\%(\%([/\\]PAT1*[^/\\\\:\\*?<>\'"`\\| .~]\)\|\%(/\.\.\)\)*[/\\]\zePAT2*$]])
:gsub('PAT1', NAME_WITH_SPACE_REGEX)
:gsub('PAT2', NAME_REGEX)
)
)
else
PATH_REGEX = assert(
vim.regex(
([[\%(\%(/PAT1*[^/\\\\:\\*?<>\'"`\\| .~]\)\|\%(/\.\.\)\)*/\zePAT2*$]])
:gsub('PAT1', NAME_WITH_SPACE_REGEX)
:gsub('PAT2', NAME_REGEX)
)
)
)
end

return {
--- Lua pattern for matching file names
Expand Down

0 comments on commit 575784f

Please sign in to comment.