From 153593ff51cdf1b038daa44f053d30a84ec62b1f Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 4 Nov 2022 14:53:57 +0100 Subject: fix(config): more comprehensive cache reset (#3416) --- lua/lvim/plugin-loader.lua | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'lua/lvim/plugin-loader.lua') diff --git a/lua/lvim/plugin-loader.lua b/lua/lvim/plugin-loader.lua index 1f574bba..88c2c0d2 100644 --- a/lua/lvim/plugin-loader.lua +++ b/lua/lvim/plugin-loader.lua @@ -69,17 +69,31 @@ local function pcall_packer_command(cmd, kwargs) end function plugin_loader.cache_clear() + if not utils.is_file(compile_path) then + return + end if vim.fn.delete(compile_path) == 0 then Log:debug "deleted packer_compiled.lua" end end +function plugin_loader.compile() + Log:debug "calling packer.compile()" + vim.api.nvim_create_autocmd("User", { + pattern = "PackerCompileDone", + once = true, + callback = function() + if utils.is_file(compile_path) then + Log:debug "finished compiling packer_compiled.lua" + end + end, + }) + pcall_packer_command "compile" +end + function plugin_loader.recompile() plugin_loader.cache_clear() - pcall_packer_command "compile" - if utils.is_file(compile_path) then - Log:debug "generated packer_compiled.lua" - end + plugin_loader.compile() end function plugin_loader.reload(configurations) @@ -140,17 +154,10 @@ function plugin_loader.load_snapshot(snapshot_file) end function plugin_loader.sync_core_plugins() - -- problem: rollback() will get stuck if a plugin directory doesn't exist - -- solution: call sync() beforehand - -- see https://github.com/wbthomason/packer.nvim/issues/862 - vim.api.nvim_create_autocmd("User", { - pattern = "PackerComplete", - once = true, - callback = function() - require("lvim.plugin-loader").load_snapshot(default_snapshot) - end, - }) - pcall_packer_command "sync" + plugin_loader.cache_clear() + local core_plugins = plugin_loader.get_core_plugins() + Log:trace(string.format("Syncing core plugins: [%q]", table.concat(core_plugins, ", "))) + pcall_packer_command("sync", core_plugins) end function plugin_loader.ensure_plugins() @@ -158,8 +165,7 @@ function plugin_loader.ensure_plugins() pattern = "PackerComplete", once = true, callback = function() - Log:debug "calling packer.clean()" - pcall_packer_command "clean" + plugin_loader.compile() end, }) Log:debug "calling packer.install()" -- cgit v1.2.3