init.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. end
  86. --- Override the configuration with a user provided one
  87. -- @param config_path The path to the configuration overrides
  88. function M:load(config_path)
  89. local autocmds = require "lvim.core.autocmds"
  90. config_path = config_path or self:get_user_config_path()
  91. local ok, err = pcall(dofile, config_path)
  92. if not ok then
  93. if utils.is_file(user_config_file) then
  94. Log:warn("Invalid configuration: " .. err)
  95. else
  96. vim.notify_once(string.format("Unable to find configuration file [%s]", config_path), vim.log.levels.WARN)
  97. end
  98. end
  99. handle_deprecated_settings()
  100. autocmds.define_autocmds(lvim.autocommands)
  101. vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
  102. require("lvim.keymappings").load(lvim.keys)
  103. if lvim.transparent_window then
  104. autocmds.enable_transparent_mode()
  105. end
  106. end
  107. --- Override the configuration with a user provided one
  108. -- @param config_path The path to the configuration overrides
  109. function M:reload()
  110. vim.schedule(function()
  111. require_clean("lvim.utils.hooks").run_pre_reload()
  112. M:load()
  113. require("lvim.core.autocmds").configure_format_on_save()
  114. local plugins = require "lvim.plugins"
  115. local plugin_loader = require "lvim.plugin-loader"
  116. plugin_loader.reload { plugins, lvim.plugins }
  117. require_clean("lvim.utils.hooks").run_post_reload()
  118. end)
  119. end
  120. return M