hooks.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. local in_headless = #vim.api.nvim_list_uis() == 0
  4. local plugin_loader = require "lvim.plugin-loader"
  5. function M.run_pre_update()
  6. Log:debug "Starting pre-update hook"
  7. end
  8. function M.run_pre_reload()
  9. Log:debug "Starting pre-reload hook"
  10. end
  11. -- TODO: convert to lazy.nvim
  12. -- function M.run_on_packer_complete()
  13. -- -- FIXME(kylo252): nvim-tree.lua/lua/nvim-tree/view.lua:442: Invalid window id
  14. -- vim.g.colors_name = lvim.colorscheme
  15. -- pcall(vim.cmd.colorscheme, lvim.colorscheme)
  16. -- end
  17. function M.run_post_reload()
  18. Log:debug "Starting post-reload hook"
  19. end
  20. ---Reset any startup cache files used by lazy.nvim
  21. ---It also forces regenerating any template ftplugin files
  22. ---Tip: Useful for clearing any outdated settings
  23. function M.reset_cache()
  24. plugin_loader.reset_cache()
  25. local lvim_modules = {}
  26. for module, _ in pairs(package.loaded) do
  27. if module:match "lvim.core" or module:match "lvim.lsp" then
  28. package.loaded[module] = nil
  29. table.insert(lvim_modules, module)
  30. end
  31. end
  32. Log:trace(string.format("Cache invalidated for core modules: { %s }", table.concat(lvim_modules, ", ")))
  33. require("lvim.lsp.templates").generate_templates()
  34. end
  35. function M.run_post_update()
  36. Log:debug "Starting post-update hook"
  37. if vim.fn.has "nvim-0.8" ~= 1 then
  38. local compat_tag = "1.1.4"
  39. vim.notify(
  40. "Please upgrade your Neovim base installation. Newer version of Lunarvim requires v0.7+",
  41. vim.log.levels.WARN
  42. )
  43. vim.wait(1000)
  44. local ret = reload("lvim.utils.git").switch_lvim_branch(compat_tag)
  45. if ret then
  46. vim.notify("Reverted to the last known compatible version: " .. compat_tag, vim.log.levels.WARN)
  47. end
  48. return
  49. end
  50. M.reset_cache()
  51. Log:debug "Syncing core plugins"
  52. 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