make finding modules synchronous to avoid some bugs when calling...

internal neovim api functions
This commit is contained in:
2025-07-02 20:34:42 -04:00
parent 5deffca36e
commit 1538046b6f

View File

@ -30,54 +30,45 @@ function modules:setup(speclist, overrides, config_path)
"lua", (speclist.modules.prefix:gsub("%.", "/"))
)
h.uv.fs_scandir(path, function(err, handle)
if err then
logger:log("error", "failed to load modules; reason: %s", err)
else
while handle do
local name = h.uv.fs_scandir_next(handle)
if name then
-- skip non-lua files
if name:sub(#name - 3) ~= ".lua" then
goto continue
end
-- remove the file extension from the name so that lua doesn't fail
-- when attempting to load it
name = name:sub(0, #name - 4)
-- attempt to load the module
local mod = module.new(nil, name, speclist.modules.prefix, overrides)
if not mod then
goto continue
end
table.insert(o.modules, mod)
::continue::
elseif name == nil then
-- no more entries
break
else
-- if there's a single error bail out
logger:log("error", "failed to run clean uv.fs_scandir_next failed")
return
end
local handle = h.uv.fs_scandir(path)
while handle do
local name = h.uv.fs_scandir_next(handle)
if name then
-- skip non-lua files
if name:sub(#name - 3) ~= ".lua" then
goto continue
end
end
end)
else
-- loop through all modules and initialize them
for _, modpath in ipairs(speclist.modules) do
local mod = module.new(nil, modpath, speclist.modules.prefix, overrides)
if not mod then
goto continue
end
table.insert(o.modules, mod)
::continue::
-- remove the file extension from the name so that lua doesn't fail
-- when attempting to load it
name = name:sub(0, #name - 4)
-- put the module into the list of modules
table.insert(speclist.modules, name)
::continue::
elseif name == nil then
-- no more entries
break
else
-- if there's a single error bail out
logger:log("error", "failed to run clean uv.fs_scandir_next failed")
break
end
end
end
-- loop through all modules and initialize them
for _, modpath in ipairs(speclist.modules) do
local mod = module.new(nil, modpath, speclist.modules.prefix, overrides)
if not mod then
goto continue
end
table.insert(o.modules, mod)
::continue::
end
return self
end