feat: support relative paths without a leading forward slash

This patch adds support for triggering path completion on `"` and `'`
(double and single quotes), limited to relative paths that start without
a leading forward slash.

closes #10
This commit is contained in:
Benjamin Denhartog 2021-11-24 20:15:55 -07:00
parent 81518cf6ae
commit d4544fc965
No known key found for this signature in database
GPG Key ID: C2631F793A698827
1 changed files with 3 additions and 3 deletions

View File

@ -1,7 +1,7 @@
local cmp = require'cmp' local cmp = require'cmp'
local NAME_REGEX = '\\%([^/\\\\:\\*?<>\'"`\\|]\\)' local NAME_REGEX = '\\%([^/\\\\:\\*?<>\'"`\\|]\\)'
local PATH_REGEX = vim.regex(([[\%(/PAT\+\)*/\zePAT*$]]):gsub('PAT', NAME_REGEX)) local PATH_REGEX = vim.regex(([[\%([/"\']PAT\+\)*[/"\']\zePAT*$]]):gsub('PAT', NAME_REGEX))
local source = {} local source = {}
@ -14,7 +14,7 @@ source.new = function()
end end
source.get_trigger_characters = function() source.get_trigger_characters = function()
return { '/', '.' } return { '/', '.', '"', '\'' }
end end
source.get_keyword_pattern = function() source.get_keyword_pattern = function()
@ -56,7 +56,7 @@ source._dirname = function(self, params)
if prefix:match('%.%./$') then if prefix:match('%.%./$') then
return vim.fn.resolve(buf_dirname .. '/../' .. dirname) return vim.fn.resolve(buf_dirname .. '/../' .. dirname)
end end
if prefix:match('%./$') then if (prefix:match('%./$') or prefix:match('"$') or prefix:match('\'$')) then
return vim.fn.resolve(buf_dirname .. '/' .. dirname) return vim.fn.resolve(buf_dirname .. '/' .. dirname)
end end
if prefix:match('~/$') then if prefix:match('~/$') then