feat(util): added util.on_load to execute code when a plugin loads

This commit is contained in:
Folke Lemaitre
2023-07-12 17:24:38 +02:00
parent b1721bc20a
commit 9fd89701da

View File

@ -256,4 +256,25 @@ function M.lsp_disable(server, cond)
end)
end
---@param name string
---@param fn fun(name:string)
function M.on_load(name, fn)
local Config = require("lazy.core.config")
if Config.plugins[name] and Config.plugins[name]._.loaded then
vim.schedule(function()
fn(name)
end)
else
vim.api.nvim_create_autocmd("User", {
pattern = "LazyLoad",
callback = function(event)
if event.data == name then
fn(name)
return true
end
end,
})
end
end
return M