From 34e2c78e0690a93196b5e59bbc9e050dfd6f3986 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 31 Dec 2022 16:01:59 +0100 Subject: [PATCH] feat(ui): show new version that is available instead of general message --- lua/lazy/manage/checker.lua | 6 +++--- lua/lazy/manage/init.lua | 2 +- lua/lazy/manage/task/git.lua | 4 +++- lua/lazy/types.lua | 2 +- lua/lazy/view/render.lua | 15 +++++++++++---- lua/lazy/view/sections.lua | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lua/lazy/manage/checker.lua b/lua/lazy/manage/checker.lua index 2b7a62a..f86e55e 100644 --- a/lua/lazy/manage/checker.lua +++ b/lua/lazy/manage/checker.lua @@ -19,11 +19,11 @@ function M.fast_check(opts) opts = opts or {} for _, plugin in pairs(Config.plugins) do if not plugin.pin and plugin._.installed then - plugin._.has_updates = nil + plugin._.updates = nil local info = Git.info(plugin.dir) local ok, target = pcall(Git.get_target, plugin) if ok and info and target and info.commit ~= target.commit then - plugin._.has_updates = true + plugin._.updates = { from = info, to = target } end end end @@ -45,7 +45,7 @@ function M.report(notify) local lines = {} M.updated = {} for _, plugin in pairs(Config.plugins) do - if plugin._.has_updates then + if plugin._.updates then table.insert(M.updated, plugin.name) if not vim.tbl_contains(M.reported, plugin.name) then table.insert(lines, "- **" .. plugin.name .. "**") diff --git a/lua/lazy/manage/init.lua b/lua/lazy/manage/init.lua index 9b8c8ac..83dd18c 100644 --- a/lua/lazy/manage/init.lua +++ b/lua/lazy/manage/init.lua @@ -183,7 +183,7 @@ end ---@param plugins? LazyPlugin[] function M.clear(plugins) for _, plugin in pairs(plugins or Config.plugins) do - plugin._.has_updates = nil + plugin._.updates = nil plugin._.updated = nil plugin._.cloned = nil plugin._.dirty = nil diff --git a/lua/lazy/manage/task/git.lua b/lua/lazy/manage/task/git.lua index 20b965b..376245d 100644 --- a/lua/lazy/manage/task/git.lua +++ b/lua/lazy/manage/task/git.lua @@ -35,7 +35,9 @@ M.log = { local info = assert(Git.info(self.plugin.dir)) local target = assert(Git.get_target(self.plugin)) assert(target.commit, self.plugin.name .. " " .. target.branch) - self.plugin._.has_updates = target.commit ~= info.commit + if target.commit ~= info.commit then + self.plugin._.updates = { from = info, to = target } + end table.insert(args, info.commit .. ".." .. target.commit) else vim.list_extend(args, opts.args or Config.options.git.log) diff --git a/lua/lazy/types.lua b/lua/lazy/types.lua index 053961f..c68cdf9 100644 --- a/lua/lazy/types.lua +++ b/lua/lazy/types.lua @@ -8,7 +8,7 @@ ---@field dirty? boolean ---@field updated? {from:string, to:string} ---@field is_local boolean ----@field has_updates? boolean +---@field updates? {from:GitInfo, to:GitInfo} ---@field cloned? boolean ---@field kind? LazyPluginKind ---@field dep? boolean True if this plugin is only in the spec as a dependency diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index 20c0f16..d57e504 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -345,10 +345,17 @@ function M:diagnostics(plugin) message = "updated from " .. plugin._.updated.from:sub(1, 7) .. " to " .. plugin._.updated.to:sub(1, 7), }) end - elseif plugin._.has_updates then - self:diagnostic({ - message = "updates available", - }) + elseif plugin._.updates then + local version = plugin._.updates.to.version + if version then + self:diagnostic({ + message = "version " .. tostring(version) .. " is available", + }) + else + self:diagnostic({ + message = "updates available", + }) + end end for _, task in ipairs(plugin._.tasks or {}) do if task:is_running() then diff --git a/lua/lazy/view/sections.lua b/lua/lazy/view/sections.lua index 213c446..d23cefd 100644 --- a/lua/lazy/view/sections.lua +++ b/lua/lazy/view/sections.lua @@ -63,7 +63,7 @@ return { { ---@param plugin LazyPlugin filter = function(plugin) - return plugin._.has_updates + return plugin._.updates end, title = "Updates", },