mirror of https://github.com/folke/lazy.nvim.git
fix(ui): get plugin details from the correct plugin in case it was deleted
This commit is contained in:
parent
6c5af82589
commit
2f5c1be525
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue