Skip to content

Commit

Permalink
fix(ui): get plugin details from the correct plugin in case it was de…
Browse files Browse the repository at this point in the history
…leted
  • Loading branch information
folke committed Dec 26, 2022
1 parent 6c5af82 commit 2f5c1be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
25 changes: 17 additions & 8 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, {from: number, to: number}>
---@field locations {name:string, from: number, to: number, kind?: LazyPluginKind}[]
local M = {}

---@return LazyRender
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 2f5c1be

Please sign in to comment.