Pārlūkot izejas kodu

refactor(hooks): use colorscheme event after reload (#3375)

kylo252 2 gadi atpakaļ
vecāks
revīzija
325bf72f93
2 mainītis faili ar 26 papildinājumiem un 9 dzēšanām
  1. 18 4
      lua/lvim/plugin-loader.lua
  2. 8 5
      lua/lvim/utils/hooks.lua

+ 18 - 4
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()

+ 8 - 5
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()