mirror of https://github.com/folke/lazy.nvim.git
fix: clean
This commit is contained in:
parent
35b1f98ac7
commit
7f4743ac30
|
@ -31,9 +31,9 @@ function M.setup(opts)
|
|||
Util.track("lazy_install")
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
if not plugin.installed then
|
||||
-- require("lazy.manager").install({
|
||||
-- wait = true,
|
||||
-- })
|
||||
require("lazy.manager").install({
|
||||
wait = true,
|
||||
})
|
||||
break
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,9 @@ local Util = require("lazy.util")
|
|||
|
||||
local M = {}
|
||||
|
||||
---@type table<string, LazyPlugin>
|
||||
M.to_clean = {}
|
||||
|
||||
---@alias ManagerOpts {wait?: boolean, plugins?: LazyPlugin[], clear?: boolean, show?: boolean}
|
||||
|
||||
---@param operation TaskType
|
||||
|
@ -84,11 +87,10 @@ end
|
|||
|
||||
---@param opts? ManagerOpts
|
||||
function M.clean(opts)
|
||||
opts = opts or {}
|
||||
M.check_clean()
|
||||
---@param plugin LazyPlugin
|
||||
M.run("clean", opts, function(plugin)
|
||||
return plugin.uri == nil and plugin.installed
|
||||
end)
|
||||
opts.plugins = vim.tbl_values(M.to_clean)
|
||||
M.run("clean", opts)
|
||||
end
|
||||
|
||||
function M.check_clean()
|
||||
|
@ -111,7 +113,7 @@ function M.check_clean()
|
|||
opt = opt == "opt",
|
||||
installed = true,
|
||||
}
|
||||
Config.plugins[pack.name] = plugin
|
||||
M.to_clean[plugin.dir] = plugin
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -119,7 +121,7 @@ function M.check_clean()
|
|||
end
|
||||
|
||||
function M.clear()
|
||||
for pack, plugin in pairs(Config.plugins) do
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
-- clear finished tasks
|
||||
if plugin.tasks then
|
||||
---@param task LazyTask
|
||||
|
@ -127,11 +129,8 @@ function M.clear()
|
|||
return task.running
|
||||
end, plugin.tasks)
|
||||
end
|
||||
-- clear cleaned plugins
|
||||
if plugin.uri == nil and not plugin.installed then
|
||||
Config.plugins[pack] = nil
|
||||
end
|
||||
end
|
||||
M.to_clean = {}
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -50,8 +50,8 @@ function M.plugin(plugin)
|
|||
plugin.name = name:lower()
|
||||
end
|
||||
|
||||
if Config.plugins[plugin.name] then
|
||||
for k, v in ipairs(plugin) do
|
||||
if Config.plugins[plugin.name] and Config.plugins[plugin.name] ~= plugin then
|
||||
for k, v in pairs(plugin) do
|
||||
Config.plugins[plugin.name][k] = v
|
||||
end
|
||||
return Config.plugins[plugin.name]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
local Process = require("lazy.process")
|
||||
local Loader = require("lazy.loader")
|
||||
local Util = require("lazy.util")
|
||||
|
||||
---@class LazyTask
|
||||
---@field plugin LazyPlugin
|
||||
|
@ -39,16 +40,17 @@ function Task:clean()
|
|||
vim.loop.fs_unlink(entry.path)
|
||||
end
|
||||
end
|
||||
|
||||
vim.loop.fs_rmdir(path)
|
||||
end
|
||||
|
||||
local stat = vim.loop.fs_stat(self.plugin.dir)
|
||||
local dir = self.plugin.dir:gsub("/+$", "")
|
||||
|
||||
local stat = vim.loop.fs_lstat(dir)
|
||||
|
||||
if stat.type == "directory" then
|
||||
rm(self.plugin.dir)
|
||||
rm(dir)
|
||||
else
|
||||
vim.loop.fs_unlink(self.plugin.dir)
|
||||
vim.loop.fs_unlink(dir)
|
||||
end
|
||||
|
||||
self.plugin.installed = false
|
||||
|
@ -96,7 +98,6 @@ function Task:run()
|
|||
Loader.load(self.plugin)
|
||||
|
||||
local run = self.plugin.run
|
||||
|
||||
if run then
|
||||
if type(run) == "string" and run:sub(1, 1) == ":" then
|
||||
vim.cmd(run:sub(2))
|
||||
|
|
|
@ -56,15 +56,13 @@ function M.show()
|
|||
nowait = true,
|
||||
buffer = buf,
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "q", close, {
|
||||
nowait = true,
|
||||
buffer = buf,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({
|
||||
"BufDelete",
|
||||
"BufLeave",
|
||||
"BufHidden",
|
||||
}, {
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufDelete", "BufLeave", "BufHidden" }, {
|
||||
once = true,
|
||||
buffer = buf,
|
||||
callback = close,
|
||||
|
|
|
@ -19,9 +19,11 @@ function M.render_plugins(buf, win, padding)
|
|||
self.buf = buf
|
||||
self.win = win
|
||||
self.padding = padding
|
||||
|
||||
Manager.check_clean()
|
||||
|
||||
self.plugins = vim.tbl_values(Config.plugins)
|
||||
vim.list_extend(self.plugins, vim.tbl_values(Manager.to_clean))
|
||||
table.sort(self.plugins, function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue