Parcourir la source

fix(install): avoid data-races for `on_packer_complete` (#2157)

kylo252 il y a 3 ans
Parent
commit
ec1e4140fa
3 fichiers modifiés avec 13 ajouts et 19 suppressions
  1. 4 0
      lua/lvim/lsp/templates.lua
  2. 3 2
      lua/lvim/plugin-loader.lua
  3. 6 17
      lua/lvim/utils/hooks.lua

+ 4 - 0
lua/lvim/lsp/templates.lua

@@ -42,6 +42,10 @@ end
 ---The files are generated to a runtimepath: "$LUNARVIM_RUNTIME_DIR/site/after/ftplugin/template.lua"
 ---@param servers_names table list of servers to be enabled. Will add all by default
 function M.generate_templates(servers_names)
+  for _, client in pairs(vim.lsp.get_active_clients()) do
+    client:stop()
+  end
+
   servers_names = servers_names or {}
 
   Log:debug "Templates installation in progress"

+ 3 - 2
lua/lvim/plugin-loader.lua

@@ -43,7 +43,9 @@ function plugin_loader.init(opts)
     },
   }
 
-  vim.cmd [[autocmd User PackerComplete lua require('lvim.utils.hooks').run_on_packer_complete()]]
+  if not in_headless then
+    vim.cmd [[autocmd User PackerComplete lua require('lvim.utils.hooks').run_on_packer_complete()]]
+  end
 end
 
 -- packer expects a space separated list
@@ -113,7 +115,6 @@ function plugin_loader.sync_core_plugins()
 end
 
 function plugin_loader.ensure_installed()
-  plugin_loader.cache_clear()
   local all_plugins = _G.packer_plugins or plugin_loader.get_core_plugins()
   Log:trace(string.format("Syncing core plugins: [%q]", table.concat(all_plugins, ", ")))
   pcall_packer_command("install", all_plugins)

+ 6 - 17
lua/lvim/utils/hooks.lua

@@ -5,33 +5,25 @@ local in_headless = #vim.api.nvim_list_uis() == 0
 
 function M.run_pre_update()
   Log:debug "Starting pre-update hook"
-  if package.loaded["lspconfig"] then
-    vim.cmd [[ LspStop ]]
-  end
 end
 
 function M.run_pre_reload()
   Log:debug "Starting pre-reload hook"
-  if package.loaded["lspconfig"] then
-    vim.cmd [[ LspStop ]]
-  end
 end
 
 function M.run_on_packer_complete()
-  require("lvim.plugin-loader").recompile()
-  -- forcefully activate nvim-web-devicons
-  require("nvim-web-devicons").set_up_highlights()
-  if package.loaded["lspconfig"] then
-    vim.cmd [[ LspStart ]]
-  end
+  -- manually trigger event to fix colors
+  vim.cmd [[ doautocmd ColorScheme ]]
   Log:info "Reloaded configuration"
 end
 
 function M.run_post_reload()
   Log:debug "Starting post-reload hook"
-
-  M.reset_cache()
   require("lvim.plugin-loader").ensure_installed()
+  M.reset_cache()
+  if package.loaded["lspconfig"] then
+    pcall(vim.cmd, "LspRestart")
+  end
 end
 
 ---Reset any startup cache files used by Packer and Impatient
@@ -67,9 +59,6 @@ function M.run_post_update()
       end
       -- TODO: add a changelog
       vim.notify("Update complete", vim.log.levels.INFO)
-      if package.loaded["lspconfig"] then
-        vim.cmd [[ LspStart ]]
-      end
     end)
   end
 end