fix: work-around for libuv issue where fs_scandir_next sometimes fails to return a file type

This commit is contained in:
Folke Lemaitre 2023-01-17 14:35:21 +01:00
parent 1b2a6f631c
commit c791c0ed7d
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 7 additions and 4 deletions

View File

@ -175,13 +175,16 @@ function M.ls(path, fn)
local handle = vim.loop.fs_scandir(path)
while handle do
local name, t = vim.loop.fs_scandir_next(handle)
-- HACK: assume type is a file if no type returned
-- see https://github.com/folke/lazy.nvim/issues/306
t = t or "file"
if not name then
break
end
if fn(path .. "/" .. name, name, t) == false then
local fname = path .. "/" .. name
-- HACK: type is not always returned due to a bug in luv,
-- so fecth it with fs_stat instead when needed.
-- see https://github.com/folke/lazy.nvim/issues/306
if fn(fname, name, t or vim.loop.fs_stat(fname).type) == false then
break
end
end