* fix(#2094): fix the path resolving in windows * fix test case * tweak test case
This commit is contained in:
@@ -6,6 +6,7 @@ local lsp = vim.lsp
|
||||
---@field tokens avante.utils.tokens
|
||||
---@field root avante.utils.root
|
||||
---@field file avante.utils.file
|
||||
---@field path avante.utils.path
|
||||
---@field environment avante.utils.environment
|
||||
---@field lsp avante.utils.lsp
|
||||
local M = {}
|
||||
@@ -32,20 +33,9 @@ function M.has(plugin)
|
||||
return res
|
||||
end
|
||||
|
||||
local _is_win = nil
|
||||
function M.is_win() return M.path.is_win() end
|
||||
|
||||
function M.is_win()
|
||||
if _is_win == nil then _is_win = jit.os:find("Windows") ~= nil end
|
||||
return _is_win
|
||||
end
|
||||
|
||||
M.path_sep = (function()
|
||||
if M.is_win() then
|
||||
return "\\"
|
||||
else
|
||||
return "/"
|
||||
end
|
||||
end)()
|
||||
M.path_sep = M.path.SEP
|
||||
|
||||
---@return "linux" | "darwin" | "windows"
|
||||
function M.get_os_name()
|
||||
@@ -340,7 +330,7 @@ end
|
||||
|
||||
---@param path string
|
||||
---@return string
|
||||
function M.norm(path) return vim.fs.normalize(path) end
|
||||
function M.norm(path) return M.path.normalize(path) end
|
||||
|
||||
---@param msg string|string[]
|
||||
---@param opts? LazyNotifyOpts
|
||||
@@ -900,26 +890,9 @@ function M.get_parent_path(filepath)
|
||||
return res
|
||||
end
|
||||
|
||||
function M.make_relative_path(filepath, base_dir)
|
||||
if filepath:sub(-2) == M.path_sep .. "." then filepath = filepath:sub(1, -3) end
|
||||
if base_dir:sub(-2) == M.path_sep .. "." then base_dir = base_dir:sub(1, -3) end
|
||||
if filepath == base_dir then return "." end
|
||||
if filepath:sub(1, #base_dir) == base_dir then
|
||||
filepath = filepath:sub(#base_dir + 1)
|
||||
if filepath:sub(1, 2) == "." .. M.path_sep then
|
||||
filepath = filepath:sub(3)
|
||||
elseif filepath:sub(1, 1) == M.path_sep then
|
||||
filepath = filepath:sub(2)
|
||||
end
|
||||
end
|
||||
return filepath
|
||||
end
|
||||
function M.make_relative_path(filepath, base_dir) return M.path.relative(base_dir, filepath, false) end
|
||||
|
||||
function M.is_absolute_path(path)
|
||||
if not path then return false end
|
||||
if M.is_win() then return path:match("^%a:[/\\]") ~= nil end
|
||||
return path:match("^/") ~= nil
|
||||
end
|
||||
function M.is_absolute_path(path) return M.path.is_absolute(path) end
|
||||
|
||||
function M.to_absolute_path(path)
|
||||
if not path or path == "" then return path end
|
||||
@@ -939,16 +912,13 @@ function M.join_paths(...)
|
||||
goto continue
|
||||
end
|
||||
|
||||
if path:sub(1, 2) == "." .. M.path_sep then path = path:sub(3) end
|
||||
|
||||
if result ~= "" and result:sub(-1) ~= M.path_sep then result = result .. M.path_sep end
|
||||
result = result .. path
|
||||
result = result == "" and path or M.path.join(result, path)
|
||||
::continue::
|
||||
end
|
||||
return M.norm(result)
|
||||
end
|
||||
|
||||
function M.path_exists(path) return vim.loop.fs_stat(path) ~= nil end
|
||||
function M.path_exists(path) return M.path.is_exist(path) end
|
||||
|
||||
function M.is_first_letter_uppercase(str) return string.match(str, "^[A-Z]") ~= nil end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user