Skip to content

Commit

Permalink
fix: clean
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 20, 2022
1 parent 35b1f98 commit 7f4743a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lua/lazy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions lua/lazy/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -111,27 +113,24 @@ function M.check_clean()
opt = opt == "opt",
installed = true,
}
Config.plugins[pack.name] = plugin
M.to_clean[plugin.dir] = plugin
end
end
end
end
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
plugin.tasks = vim.tbl_filter(function(task)
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
4 changes: 2 additions & 2 deletions lua/lazy/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 6 additions & 5 deletions lua/lazy/task.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Process = require("lazy.process")
local Loader = require("lazy.loader")
local Util = require("lazy.util")

---@class LazyTask
---@field plugin LazyPlugin
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 3 additions & 5 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7f4743a

Please sign in to comment.