hooks.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. vim.cmd "LspStop"
  9. end
  10. ---Reset any startup cache files used by Packer and Impatient
  11. ---It also forces regenerating any template ftplugin files
  12. ---Tip: Useful for clearing any outdated settings
  13. function M.reset_cache()
  14. _G.__luacache.clear_cache()
  15. require("lvim.plugin-loader").recompile()
  16. package.loaded["lvim.lsp.templates"] = nil
  17. Log:debug "Re-generatring ftplugin template files"
  18. require("lvim.lsp.templates").generate_templates()
  19. end
  20. function M.run_post_update()
  21. Log:debug "Starting post-update hook"
  22. Log:debug "Re-generatring ftplugin template files"
  23. package.loaded["lvim.lsp.templates"] = nil
  24. require("lvim.lsp.templates").generate_templates()
  25. Log:debug "Updating core plugins"
  26. plugin_loader:sync_core_plugins()
  27. if not in_headless then
  28. vim.schedule(function()
  29. -- TODO: add a changelog
  30. vim.notify("Update complete", vim.log.levels.INFO)
  31. vim.cmd "LspRestart"
  32. end)
  33. end
  34. end
  35. return M