mirror of https://github.com/folke/lazy.nvim.git
refactor: reloader
This commit is contained in:
parent
025520d083
commit
f4d57485b0
|
@ -92,7 +92,10 @@ function M.pretty_trace(opts)
|
||||||
return #trace > 0 and ("\n\n# stacktrace:\n" .. table.concat(trace, "\n")) or ""
|
return #trace > 0 and ("\n\n# stacktrace:\n" .. table.concat(trace, "\n")) or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@generic R
|
||||||
|
---@param fn fun():R
|
||||||
---@param opts? string|{msg:string, on_error:fun(msg)}
|
---@param opts? string|{msg:string, on_error:fun(msg)}
|
||||||
|
---@return R
|
||||||
function M.try(fn, opts)
|
function M.try(fn, opts)
|
||||||
opts = type(opts) == "string" and { msg = opts } or opts or {}
|
opts = type(opts) == "string" and { msg = opts } or opts or {}
|
||||||
local msg = opts.msg
|
local msg = opts.msg
|
||||||
|
|
|
@ -84,6 +84,12 @@ function M.check(start)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not (start or #changes == 0) then
|
if not (start or #changes == 0) then
|
||||||
|
M.reload(changes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param {file:string, what:string}[]
|
||||||
|
function M.reload(changes)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
if Config.options.change_detection.notify and not Config.headless() then
|
if Config.options.change_detection.notify and not Config.headless() then
|
||||||
local lines = { "# Config Change Detected. Reloading...", "" }
|
local lines = { "# Config Change Detected. Reloading...", "" }
|
||||||
|
@ -96,7 +102,6 @@ function M.check(start)
|
||||||
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
||||||
vim.api.nvim_exec_autocmds("User", { pattern = "LazyReload", modeline = false })
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyReload", modeline = false })
|
||||||
end)
|
end)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue