init.lua 4.1 KB

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