fix bug making the folder traversal ignore the cwd folder

This commit is contained in:
2026-06-14 22:10:40 +02:00
parent c7b7cf08e0
commit 1c3bb2a037
+20 -10
View File
@@ -358,21 +358,31 @@ do
return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= '' return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= ''
end end
---@param glob_pattern string ---return iterator starting from cwd and going upwards until the project
---@return boolean ---root is found by looking for the .git folder.
local function look_for_file(glob_pattern) ---@return fun(): string?
---@type string[] local function all_folders_till_root()
local folders = {vim.fn.getcwd()} local cwd = vim.fn.getcwd()
if not file_exists(folders[1], '.git') then local folders = {cwd}
for dir in vim.fs.parents(vim.fn.getcwd()) do for dir in vim.fs.parents(cwd) do
table.insert(folders, dir) table.insert(folders, dir)
if file_exists(dir, '.git') then
break
end end
local curr = 0
return function()
curr = curr + 1
local f = folders[curr]
if file_exists(f, '.git') then
curr = -1
end
return f
end end
end end
for _, dir in ipairs(folders) do ---@param glob_pattern string
---@return boolean
local function look_for_file(glob_pattern)
for dir in all_folders_till_root() do
if file_exists(dir, glob_pattern) then if file_exists(dir, glob_pattern) then
return true return true
end end