bootstrap.lua 2.5 KB

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