hooks.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. local in_headless = #vim.api.nvim_list_uis() == 0
  4. function M.run_pre_update()
  5. Log:debug "Starting pre-update hook"
  6. end
  7. function M.run_pre_reload()
  8. Log:debug "Starting pre-reload hook"
  9. end
  10. function M.run_on_packer_complete()
  11. vim.schedule(function()
  12. if not in_headless then
  13. -- colorscheme must get called after plugins are loaded or it will break new installs.
  14. vim.g.colors_name = lvim.colorscheme
  15. vim.cmd("colorscheme " .. lvim.colorscheme)
  16. else
  17. Log:debug "Packer operation complete"
  18. end
  19. end)
  20. end
  21. function M.run_post_reload()
  22. Log:debug "Starting post-reload hook"
  23. M.reset_cache()
  24. vim.schedule(function()
  25. if not in_headless then
  26. Log:info "Reloaded configuration"
  27. end
  28. end)
  29. end
  30. ---Reset any startup cache files used by Packer and Impatient
  31. ---It also forces regenerating any template ftplugin files
  32. ---Tip: Useful for clearing any outdated settings
  33. function M.reset_cache()
  34. local impatient = _G.__luacache
  35. if impatient then
  36. impatient.clear_cache()
  37. end
  38. local lvim_modules = {}
  39. for module, _ in pairs(package.loaded) do
  40. if module:match "lvim.core" or module:match "lvim.lsp" then
  41. package.loaded[module] = nil
  42. table.insert(lvim_modules, module)
  43. end
  44. end
  45. Log:trace(string.format("Cache invalidated for core modules: { %s }", table.concat(lvim_modules, ", ")))
  46. require("lvim.lsp.templates").generate_templates()
  47. end
  48. function M.run_post_update()
  49. Log:debug "Starting post-update hook"
  50. M.reset_cache()
  51. Log:debug "Syncing core plugins"
  52. require("lvim.plugin-loader").sync_core_plugins()
  53. if not in_headless then
  54. vim.schedule(function()
  55. if package.loaded["nvim-treesitter"] then
  56. vim.cmd [[ TSUpdateSync ]]
  57. end
  58. -- TODO: add a changelog
  59. vim.notify("Update complete", vim.log.levels.INFO)
  60. end)
  61. end
  62. end
  63. return M