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