From 1538046b6f9ba5a11e0dfc3d6a308d7dff2295a4 Mon Sep 17 00:00:00 2001 From: Squibid Date: Wed, 2 Jul 2025 20:34:42 -0400 Subject: [PATCH] make finding modules synchronous to avoid some bugs when calling... internal neovim api functions --- lua/dep/modules/init.lua | 77 ++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/lua/dep/modules/init.lua b/lua/dep/modules/init.lua index 0902fc5..fb05230 100644 --- a/lua/dep/modules/init.lua +++ b/lua/dep/modules/init.lua @@ -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