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 = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@alias LazyPluginKind "normal"|"clean"
|
||||||
|
|
||||||
---@class LazyPluginState
|
---@class LazyPluginState
|
||||||
---@field loaded? {[string]:string}|{time:number}
|
---@field loaded? {[string]:string}|{time:number}
|
||||||
---@field installed boolean
|
---@field installed boolean
|
||||||
|
@ -14,6 +16,7 @@ local M = {}
|
||||||
---@field is_local boolean
|
---@field is_local boolean
|
||||||
---@field has_updates? boolean
|
---@field has_updates? boolean
|
||||||
---@field cloned? boolean
|
---@field cloned? boolean
|
||||||
|
---@field kind? LazyPluginKind
|
||||||
---@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
|
||||||
|
|
||||||
---@class LazyPluginHooks
|
---@class LazyPluginHooks
|
||||||
|
@ -218,6 +221,7 @@ function M.update_state()
|
||||||
name = pack,
|
name = pack,
|
||||||
dir = Config.options.root .. "/" .. pack,
|
dir = Config.options.root .. "/" .. pack,
|
||||||
_ = {
|
_ = {
|
||||||
|
kind = "clean",
|
||||||
installed = true,
|
installed = true,
|
||||||
is_symlink = dir_type == "link",
|
is_symlink = dir_type == "link",
|
||||||
is_local = dir_type == "link",
|
is_local = dir_type == "link",
|
||||||
|
|
|
@ -8,7 +8,7 @@ local Float = require("lazy.view.float")
|
||||||
|
|
||||||
---@class LazyViewState
|
---@class LazyViewState
|
||||||
---@field mode string
|
---@field mode string
|
||||||
---@field plugin? string
|
---@field plugin? {name:string, kind?: LazyPluginKind}
|
||||||
local default_state = {
|
local default_state = {
|
||||||
mode = "home",
|
mode = "home",
|
||||||
profile = {
|
profile = {
|
||||||
|
@ -38,6 +38,11 @@ function M.show(mode)
|
||||||
M.view:update()
|
M.view:update()
|
||||||
end
|
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()
|
function M.create()
|
||||||
local self = setmetatable({}, { __index = setmetatable(M, { __index = Float }) })
|
local self = setmetatable({}, { __index = setmetatable(M, { __index = Float }) })
|
||||||
---@cast self LazyView
|
---@cast self LazyView
|
||||||
|
@ -61,7 +66,11 @@ function M.create()
|
||||||
self:on_key(ViewConfig.keys.details, function()
|
self:on_key(ViewConfig.keys.details, function()
|
||||||
local plugin = self.render:get_plugin()
|
local plugin = self.render:get_plugin()
|
||||||
if plugin then
|
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()
|
self:update()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -15,7 +15,7 @@ local Text = require("lazy.view.text")
|
||||||
---@field plugins LazyPlugin[]
|
---@field plugins LazyPlugin[]
|
||||||
---@field progress {total:number, done:number}
|
---@field progress {total:number, done:number}
|
||||||
---@field _diagnostics LazyDiagnostic[]
|
---@field _diagnostics LazyDiagnostic[]
|
||||||
---@field plugin_range table<string, {from: number, to: number}>
|
---@field locations {name:string, from: number, to: number, kind?: LazyPluginKind}[]
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@return LazyRender
|
---@return LazyRender
|
||||||
|
@ -32,7 +32,7 @@ end
|
||||||
function M:update()
|
function M:update()
|
||||||
self._lines = {}
|
self._lines = {}
|
||||||
self._diagnostics = {}
|
self._diagnostics = {}
|
||||||
self.plugin_range = {}
|
self.locations = {}
|
||||||
|
|
||||||
self.plugins = vim.tbl_values(Config.plugins)
|
self.plugins = vim.tbl_values(Config.plugins)
|
||||||
vim.list_extend(self.plugins, vim.tbl_values(Config.to_clean))
|
vim.list_extend(self.plugins, vim.tbl_values(Config.to_clean))
|
||||||
|
@ -90,9 +90,17 @@ end
|
||||||
---@return LazyPlugin?
|
---@return LazyPlugin?
|
||||||
function M:get_plugin(row)
|
function M:get_plugin(row)
|
||||||
row = row or vim.api.nvim_win_get_cursor(self.view.win)[1]
|
row = row or vim.api.nvim_win_get_cursor(self.view.win)[1]
|
||||||
for name, range in pairs(self.plugin_range) do
|
for _, loc in ipairs(self.locations) do
|
||||||
if row >= range.from and row <= range.to then
|
if row >= loc.from and row <= loc.to then
|
||||||
return Config.plugins[name]
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -361,11 +369,12 @@ function M:plugin(plugin)
|
||||||
self:diagnostics(plugin)
|
self:diagnostics(plugin)
|
||||||
self:nl()
|
self:nl()
|
||||||
|
|
||||||
if self.view.state.plugin == plugin.name then
|
if self.view:is_selected(plugin) then
|
||||||
self:details(plugin)
|
self:details(plugin)
|
||||||
end
|
end
|
||||||
self:tasks(plugin)
|
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
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
|
@ -378,7 +387,7 @@ function M:tasks(plugin)
|
||||||
end
|
end
|
||||||
if task.name == "log" and not task.error then
|
if task.name == "log" and not task.error then
|
||||||
self:log(task)
|
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
|
if task.error then
|
||||||
self:append(vim.trim(task.error), "LazyError", { indent = 4, prefix = "│ " })
|
self:append(vim.trim(task.error), "LazyError", { indent = 4, prefix = "│ " })
|
||||||
self:nl()
|
self:nl()
|
||||||
|
|
Loading…
Reference in New Issue