diff options
author | kylo252 <[email protected]> | 2021-12-13 17:58:35 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-12-13 17:58:35 +0100 |
commit | 6cf21e9ddec41addf01744176afb2e138b3e1b3f (patch) | |
tree | 4abf843da0e2ed38689c872694b13d7418536106 /lua/lvim/utils/hooks.lua | |
parent | 3a2d62ed2510ca05eb6ea87240a86df82338f5aa (diff) | |
parent | b09ada89402e668ea1636bdbf671a89330199717 (diff) |
Merge LunarVim/release-candidate
Diffstat (limited to 'lua/lvim/utils/hooks.lua')
-rw-r--r-- | lua/lvim/utils/hooks.lua | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua index 0fe4a7fd..9b02b958 100644 --- a/lua/lvim/utils/hooks.lua +++ b/lua/lvim/utils/hooks.lua @@ -1,42 +1,75 @@ local M = {} -local plugin_loader = require "lvim.plugin-loader" local Log = require "lvim.core.log" local in_headless = #vim.api.nvim_list_uis() == 0 function M.run_pre_update() Log:debug "Starting pre-update hook" - _G.__luacache.clear_cache() - vim.cmd "LspStop" + 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() + Log:info "Reloaded configuration" +end + +function M.run_post_reload() + Log:debug "Starting post-reload hook" + if package.loaded["lspconfig"] then + vim.cmd [[ LspRestart ]] + end + + M.reset_cache() + require("lvim.plugin-loader").ensure_installed() end ---Reset any startup cache files used by Packer and Impatient ---It also forces regenerating any template ftplugin files ---Tip: Useful for clearing any outdated settings function M.reset_cache() - _G.__luacache.clear_cache() - require("lvim.plugin-loader").recompile() - package.loaded["lvim.lsp.templates"] = nil - - Log:debug "Re-generatring ftplugin template files" + local impatient = _G.__luacache + if impatient then + impatient.clear_cache() + end + local lvim_modules = {} + for module, _ in pairs(package.loaded) do + if module:match "lvim.core" or module:match "lvim.lsp" then + package.loaded[module] = nil + table.insert(lvim_modules, module) + end + end + Log:trace(string.format("Cache invalidated for core modules: { %s }", table.concat(lvim_modules, ", "))) require("lvim.lsp.templates").generate_templates() end function M.run_post_update() Log:debug "Starting post-update hook" - - Log:debug "Re-generatring ftplugin template files" - package.loaded["lvim.lsp.templates"] = nil - require("lvim.lsp.templates").generate_templates() + M.reset_cache() Log:debug "Updating core plugins" - plugin_loader:sync_core_plugins() + require("lvim.plugin-loader").ensure_installed() if not in_headless then vim.schedule(function() + if package.loaded["nvim-treesitter"] then + vim.cmd [[ TSUpdateSync ]] + end -- TODO: add a changelog vim.notify("Update complete", vim.log.levels.INFO) - vim.cmd "LspRestart" + if package.loaded["lspconfig"] then + vim.cmd [[ LspRestart ]] + end end) end end |