slight optimization
reuse the same folder array. just keep it in memory forever
This commit is contained in:
+16
-12
@@ -358,23 +358,27 @@ do
|
|||||||
return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= ''
|
return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= ''
|
||||||
end
|
end
|
||||||
|
|
||||||
---return iterator starting from cwd and going upwards until the project
|
local all_folders_till_root = nil
|
||||||
---root is found by looking for the .git folder.
|
do
|
||||||
---@return fun(): string?
|
|
||||||
local function all_folders_till_root()
|
|
||||||
local cwd = vim.fn.getcwd()
|
local cwd = vim.fn.getcwd()
|
||||||
local folders = {cwd}
|
local folders = {cwd} -- array of all folders from cwd to root
|
||||||
for dir in vim.fs.parents(cwd) do
|
for dir in vim.fs.parents(cwd) do
|
||||||
table.insert(folders, dir)
|
table.insert(folders, dir)
|
||||||
end
|
end
|
||||||
local curr = 0
|
|
||||||
return function()
|
---return iterator starting from cwd and going upwards until the project
|
||||||
curr = curr + 1
|
---root is found by looking for the .git folder.
|
||||||
local f = folders[curr]
|
---@return fun(): string?
|
||||||
if file_exists(f, '.git') then
|
all_folders_till_root = function()
|
||||||
curr = -1
|
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
|
||||||
return f
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user