bootstrap.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 --tags")
  33. if string.match(lvim_full_ver, "%d") == nil then
  34. return nil
  35. end
  36. if type == "short" then
  37. return vim.fn.split(lvim_full_ver, "-")[1]
  38. else
  39. return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1)
  40. end
  41. end
  42. function M:init()
  43. self.runtime_dir = get_runtime_dir()
  44. self.config_dir = get_config_dir()
  45. self.cache_path = get_cache_dir()
  46. self.pack_dir = join_paths(self.runtime_dir, "site", "pack")
  47. self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim")
  48. self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua")
  49. if os.getenv "LUNARVIM_RUNTIME_DIR" then
  50. vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site"))
  51. vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site", "after"))
  52. vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site"))
  53. vim.opt.rtp:append(join_paths(self.runtime_dir, "site", "after"))
  54. vim.opt.rtp:remove(vim.fn.stdpath "config")
  55. vim.opt.rtp:remove(join_paths(vim.fn.stdpath "config", "after"))
  56. vim.opt.rtp:prepend(self.config_dir)
  57. vim.opt.rtp:append(join_paths(self.config_dir, "after"))
  58. -- TODO: we need something like this: vim.opt.packpath = vim.opt.rtp
  59. vim.cmd [[let &packpath = &runtimepath]]
  60. vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add"))
  61. end
  62. -- FIXME: currently unreliable in unit-tests
  63. if not os.getenv "LVIM_TEST_ENV" then
  64. vim.fn.mkdir(vim.fn.stdpath "cache", "p")
  65. require("impatient").setup {
  66. path = vim.fn.stdpath "cache" .. "/lvim_cache",
  67. enable_profiling = true,
  68. }
  69. end
  70. local config = require "config"
  71. config:init {
  72. path = join_paths(self.config_dir, "config.lua"),
  73. }
  74. require("plugin-loader"):init {
  75. package_root = self.pack_dir,
  76. install_path = self.packer_install_dir,
  77. }
  78. return self
  79. end
  80. return M