diff options
author | kylo252 <[email protected]> | 2022-11-01 15:22:20 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2022-11-01 10:22:20 -0400 |
commit | 325bf72f935aa2caf25cb644f79dc7a3ea2c1168 (patch) | |
tree | 0a5c04044f0e42b7701ef66b5c7320f4d53db982 | |
parent | 978ff7c24de968d5f2f956b72a196773ae80b903 (diff) |
refactor(hooks): use colorscheme event after reload (#3375)
-rw-r--r-- | lua/lvim/plugin-loader.lua | 22 | ||||
-rw-r--r-- | lua/lvim/utils/hooks.lua | 13 |
2 files changed, 26 insertions, 9 deletions
diff --git a/lua/lvim/plugin-loader.lua b/lua/lvim/plugin-loader.lua index 1f574bba..b786bfa7 100644 --- a/lua/lvim/plugin-loader.lua +++ b/lua/lvim/plugin-loader.lua @@ -69,6 +69,9 @@ 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 @@ -76,10 +79,17 @@ end function plugin_loader.recompile() plugin_loader.cache_clear() + vim.cmd [[LuaCacheClear]] pcall_packer_command "compile" - if utils.is_file(compile_path) then - Log:debug "generated packer_compiled.lua" - end + vim.api.nvim_create_autocmd("User", { + pattern = "PackerCompileDone", + once = true, + callback = function() + if utils.is_file(compile_path) then + Log:debug "generated packer_compiled.lua" + end + end, + }) end function plugin_loader.reload(configurations) @@ -150,7 +160,11 @@ function plugin_loader.sync_core_plugins() 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() diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua index bf0dac60..13f078b1 100644 --- a/lua/lvim/utils/hooks.lua +++ b/lua/lvim/utils/hooks.lua @@ -2,6 +2,7 @@ local M = {} local Log = require "lvim.core.log" local in_headless = #vim.api.nvim_list_uis() == 0 +local plugin_loader = require "lvim.plugin-loader" function M.run_pre_update() Log:debug "Starting pre-update hook" @@ -15,10 +16,12 @@ function M.run_on_packer_complete() Log:debug "Packer operation complete" vim.api.nvim_exec_autocmds("User", { pattern = "PackerComplete" }) - vim.g.colors_name = lvim.colorscheme - pcall(vim.cmd, "colorscheme " .. lvim.colorscheme) - if M._reload_triggered then + if not in_headless then + vim.schedule(function() + pcall(vim.api.nvim_exec_autocmds, "ColorScheme", { pattern = "*" }) + end) + end Log:debug "Reloaded configuration" M._reload_triggered = nil end @@ -34,7 +37,7 @@ end ---It also forces regenerating any template ftplugin files ---Tip: Useful for clearing any outdated settings function M.reset_cache() - vim.cmd [[LuaCacheClear]] + plugin_loader.recompile() local lvim_modules = {} for module, _ in pairs(package.loaded) do if module:match "lvim.core" or module:match "lvim.lsp" then @@ -68,7 +71,7 @@ function M.run_post_update() M.reset_cache() Log:debug "Syncing core plugins" - require("lvim.plugin-loader").sync_core_plugins() + plugin_loader.sync_core_plugins() if not in_headless then vim.schedule(function() |