mirror of https://github.com/folke/lazy.nvim.git
feat(checker): checker will now save last check time and only check at configured frequency even after restarting Neovim
This commit is contained in:
parent
835731f102
commit
813fc944d7
|
@ -136,6 +136,7 @@ M.defaults = {
|
||||||
-- only generate markdown helptags for plugins that dont have docs
|
-- only generate markdown helptags for plugins that dont have docs
|
||||||
skip_if_doc_exists = true,
|
skip_if_doc_exists = true,
|
||||||
},
|
},
|
||||||
|
state = vim.fn.stdpath("state") .. "/lazy/state.json", -- state info for checker and other things
|
||||||
debug = false,
|
debug = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ local Manage = require("lazy.manage")
|
||||||
local Util = require("lazy.util")
|
local Util = require("lazy.util")
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
local Git = require("lazy.manage.git")
|
local Git = require("lazy.manage.git")
|
||||||
|
local State = require("lazy.state")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
@ -12,7 +13,14 @@ M.reported = {}
|
||||||
|
|
||||||
function M.start()
|
function M.start()
|
||||||
M.fast_check()
|
M.fast_check()
|
||||||
M.check()
|
M.schedule()
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.schedule()
|
||||||
|
State.read() -- update state
|
||||||
|
local next_check = State.checker.last_check + Config.options.checker.frequency - os.time()
|
||||||
|
next_check = math.max(next_check, 0)
|
||||||
|
vim.defer_fn(M.check, next_check * 1000)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts? {report:boolean} report defaults to true
|
---@param opts? {report:boolean} report defaults to true
|
||||||
|
@ -32,6 +40,8 @@ function M.fast_check(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.check()
|
function M.check()
|
||||||
|
State.checker.last_check = os.time()
|
||||||
|
State.write() -- update state
|
||||||
local errors = false
|
local errors = false
|
||||||
for _, plugin in pairs(Config.plugins) do
|
for _, plugin in pairs(Config.plugins) do
|
||||||
if Plugin.has_errors(plugin) then
|
if Plugin.has_errors(plugin) then
|
||||||
|
@ -40,14 +50,14 @@ function M.check()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if errors then
|
if errors then
|
||||||
vim.defer_fn(M.check, Config.options.checker.frequency * 1000)
|
M.schedule()
|
||||||
else
|
else
|
||||||
Manage.check({
|
Manage.check({
|
||||||
show = false,
|
show = false,
|
||||||
concurrency = Config.options.checker.concurrency,
|
concurrency = Config.options.checker.concurrency,
|
||||||
}):wait(function()
|
}):wait(function()
|
||||||
M.report()
|
M.report()
|
||||||
vim.defer_fn(M.check, Config.options.checker.frequency * 1000)
|
M.schedule()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
local Util = require("lazy.util")
|
||||||
|
local Config = require("lazy.core.config")
|
||||||
|
|
||||||
|
---@type LazyState
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@class LazyState
|
||||||
|
local defaults = {
|
||||||
|
checker = {
|
||||||
|
last_check = 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
---@type LazyState
|
||||||
|
local data = nil
|
||||||
|
|
||||||
|
function M.read()
|
||||||
|
pcall(function()
|
||||||
|
---@diagnostic disable-next-line: cast-local-type
|
||||||
|
data = vim.json.decode(Util.read_file(Config.options.state))
|
||||||
|
end)
|
||||||
|
data = vim.tbl_deep_extend("force", {}, defaults, data or {})
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.write()
|
||||||
|
vim.fn.mkdir(vim.fn.fnamemodify(Config.options.state, ":p:h"), "p")
|
||||||
|
Util.write_file(Config.options.state, vim.json.encode(data))
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.__index(_, key)
|
||||||
|
if not data then
|
||||||
|
M.read()
|
||||||
|
end
|
||||||
|
return data[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.__setindex(_, key, value)
|
||||||
|
if not data then
|
||||||
|
M.read()
|
||||||
|
end
|
||||||
|
---@diagnostic disable-next-line: no-unknown
|
||||||
|
data[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(M, M)
|
Loading…
Reference in New Issue