diff --git a/lua/lazy/init.lua b/lua/lazy/init.lua index 233776a..717e701 100644 --- a/lua/lazy/init.lua +++ b/lua/lazy/init.lua @@ -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 diff --git a/lua/lazy/manager.lua b/lua/lazy/manager.lua index f576f6e..f4c8096 100644 --- a/lua/lazy/manager.lua +++ b/lua/lazy/manager.lua @@ -5,6 +5,9 @@ local Util = require("lazy.util") local M = {} +---@type table +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 diff --git a/lua/lazy/plugin.lua b/lua/lazy/plugin.lua index e273a55..fe79161 100644 --- a/lua/lazy/plugin.lua +++ b/lua/lazy/plugin.lua @@ -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] diff --git a/lua/lazy/task.lua b/lua/lazy/task.lua index 6cb0124..f330228 100644 --- a/lua/lazy/task.lua +++ b/lua/lazy/task.lua @@ -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)) diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 69bf1ee..fef5162 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -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, diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index 7402394..4afda31 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -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)