mirror of https://github.com/folke/lazy.nvim.git
feat(ui): added update checker
This commit is contained in:
parent
71e4b92fd6
commit
65cd28e613
|
@ -50,6 +50,13 @@ M.defaults = {
|
||||||
},
|
},
|
||||||
throttle = 20, -- how frequently should the ui process render events
|
throttle = 20, -- how frequently should the ui process render events
|
||||||
},
|
},
|
||||||
|
checker = {
|
||||||
|
-- lazy can automatically check for updates
|
||||||
|
enabled = false,
|
||||||
|
concurrency = 10, -- set to 1 to very slowly check for updates
|
||||||
|
notify = true, -- get a notification if new updates are found
|
||||||
|
frequency = 3600, -- every hour
|
||||||
|
},
|
||||||
performance = {
|
performance = {
|
||||||
---@type LazyCacheConfig
|
---@type LazyCacheConfig
|
||||||
cache = nil,
|
cache = nil,
|
||||||
|
@ -102,6 +109,9 @@ function M.setup(spec, opts)
|
||||||
require("lazy.core.cache").autosave()
|
require("lazy.core.cache").autosave()
|
||||||
require("lazy.view").setup()
|
require("lazy.view").setup()
|
||||||
require("lazy.manage.reloader").enable()
|
require("lazy.manage.reloader").enable()
|
||||||
|
if M.options.checker.enabled then
|
||||||
|
require("lazy.manage.checker").start()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ local M = {}
|
||||||
---@field dirty? boolean
|
---@field dirty? boolean
|
||||||
---@field updated? {from:string, to:string}
|
---@field updated? {from:string, to:string}
|
||||||
---@field is_local boolean
|
---@field is_local boolean
|
||||||
|
---@field has_updates? boolean
|
||||||
---@field cloned? boolean
|
---@field cloned? boolean
|
||||||
---@field dep? boolean True if this plugin is only in the spec as a dependency
|
---@field dep? boolean True if this plugin is only in the spec as a dependency
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
local Config = require("lazy.core.config")
|
||||||
|
local Manage = require("lazy.manage")
|
||||||
|
local Util = require("lazy.util")
|
||||||
|
local Git = require("lazy.manage.git")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.running = false
|
||||||
|
M.updated = {}
|
||||||
|
|
||||||
|
function M.start()
|
||||||
|
M.fast_check()
|
||||||
|
M.check()
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.fast_check()
|
||||||
|
for _, plugin in pairs(Config.plugins) do
|
||||||
|
local info = Git.info(plugin.dir)
|
||||||
|
local target = Git.get_target(plugin)
|
||||||
|
if info and target and info.commit ~= target.commit then
|
||||||
|
plugin._.has_updates = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
M.report()
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.check()
|
||||||
|
Manage.check({
|
||||||
|
show = false,
|
||||||
|
concurrency = Config.options.checker.concurrency,
|
||||||
|
}):wait(function()
|
||||||
|
M.report()
|
||||||
|
vim.defer_fn(M.check, Config.options.checker.frequency * 1000)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.report()
|
||||||
|
local lines = {}
|
||||||
|
for _, plugin in pairs(Config.plugins) do
|
||||||
|
if plugin._.has_updates and not vim.tbl_contains(M.updated, plugin.name) then
|
||||||
|
table.insert(lines, "- **" .. plugin.name .. "**")
|
||||||
|
table.insert(M.updated, plugin.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #lines > 0 and Config.options.checker.notify then
|
||||||
|
table.insert(lines, 1, "# Plugin Updates")
|
||||||
|
Util.info(lines)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -31,6 +31,7 @@ M.log = {
|
||||||
local info = assert(Git.info(self.plugin.dir))
|
local info = assert(Git.info(self.plugin.dir))
|
||||||
local target = assert(Git.get_target(self.plugin))
|
local target = assert(Git.get_target(self.plugin))
|
||||||
assert(target.commit, self.plugin.name .. " " .. target.branch)
|
assert(target.commit, self.plugin.name .. " " .. target.branch)
|
||||||
|
self.plugin._.has_updates = target.commit ~= info.commit
|
||||||
table.insert(args, info.commit .. ".." .. target.commit)
|
table.insert(args, info.commit .. ".." .. target.commit)
|
||||||
else
|
else
|
||||||
vim.list_extend(args, opts.args or Config.options.git.log)
|
vim.list_extend(args, opts.args or Config.options.git.log)
|
||||||
|
|
|
@ -42,7 +42,7 @@ function M.show(mode)
|
||||||
require("lazy.view.colors").setup()
|
require("lazy.view.colors").setup()
|
||||||
|
|
||||||
if M._buf and vim.api.nvim_buf_is_valid(M._buf) then
|
if M._buf and vim.api.nvim_buf_is_valid(M._buf) then
|
||||||
vim.api.nvim_win_set_cursor(M._win, { 1, 0 })
|
-- vim.api.nvim_win_set_cursor(M._win, { 1, 0 })
|
||||||
vim.cmd([[do User LazyRender]])
|
vim.cmd([[do User LazyRender]])
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue