Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit 1c481cf

Browse files
committed
fix: some issues with path completion(#23)
1 parent 18378ad commit 1c481cf

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lua/source/path.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ M.getCallback = function()
4444
return M.callback
4545
end
4646

47+
4748
M.triggerFunction = function(_, _, _, manager)
4849
local pos = api.nvim_win_get_cursor(0)
4950
local line = api.nvim_get_current_line()
5051
local line_to_cursor = line:sub(1, pos[2])
5152
local textMatch = vim.fn.match(line_to_cursor, '\\f*$')
5253
local keyword = line_to_cursor:sub(textMatch+1)
53-
keyword = keyword:match("%s*(%S+)%w*/.*$")
54+
if keyword ~= '/' then
55+
keyword = keyword:match("%s*(%S+)%w*/.*$")
56+
end
5457
local path = vim.fn.expand('%:p:h')
58+
print(keyword)
5559
if keyword ~= nil then
5660
-- dealing with special case in matching
5761
if keyword == "/" and line:sub(pos[2], pos[2]) then
@@ -60,16 +64,21 @@ M.triggerFunction = function(_, _, _, manager)
6064
elseif string.sub(keyword, 1, 1) == "\"" or string.sub(keyword, 1, 1) == "'" then
6165
keyword = string.sub(keyword, 2, #keyword)
6266
end
67+
6368
local expanded_keyword = vim.fn.glob(keyword)
6469
local home = vim.fn.expand("$HOME")
65-
if expanded_keyword ~= nil and (expanded_keyword:find(home) or expanded_keyword:sub(1, 1) == "/") then
70+
if expanded_keyword == '/' then
71+
goto continue
72+
elseif expanded_keyword ~= nil and expanded_keyword ~= '/' then
6673
path = expanded_keyword
6774
else
6875
path = vim.fn.expand('%:p:h')
6976
path = path..'/'..keyword
7077
end
7178
end
79+
7280
::continue::
81+
path = path..'/'
7382
M.items = {}
7483
local stdout = vim.loop.new_pipe(false)
7584
local stderr = vim.loop.new_pipe(false)

0 commit comments

Comments
 (0)