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("%.", "/")) "lua", (speclist.modules.prefix:gsub("%.", "/"))
) )
h.uv.fs_scandir(path, function(err, handle) local handle = h.uv.fs_scandir(path)
if err then while handle do
logger:log("error", "failed to load modules; reason: %s", err) local name = h.uv.fs_scandir_next(handle)
else if name then
while handle do -- skip non-lua files
local name = h.uv.fs_scandir_next(handle) if name:sub(#name - 3) ~= ".lua" then
if name then goto continue
-- 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
end 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) -- remove the file extension from the name so that lua doesn't fail
::continue:: -- 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
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 return self
end end