Skip to content

Commit 6cf5fce

Browse files
authored
fix: add search_ancestors function to util (#178)
1 parent 26c7e82 commit 6cf5fce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lua/quarto/util.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ function M.strip_archive_subpath(path)
1515
return path
1616
end
1717

18+
function M.search_ancestors(startpath, func)
19+
if nvim_eleven then
20+
vim.validate('func', func, 'function')
21+
end
22+
if func(startpath) then
23+
return startpath
24+
end
25+
local guard = 100
26+
for path in vim.fs.parents(startpath) do
27+
-- Prevent infinite recursion if our algorithm breaks
28+
guard = guard - 1
29+
if guard == 0 then
30+
return
31+
end
32+
33+
if func(path) then
34+
return path
35+
end
36+
end
37+
end
38+
1839
local function escape_wildcards(path)
1940
return path:gsub('([%[%]%?%*])', '\\%1')
2041
end

0 commit comments

Comments
 (0)