init.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. end
  40. local function handle_deprecated_settings()
  41. local function deprecation_notice(setting, new_setting)
  42. local in_headless = #vim.api.nvim_list_uis() == 0
  43. if in_headless then
  44. return
  45. end
  46. local msg = string.format(
  47. "Deprecation notice: [%s] setting is no longer supported. %s",
  48. setting,
  49. new_setting or "See https://github.com/LunarVim/LunarVim#breaking-changes"
  50. )
  51. vim.schedule(function()
  52. vim.notify_once(msg, vim.log.levels.WARN)
  53. end)
  54. end
  55. ---lvim.lang.FOO.lsp
  56. for lang, entry in pairs(lvim.lang) do
  57. local deprecated_config = entry.formatters or entry.linters or {}
  58. if not vim.tbl_isempty(deprecated_config) then
  59. deprecation_notice(string.format("lvim.lang.%s", lang))
  60. end
  61. end
  62. -- lvim.lsp.override
  63. if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
  64. deprecation_notice("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
  65. vim.tbl_map(function(c)
  66. if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then
  67. table.insert(lvim.lsp.automatic_configuration.skipped_servers, c)
  68. end
  69. end, lvim.lsp.override)
  70. end
  71. -- lvim.lsp.popup_border
  72. if vim.tbl_contains(vim.tbl_keys(lvim.lsp), "popup_border") then
  73. deprecation_notice "lvim.lsp.popup_border"
  74. end
  75. -- dashboard.nvim
  76. if lvim.builtin.dashboard.active then
  77. deprecation_notice("lvim.builtin.dashboard", "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
  78. end
  79. if lvim.autocommands.custom_groups then
  80. deprecation_notice(
  81. "lvim.autocommands.custom_groups",
  82. "Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax"
  83. )
  84. end
  85. if lvim.lsp.automatic_servers_installation then
  86. deprecation_notice(
  87. "lvim.lsp.automatic_servers_installation",
  88. "Use `lvim.lsp.installer.setup.automatic_installation` instead"
  89. )
  90. end
  91. end
  92. --- Override the configuration with a user provided one
  93. -- @param config_path The path to the configuration overrides
  94. function M:load(config_path)
  95. local autocmds = reload "lvim.core.autocmds"
  96. config_path = config_path or self:get_user_config_path()
  97. local ok, err = pcall(dofile, config_path)
  98. if not ok then
  99. if utils.is_file(user_config_file) then
  100. Log:warn("Invalid configuration: " .. err)
  101. else
  102. vim.notify_once(string.format("Unable to find configuration file [%s]", config_path), vim.log.levels.WARN)
  103. end
  104. end
  105. handle_deprecated_settings()
  106. autocmds.define_autocmds(lvim.autocommands)
  107. vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
  108. reload("lvim.keymappings").load(lvim.keys)
  109. if lvim.transparent_window then
  110. autocmds.enable_transparent_mode()
  111. end
  112. end
  113. --- Override the configuration with a user provided one
  114. -- @param config_path The path to the configuration overrides
  115. function M:reload()
  116. vim.schedule(function()
  117. reload("lvim.utils.hooks").run_pre_reload()
  118. M:load()
  119. reload("lvim.core.autocmds").configure_format_on_save()
  120. local plugins = reload "lvim.plugins"
  121. local plugin_loader = reload "lvim.plugin-loader"
  122. plugin_loader.reload { plugins, lvim.plugins }
  123. reload("lvim.core.theme").setup()
  124. reload("lvim.utils.hooks").run_post_reload()
  125. end)
  126. end
  127. return M