bootstrap.lua 2.5 KB

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