init.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 and variables
  12. function M:init()
  13. lvim = vim.deepcopy(require "lvim.config.defaults")
  14. require("lvim.keymappings").load_defaults()
  15. local builtins = require "lvim.core.builtins"
  16. builtins.config { user_config_file = user_config_file }
  17. local settings = require "lvim.config.settings"
  18. settings.load_defaults()
  19. local autocmds = require "lvim.core.autocmds"
  20. autocmds.load_defaults()
  21. local lvim_lsp_config = require "lvim.lsp.config"
  22. lvim.lsp = vim.deepcopy(lvim_lsp_config)
  23. ---@deprecated replaced with lvim.builtin.alpha
  24. lvim.builtin.dashboard = {
  25. active = false,
  26. on_config_done = nil,
  27. search_handler = "",
  28. disable_at_vim_enter = 0,
  29. session_directory = "",
  30. custom_header = {},
  31. custom_section = {},
  32. footer = {},
  33. }
  34. lvim.builtin.luasnip = {
  35. sources = {
  36. friendly_snippets = true,
  37. },
  38. }
  39. ---@deprecated
  40. lvim.builtin.notify = {
  41. active = false,
  42. }
  43. end
  44. local function handle_deprecated_settings()
  45. local function deprecation_notice(setting, new_setting)
  46. local in_headless = #vim.api.nvim_list_uis() == 0
  47. if in_headless then
  48. return
  49. end
  50. local msg = string.format(
  51. "Deprecation notice: [%s] setting is no longer supported. %s",
  52. setting,
  53. new_setting or "See https://github.com/LunarVim/LunarVim#breaking-changes"
  54. )
  55. vim.schedule(function()
  56. vim.notify_once(msg, vim.log.levels.WARN)
  57. end)
  58. end
  59. ---lvim.lang.FOO.lsp
  60. for lang, entry in pairs(lvim.lang) do
  61. local deprecated_config = entry.formatters or entry.linters or {}
  62. if not vim.tbl_isempty(deprecated_config) then
  63. deprecation_notice(string.format("lvim.lang.%s", lang))
  64. end
  65. end
  66. -- lvim.lsp.override
  67. if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
  68. deprecation_notice("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
  69. vim.tbl_map(function(c)
  70. if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then
  71. table.insert(lvim.lsp.automatic_configuration.skipped_servers, c)
  72. end
  73. end, lvim.lsp.override)
  74. end
  75. -- lvim.lsp.popup_border
  76. if vim.tbl_contains(vim.tbl_keys(lvim.lsp), "popup_border") then
  77. deprecation_notice "lvim.lsp.popup_border"
  78. end
  79. -- dashboard.nvim
  80. if lvim.builtin.dashboard.active then
  81. deprecation_notice("lvim.builtin.dashboard", "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
  82. end
  83. -- notify.nvim
  84. if lvim.builtin.notify.active then
  85. deprecation_notice("lvim.builtin.notify", "See LunarVim#3294")
  86. end
  87. if lvim.autocommands.custom_groups then
  88. deprecation_notice(
  89. "lvim.autocommands.custom_groups",
  90. "Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax"
  91. )
  92. end
  93. if lvim.lsp.automatic_servers_installation then
  94. deprecation_notice(
  95. "lvim.lsp.automatic_servers_installation",
  96. "Use `lvim.lsp.installer.setup.automatic_installation` instead"
  97. )
  98. end
  99. end
  100. --- Override the configuration with a user provided one
  101. -- @param config_path The path to the configuration overrides
  102. function M:load(config_path)
  103. local autocmds = reload "lvim.core.autocmds"
  104. config_path = config_path or self:get_user_config_path()
  105. local ok, err = pcall(dofile, config_path)
  106. if not ok then
  107. if utils.is_file(user_config_file) then
  108. Log:warn("Invalid configuration: " .. err)
  109. else
  110. vim.notify_once(
  111. string.format("User-configuration not found. Creating an example configuration in %s", config_path)
  112. )
  113. local example_config = join_paths(get_lvim_base_dir(), "utils", "installer", "config.example.lua")
  114. vim.loop.fs_copyfile(example_config, config_path)
  115. end
  116. end
  117. Log:set_level(lvim.log.level)
  118. handle_deprecated_settings()
  119. autocmds.define_autocmds(lvim.autocommands)
  120. vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
  121. reload("lvim.keymappings").load(lvim.keys)
  122. if lvim.transparent_window then
  123. autocmds.enable_transparent_mode()
  124. end
  125. if lvim.reload_config_on_save then
  126. autocmds.enable_reload_config_on_save()
  127. end
  128. end
  129. --- Override the configuration with a user provided one
  130. -- @param config_path The path to the configuration overrides
  131. function M:reload()
  132. vim.schedule(function()
  133. reload("lvim.utils.hooks").run_pre_reload()
  134. M:load()
  135. reload("lvim.core.autocmds").configure_format_on_save()
  136. local plugins = reload "lvim.plugins"
  137. local plugin_loader = reload "lvim.plugin-loader"
  138. plugin_loader.reload { plugins, lvim.plugins }
  139. reload("lvim.core.theme").setup()
  140. reload("lvim.utils.hooks").run_post_reload()
  141. end)
  142. end
  143. return M