diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index fe22abe..f72ab21 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -92,7 +92,10 @@ function M.pretty_trace(opts) return #trace > 0 and ("\n\n# stacktrace:\n" .. table.concat(trace, "\n")) or "" end +---@generic R +---@param fn fun():R ---@param opts? string|{msg:string, on_error:fun(msg)} +---@return R function M.try(fn, opts) opts = type(opts) == "string" and { msg = opts } or opts or {} local msg = opts.msg diff --git a/lua/lazy/manage/reloader.lua b/lua/lazy/manage/reloader.lua index ef9305c..1a2b042 100644 --- a/lua/lazy/manage/reloader.lua +++ b/lua/lazy/manage/reloader.lua @@ -84,19 +84,24 @@ function M.check(start) end if not (start or #changes == 0) then - vim.schedule(function() - if Config.options.change_detection.notify and not Config.headless() then - local lines = { "# Config Change Detected. Reloading...", "" } - for _, change in ipairs(changes) do - table.insert(lines, "- **" .. change.what .. "**: `" .. vim.fn.fnamemodify(change.file, ":p:~:.") .. "`") - end - Util.warn(lines) - end - Plugin.load() - vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false }) - vim.api.nvim_exec_autocmds("User", { pattern = "LazyReload", modeline = false }) - end) + M.reload(changes) end end +---@param {file:string, what:string}[] +function M.reload(changes) + vim.schedule(function() + if Config.options.change_detection.notify and not Config.headless() then + local lines = { "# Config Change Detected. Reloading...", "" } + for _, change in ipairs(changes) do + table.insert(lines, "- **" .. change.what .. "**: `" .. vim.fn.fnamemodify(change.file, ":p:~:.") .. "`") + end + Util.warn(lines) + end + Plugin.load() + vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false }) + vim.api.nvim_exec_autocmds("User", { pattern = "LazyReload", modeline = false }) + end) +end + return M