hooks.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local M = {}
  2. local plugin_loader = require "lvim.plugin-loader"
  3. local Log = require "lvim.core.log"
  4. local in_headless = #vim.api.nvim_list_uis() == 0
  5. function M.run_pre_update()
  6. Log:debug "Starting pre-update hook"
  7. _G.__luacache.clear_cache()
  8. if package.loaded["lspconfig"] then
  9. vim.cmd [[ LspStop ]]
  10. end
  11. end
  12. ---Reset any startup cache files used by Packer and Impatient
  13. ---It also forces regenerating any template ftplugin files
  14. ---Tip: Useful for clearing any outdated settings
  15. function M.reset_cache()
  16. _G.__luacache.clear_cache()
  17. require("lvim.plugin-loader").recompile()
  18. package.loaded["lvim.lsp.templates"] = nil
  19. Log:debug "Re-generatring ftplugin template files"
  20. require("lvim.lsp.templates").generate_templates()
  21. end
  22. function M.run_post_update()
  23. Log:debug "Starting post-update hook"
  24. Log:debug "Re-generatring ftplugin template files"
  25. package.loaded["lvim.lsp.templates"] = nil
  26. require("lvim.lsp.templates").generate_templates()
  27. Log:debug "Updating core plugins"
  28. plugin_loader:sync_core_plugins()
  29. if not in_headless then
  30. vim.schedule(function()
  31. if package.loaded["nvim-treesitter"] then
  32. vim.cmd [[ TSUpdateSync ]]
  33. end
  34. -- TODO: add a changelog
  35. vim.notify("Update complete", vim.log.levels.INFO)
  36. if package.loaded["lspconfig"] then
  37. vim.cmd [[ LspRestart ]]
  38. end
  39. end)
  40. end
  41. end
  42. return M