From 2f5c1be5255a318d610e0a86abe0a38bf18af4ad Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 25 Dec 2022 21:07:30 +0100 Subject: [PATCH] fix(ui): get plugin details from the correct plugin in case it was deleted --- lua/lazy/core/plugin.lua | 4 ++++ lua/lazy/view/init.lua | 13 +++++++++++-- lua/lazy/view/render.lua | 25 +++++++++++++++++-------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index c69f048..de365d9 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -5,6 +5,8 @@ local Cache = require("lazy.core.cache") local M = {} +---@alias LazyPluginKind "normal"|"clean" + ---@class LazyPluginState ---@field loaded? {[string]:string}|{time:number} ---@field installed boolean @@ -14,6 +16,7 @@ local M = {} ---@field is_local boolean ---@field has_updates? boolean ---@field cloned? boolean +---@field kind? LazyPluginKind ---@field dep? boolean True if this plugin is only in the spec as a dependency ---@class LazyPluginHooks @@ -218,6 +221,7 @@ function M.update_state() name = pack, dir = Config.options.root .. "/" .. pack, _ = { + kind = "clean", installed = true, is_symlink = dir_type == "link", is_local = dir_type == "link", diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 3013377..8cf6ec6 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -8,7 +8,7 @@ local Float = require("lazy.view.float") ---@class LazyViewState ---@field mode string ----@field plugin? string +---@field plugin? {name:string, kind?: LazyPluginKind} local default_state = { mode = "home", profile = { @@ -38,6 +38,11 @@ function M.show(mode) M.view:update() end +---@param plugin LazyPlugin +function M:is_selected(plugin) + return vim.deep_equal(self.state.plugin, { name = plugin.name, kind = plugin._.kind }) +end + function M.create() local self = setmetatable({}, { __index = setmetatable(M, { __index = Float }) }) ---@cast self LazyView @@ -61,7 +66,11 @@ function M.create() self:on_key(ViewConfig.keys.details, function() local plugin = self.render:get_plugin() if plugin then - self.state.plugin = self.state.plugin ~= plugin.name and plugin.name or nil + local selected = { + name = plugin.name, + kind = plugin._.kind, + } + self.state.plugin = not vim.deep_equal(self.state.plugin, selected) and selected or nil self:update() end end) diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index c7b5e8f..8342a8e 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -15,7 +15,7 @@ local Text = require("lazy.view.text") ---@field plugins LazyPlugin[] ---@field progress {total:number, done:number} ---@field _diagnostics LazyDiagnostic[] ----@field plugin_range table +---@field locations {name:string, from: number, to: number, kind?: LazyPluginKind}[] local M = {} ---@return LazyRender @@ -32,7 +32,7 @@ end function M:update() self._lines = {} self._diagnostics = {} - self.plugin_range = {} + self.locations = {} self.plugins = vim.tbl_values(Config.plugins) vim.list_extend(self.plugins, vim.tbl_values(Config.to_clean)) @@ -90,9 +90,17 @@ end ---@return LazyPlugin? function M:get_plugin(row) row = row or vim.api.nvim_win_get_cursor(self.view.win)[1] - for name, range in pairs(self.plugin_range) do - if row >= range.from and row <= range.to then - return Config.plugins[name] + for _, loc in ipairs(self.locations) do + if row >= loc.from and row <= loc.to then + if loc.kind == "clean" then + for _, plugin in ipairs(Config.to_clean) do + if plugin.name == loc.name then + return plugin + end + end + else + return Config.plugins[loc.name] + end end end end @@ -361,11 +369,12 @@ function M:plugin(plugin) self:diagnostics(plugin) self:nl() - if self.view.state.plugin == plugin.name then + if self.view:is_selected(plugin) then self:details(plugin) end self:tasks(plugin) - self.plugin_range[plugin.name] = { from = plugin_start, to = self:row() - 1 } + self.locations[#self.locations + 1] = + { name = plugin.name, from = plugin_start, to = self:row() - 1, kind = plugin._.kind } end ---@param plugin LazyPlugin @@ -378,7 +387,7 @@ function M:tasks(plugin) end if task.name == "log" and not task.error then self:log(task) - elseif task.error or self.view.state.plugin == plugin.name then + elseif task.error or self.view:is_selected(plugin) then if task.error then self:append(vim.trim(task.error), "LazyError", { indent = 4, prefix = "│ " }) self:nl()