Skip to content

Commit

Permalink
fix(hacks): better on_module
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 24, 2024
1 parent aaaef36 commit c2ba96e
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,18 @@ function M.show_cursor()
end
end

---@param modname string
---@param fn fun(mod)
function M.on_module(module, fn)
local on = vim.schedule_wrap(function()
fn(package.loaded[module])
end)
if package.loaded[module] ~= nil then
return on()
function M.on_module(modname, fn)
if type(package.loaded[modname]) == "table" then
return fn(package.loaded[modname])
end

package.preload[module] = function()
if type(package.loaded[module]) == "table" then
return on()
end
package.preload[module] = nil
for _, loader in ipairs(package.loaders) do
local ret = loader(module)
if type(ret) == "function" then
on()
return ret()
end
end
package.preload[modname] = function()
package.preload[modname] = nil
package.loaded[modname] = nil
local mod = require(modname)
fn(mod)
return mod
end
end

Expand Down

0 comments on commit c2ba96e

Please sign in to comment.