Skip to content

Commit 5127233

Browse files
committed
refactor: use vim.fs.root() instead of hand-rolled check
1 parent 4c4e7bf commit 5127233

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

lua/wincent/commandt/private/find_root.lua

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,7 @@
1111
--- @param root_markers string[]
1212
--- @return string
1313
local function find_root(starting_directory, root_markers)
14-
-- Make absolute.
15-
starting_directory = vim.fn.fnamemodify(starting_directory, ':p')
16-
17-
-- If it's a directory, :p will add a trailing slash, which we must strip.
18-
starting_directory = starting_directory:gsub('(.-)/$', '%1')
19-
20-
local next_path = starting_directory
21-
local attempts = 0
22-
while attempts < 100 do
23-
attempts = attempts + 1
24-
for _, marker in ipairs(root_markers) do
25-
local candidate = next_path .. '/' .. marker
26-
if vim.fn.isdirectory(candidate) == 1 or vim.fn.filereadable(candidate) == 1 then
27-
return next_path
28-
end
29-
end
30-
next_path = vim.fs.normalize(vim.fs.joinpath(next_path, '..'))
31-
end
32-
33-
-- Found nothing.
34-
return starting_directory
14+
return vim.fs.root(starting_directory, root_markers) or starting_directory
3515
end
3616

3717
return find_root

0 commit comments

Comments
 (0)