bootstrap.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. local M = {}
  2. -- It's not safe to require 'utils' without adjusting the runtimepath
  3. function _G.join_paths(...)
  4. local uv = vim.loop
  5. local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/"
  6. local result = table.concat({ ... }, path_sep)
  7. return result
  8. end
  9. function _G.get_runtime_dir()
  10. local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR"
  11. if not lvim_runtime_dir then
  12. -- when nvim is used directly
  13. return vim.fn.stdpath "config"
  14. end
  15. return lvim_runtime_dir
  16. end
  17. function _G.get_config_dir()
  18. local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR"
  19. if not lvim_config_dir then
  20. return vim.fn.stdpath "config"
  21. end
  22. return lvim_config_dir
  23. end
  24. function _G.get_cache_dir()
  25. local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR"
  26. if not lvim_cache_dir then
  27. return vim.fn.stdpath "cache"
  28. end
  29. return lvim_cache_dir
  30. end
  31. function _G.get_version(type)
  32. local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tag")
  33. if type == "short" then
  34. return vim.fn.split(lvim_full_ver, "-")[1]
  35. else
  36. return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1)
  37. end
  38. end
  39. function M:init()
  40. self.runtime_dir = get_runtime_dir()
  41. self.config_dir = get_config_dir()
  42. self.cache_path = get_cache_dir()
  43. self.pack_dir = join_paths(self.runtime_dir, "site", "pack")
  44. self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim")
  45. self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua")
  46. if os.getenv "LUNARVIM_RUNTIME_DIR" then
  47. vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site"))
  48. vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site", "after"))
  49. vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site"))
  50. vim.opt.rtp:append(join_paths(self.runtime_dir, "site", "after"))
  51. vim.opt.rtp:remove(vim.fn.stdpath "config")
  52. vim.opt.rtp:remove(join_paths(vim.fn.stdpath "config", "after"))
  53. vim.opt.rtp:prepend(self.config_dir)
  54. vim.opt.rtp:append(join_paths(self.config_dir, "after"))
  55. -- TODO: we need something like this: vim.opt.packpath = vim.opt.rtp
  56. vim.cmd [[let &packpath = &runtimepath]]
  57. vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add"))
  58. end
  59. -- FIXME: currently unreliable in unit-tests
  60. if not os.getenv "LVIM_TEST_ENV" then
  61. vim.fn.mkdir(vim.fn.stdpath "cache", "p")
  62. require("impatient").setup {
  63. path = vim.fn.stdpath "cache" .. "/lvim_cache",
  64. enable_profiling = true,
  65. }
  66. end
  67. local config = require "config"
  68. config:init {
  69. path = join_paths(self.config_dir, "config.lua"),
  70. }
  71. require("plugin-loader"):init {
  72. package_root = self.pack_dir,
  73. install_path = self.packer_install_dir,
  74. }
  75. return self
  76. end
  77. return M