gitignroe 的bug修复
This commit is contained in:
parent
24b9daee42
commit
010b23851b
@ -58,7 +58,6 @@ end
|
||||
|
||||
local function get_project_filepaths()
|
||||
local project_root = Utils.get_project_root()
|
||||
print("project_root:", project_root)
|
||||
local files = Utils.scan_directory_respect_gitignore({ directory = project_root, add_dirs = true })
|
||||
files = vim.iter(files):map(function(filepath) return Path:new(filepath):make_relative(project_root) end):totable()
|
||||
|
||||
|
@ -665,6 +665,19 @@ function M.scan_directory_respect_gitignore(options)
|
||||
local directory = options.directory
|
||||
local gitignore_path = directory .. "/.gitignore"
|
||||
local gitignore_patterns, gitignore_negate_patterns = M.parse_gitignore(gitignore_path)
|
||||
|
||||
-- Convert relative paths in gitignore to absolute paths based on project root
|
||||
local project_root = M.get_project_root()
|
||||
local function to_absolute_path(pattern)
|
||||
-- Skip if already absolute path
|
||||
if pattern:sub(1, 1) == "/" then return pattern end
|
||||
-- Convert relative path to absolute
|
||||
return Path:new(project_root, pattern):absolute()
|
||||
end
|
||||
|
||||
gitignore_patterns = vim.tbl_map(to_absolute_path, gitignore_patterns)
|
||||
gitignore_negate_patterns = vim.tbl_map(to_absolute_path, gitignore_negate_patterns)
|
||||
|
||||
return M.scan_directory({
|
||||
directory = directory,
|
||||
gitignore_patterns = gitignore_patterns,
|
||||
|
@ -81,12 +81,10 @@ function M.detect(opts)
|
||||
opts.spec = opts.spec or type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec
|
||||
opts.buf = (opts.buf == nil or opts.buf == 0) and vim.api.nvim_get_current_buf() or opts.buf
|
||||
|
||||
print("Detection Specs:", vim.inspect(opts.spec))
|
||||
|
||||
local ret = {} ---@type AvanteRoot[]
|
||||
for _, spec in ipairs(opts.spec) do
|
||||
local paths = M.resolve(spec)(opts.buf)
|
||||
print("Paths for Spec:", spec, vim.inspect(paths))
|
||||
|
||||
paths = paths or {}
|
||||
paths = type(paths) == "table" and paths or { paths }
|
||||
@ -101,7 +99,6 @@ function M.detect(opts)
|
||||
if opts.all == false then break end
|
||||
end
|
||||
end
|
||||
print("Detected Roots:", vim.inspect(ret))
|
||||
return ret
|
||||
end
|
||||
|
||||
@ -119,18 +116,12 @@ M.cache = {}
|
||||
function M.get(opts)
|
||||
opts = opts or {}
|
||||
local buf = opts.buf or vim.api.nvim_get_current_buf()
|
||||
print("Current Buffer:", buf)
|
||||
|
||||
local ret = M.cache[buf]
|
||||
print("Cached Root:", ret)
|
||||
|
||||
if not ret then
|
||||
local roots = M.detect({ all = false, buf = buf })
|
||||
print("Detected Roots:", vim.inspect(roots))
|
||||
|
||||
ret = roots[1] and roots[1].paths[1] or vim.uv.cwd()
|
||||
print("Selected Root:", ret)
|
||||
|
||||
M.cache[buf] = ret
|
||||
end
|
||||
|
||||
@ -138,7 +129,6 @@ function M.get(opts)
|
||||
|
||||
-- Ensure a non-empty return value
|
||||
ret = ret ~= "" and ret or vim.uv.cwd()
|
||||
print("Final Root:", ret)
|
||||
|
||||
--- return Utils.is_win() and ret:gsub("/", "\\") or ret
|
||||
return ret
|
||||
|
Loading…
x
Reference in New Issue
Block a user