mirror of
https://github.com/neovim/neovim.git
synced 2025-12-10 08:32:42 +00:00
fix(vim.fs): root() should always return absolute path #36466
This commit is contained in:
@@ -450,7 +450,8 @@ function M.root(source, marker)
|
|||||||
})
|
})
|
||||||
|
|
||||||
if #paths ~= 0 then
|
if #paths ~= 0 then
|
||||||
return vim.fs.dirname(paths[1])
|
local dir = vim.fs.dirname(paths[1])
|
||||||
|
return dir and vim.fn.fnamemodify(dir, ':p:h') or nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -432,6 +432,14 @@ describe('vim.fs', function()
|
|||||||
command('file lua://')
|
command('file lua://')
|
||||||
eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
|
eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('returns an absolute path for an invalid filename', function()
|
||||||
|
assert(n.fn.isabsolutepath(test_source_path) == 1)
|
||||||
|
eq(
|
||||||
|
t.fix_slashes(test_source_path),
|
||||||
|
t.fix_slashes(exec_lua([[return vim.fs.root('file://asd', 'CMakePresets.json')]]))
|
||||||
|
)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('joinpath()', function()
|
describe('joinpath()', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user