Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lua/cmp_path/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local constants = {
max_lines = 20,
}

local is_windows = (vim.fn.has("windows") == 1) and (vim.fn.has("unix") == 0)

---@class cmp_path.Options
---@field public trailing_slash boolean
Expand Down Expand Up @@ -60,6 +61,20 @@ source.complete = function(self, params, callback)
end)
end


local function is_url(prefix)

scheme = prefix:match('%a+://$')

-- Handle special case of drive letters on windows
if (is_windows and scheme and string.len(scheme) == 4) then
return false
end

return scheme or prefix:match('%a+:/$')

end

source._dirname = function(self, params, opts)
local s = PATH_REGEX:match_str(params.context.cursor_before_line)
if not s then
Expand Down Expand Up @@ -89,20 +104,29 @@ source._dirname = function(self, params, opts)
return vim.fn.resolve(env_var_value .. '/' .. dirname)
end
end
if prefix:match('/$') then

if is_windows then
start = prefix:match('%a://$')
end

if not start then
start = prefix:match('/$')
end

if start then
local accept = true
-- Ignore URL components
accept = accept and not prefix:match('%a/$')
-- Ignore URL scheme
accept = accept and not prefix:match('%a+:/$') and not prefix:match('%a+://$')
accept = accept and not is_url(prefix)
-- Ignore HTML closing tags
accept = accept and not prefix:match('</$')
-- Ignore math calculation
accept = accept and not prefix:match('[%d%)]%s*/$')
-- Ignore / comment
accept = accept and (not prefix:match('^[%s/]*$') or not self:_is_slash_comment())
if accept then
return vim.fn.resolve('/' .. dirname)
return vim.fn.resolve(start .. dirname)
end
end
return nil
Expand Down