init.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. local utils = require "lvim.utils"
  2. local Log = require "lvim.core.log"
  3. local M = {}
  4. local user_config_dir = get_config_dir()
  5. local user_config_file = utils.join_paths(user_config_dir, "config.lua")
  6. ---Get the full path to the user configuration file
  7. ---@return string
  8. function M:get_user_config_path()
  9. return user_config_file
  10. end
  11. --- Initialize lvim default configuration
  12. -- Define lvim global variable
  13. function M:init()
  14. if vim.tbl_isempty(lvim or {}) then
  15. lvim = require "lvim.config.defaults"
  16. local home_dir = vim.loop.os_homedir()
  17. lvim.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets")
  18. lvim.database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 }
  19. end
  20. local builtins = require "lvim.core.builtins"
  21. builtins.config { user_config_file = user_config_file }
  22. local settings = require "lvim.config.settings"
  23. settings.load_options()
  24. local autocmds = require "lvim.core.autocmds"
  25. lvim.autocommands = autocmds.load_augroups()
  26. local lvim_lsp_config = require "lvim.lsp.config"
  27. lvim.lsp = vim.deepcopy(lvim_lsp_config)
  28. local supported_languages = require "lvim.config.supported_languages"
  29. require("lvim.lsp.manager").init_defaults(supported_languages)
  30. end
  31. local function handle_deprecated_settings()
  32. local function deprecation_notice(setting)
  33. local in_headless = #vim.api.nvim_list_uis() == 0
  34. if in_headless then
  35. return
  36. end
  37. local msg = string.format(
  38. "Deprecation notice: [%s] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
  39. setting
  40. )
  41. vim.schedule(function()
  42. vim.notify(msg, vim.log.levels.WARN)
  43. end)
  44. end
  45. ---lvim.lang.FOO.lsp
  46. for lang, entry in pairs(lvim.lang) do
  47. local deprecated_config = entry["lsp"] or {}
  48. if not vim.tbl_isempty(deprecated_config) then
  49. deprecation_notice(string.format("lvim.lang.%s.lsp", lang))
  50. end
  51. end
  52. end
  53. --- Override the configuration with a user provided one
  54. -- @param config_path The path to the configuration overrides
  55. function M:load(config_path)
  56. local autocmds = require "lvim.core.autocmds"
  57. config_path = config_path or self.get_user_config_path()
  58. local ok, err = pcall(dofile, config_path)
  59. if not ok then
  60. if utils.is_file(user_config_file) then
  61. Log:warn("Invalid configuration: " .. err)
  62. else
  63. Log:warn(string.format("Unable to find configuration file [%s]", config_path))
  64. end
  65. end
  66. handle_deprecated_settings()
  67. autocmds.define_augroups(lvim.autocommands)
  68. local settings = require "lvim.config.settings"
  69. settings.load_commands()
  70. end
  71. --- Override the configuration with a user provided one
  72. -- @param config_path The path to the configuration overrides
  73. function M:reload()
  74. local lvim_modules = {}
  75. for module, _ in pairs(package.loaded) do
  76. if module:match "lvim" then
  77. package.loaded.module = nil
  78. table.insert(lvim_modules, module)
  79. end
  80. end
  81. M:init()
  82. M:load()
  83. require("lvim.keymappings").setup() -- this should be done before loading the plugins
  84. local plugins = require "lvim.plugins"
  85. utils.toggle_autoformat()
  86. local plugin_loader = require "lvim.plugin-loader"
  87. plugin_loader.cache_clear()
  88. plugin_loader.load { plugins, lvim.plugins }
  89. vim.cmd ":PackerInstall"
  90. vim.cmd ":PackerCompile"
  91. -- vim.cmd ":PackerClean"
  92. require("lvim.lsp").setup()
  93. Log:info "Reloaded configuration"
  94. end
  95. return M