2021-10-10 21:07:41 +02:00
|
|
|
local utils = require "lvim.utils"
|
|
|
|
local Log = require "lvim.core.log"
|
|
|
|
|
2021-09-13 11:28:15 +02:00
|
|
|
local M = {}
|
2021-10-10 21:07:41 +02:00
|
|
|
local user_config_dir = get_config_dir()
|
|
|
|
local user_config_file = utils.join_paths(user_config_dir, "config.lua")
|
2021-08-25 07:47:48 +02:00
|
|
|
|
2021-10-12 17:12:55 +02:00
|
|
|
---Get the full path to the user configuration file
|
|
|
|
---@return string
|
2021-10-10 21:07:41 +02:00
|
|
|
function M:get_user_config_path()
|
|
|
|
return user_config_file
|
|
|
|
end
|
2021-08-25 07:47:48 +02:00
|
|
|
|
2022-05-21 16:48:47 +02:00
|
|
|
--- Initialize lvim default configuration and variables
|
2021-10-10 21:07:41 +02:00
|
|
|
function M:init()
|
2022-05-21 16:48:47 +02:00
|
|
|
lvim = vim.deepcopy(require "lvim.config.defaults")
|
2021-09-13 11:28:15 +02:00
|
|
|
|
2021-11-18 16:04:34 +01:00
|
|
|
require("lvim.keymappings").load_defaults()
|
2021-11-10 21:45:52 +01:00
|
|
|
|
2021-10-10 21:07:41 +02:00
|
|
|
local builtins = require "lvim.core.builtins"
|
|
|
|
builtins.config { user_config_file = user_config_file }
|
2021-09-13 11:28:15 +02:00
|
|
|
|
2021-10-10 21:07:41 +02:00
|
|
|
local settings = require "lvim.config.settings"
|
2022-05-21 16:48:47 +02:00
|
|
|
settings.load_defaults()
|
2021-10-03 16:13:46 +02:00
|
|
|
|
2021-10-16 12:03:17 +02:00
|
|
|
local autocmds = require "lvim.core.autocmds"
|
2022-05-21 16:48:47 +02:00
|
|
|
autocmds.load_defaults()
|
2021-10-16 12:03:17 +02:00
|
|
|
|
2021-10-10 21:07:41 +02:00
|
|
|
local lvim_lsp_config = require "lvim.lsp.config"
|
2022-05-21 16:48:47 +02:00
|
|
|
lvim.lsp = vim.deepcopy(lvim_lsp_config)
|
2021-10-03 16:13:46 +02:00
|
|
|
|
2022-03-19 20:02:45 +01:00
|
|
|
---@deprecated replaced with lvim.builtin.alpha
|
|
|
|
lvim.builtin.dashboard = {
|
|
|
|
active = false,
|
|
|
|
on_config_done = nil,
|
|
|
|
search_handler = "",
|
|
|
|
disable_at_vim_enter = 0,
|
|
|
|
session_directory = "",
|
|
|
|
custom_header = {},
|
|
|
|
custom_section = {},
|
|
|
|
footer = {},
|
|
|
|
}
|
2022-05-26 16:06:49 +02:00
|
|
|
|
|
|
|
lvim.builtin.luasnip = {
|
|
|
|
sources = {
|
|
|
|
friendly_snippets = true,
|
|
|
|
},
|
|
|
|
}
|
2022-10-21 07:21:22 +02:00
|
|
|
|
|
|
|
---@deprecated
|
|
|
|
lvim.builtin.notify = {
|
2022-11-01 10:37:50 +01:00
|
|
|
active = false,
|
2022-10-21 07:21:22 +02:00
|
|
|
}
|
2021-08-25 07:47:48 +02:00
|
|
|
end
|
|
|
|
|
2021-10-23 18:12:11 +02:00
|
|
|
local function handle_deprecated_settings()
|
2022-04-14 20:47:22 +02:00
|
|
|
local function deprecation_notice(setting, new_setting)
|
2021-10-23 18:12:11 +02:00
|
|
|
local in_headless = #vim.api.nvim_list_uis() == 0
|
|
|
|
if in_headless then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-04-14 20:47:22 +02:00
|
|
|
local msg = string.format(
|
|
|
|
"Deprecation notice: [%s] setting is no longer supported. %s",
|
|
|
|
setting,
|
|
|
|
new_setting or "See https://github.com/LunarVim/LunarVim#breaking-changes"
|
|
|
|
)
|
2021-10-23 18:12:11 +02:00
|
|
|
vim.schedule(function()
|
2022-04-14 20:47:22 +02:00
|
|
|
vim.notify_once(msg, vim.log.levels.WARN)
|
2021-10-23 18:12:11 +02:00
|
|
|
end)
|
2021-10-03 22:23:13 +02:00
|
|
|
end
|
|
|
|
|
2021-10-23 18:12:11 +02:00
|
|
|
---lvim.lang.FOO.lsp
|
2021-10-03 22:23:13 +02:00
|
|
|
for lang, entry in pairs(lvim.lang) do
|
2021-11-06 09:23:59 +01:00
|
|
|
local deprecated_config = entry.formatters or entry.linters or {}
|
2021-10-03 22:23:13 +02:00
|
|
|
if not vim.tbl_isempty(deprecated_config) then
|
2021-11-06 09:23:59 +01:00
|
|
|
deprecation_notice(string.format("lvim.lang.%s", lang))
|
2021-10-03 22:23:13 +02:00
|
|
|
end
|
|
|
|
end
|
2021-12-23 10:03:15 +01:00
|
|
|
|
2022-04-14 20:47:22 +02:00
|
|
|
-- lvim.lsp.override
|
|
|
|
if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
|
|
|
|
deprecation_notice("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
|
|
|
|
vim.tbl_map(function(c)
|
|
|
|
if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then
|
|
|
|
table.insert(lvim.lsp.automatic_configuration.skipped_servers, c)
|
|
|
|
end
|
|
|
|
end, lvim.lsp.override)
|
|
|
|
end
|
|
|
|
|
2021-12-23 10:03:15 +01:00
|
|
|
-- lvim.lsp.popup_border
|
|
|
|
if vim.tbl_contains(vim.tbl_keys(lvim.lsp), "popup_border") then
|
|
|
|
deprecation_notice "lvim.lsp.popup_border"
|
|
|
|
end
|
2022-03-19 20:02:45 +01:00
|
|
|
|
|
|
|
-- dashboard.nvim
|
|
|
|
if lvim.builtin.dashboard.active then
|
2022-04-14 20:47:22 +02:00
|
|
|
deprecation_notice("lvim.builtin.dashboard", "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
|
2022-03-19 20:02:45 +01:00
|
|
|
end
|
2022-05-21 16:48:47 +02:00
|
|
|
|
2022-10-21 07:21:22 +02:00
|
|
|
-- notify.nvim
|
|
|
|
if lvim.builtin.notify.active then
|
|
|
|
deprecation_notice("lvim.builtin.notify", "See LunarVim#3294")
|
|
|
|
end
|
|
|
|
|
2022-05-21 16:48:47 +02:00
|
|
|
if lvim.autocommands.custom_groups then
|
|
|
|
deprecation_notice(
|
|
|
|
"lvim.autocommands.custom_groups",
|
|
|
|
"Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax"
|
|
|
|
)
|
|
|
|
end
|
2022-08-09 10:41:17 +02:00
|
|
|
|
|
|
|
if lvim.lsp.automatic_servers_installation then
|
|
|
|
deprecation_notice(
|
|
|
|
"lvim.lsp.automatic_servers_installation",
|
|
|
|
"Use `lvim.lsp.installer.setup.automatic_installation` instead"
|
|
|
|
)
|
|
|
|
end
|
2021-10-03 22:23:13 +02:00
|
|
|
end
|
|
|
|
|
2021-08-25 07:47:48 +02:00
|
|
|
--- Override the configuration with a user provided one
|
|
|
|
-- @param config_path The path to the configuration overrides
|
|
|
|
function M:load(config_path)
|
2022-10-04 19:23:52 +02:00
|
|
|
local autocmds = reload "lvim.core.autocmds"
|
2022-05-21 16:48:47 +02:00
|
|
|
config_path = config_path or self:get_user_config_path()
|
2021-10-12 17:33:41 +02:00
|
|
|
local ok, err = pcall(dofile, config_path)
|
2021-08-25 07:47:48 +02:00
|
|
|
if not ok then
|
2021-10-12 17:12:55 +02:00
|
|
|
if utils.is_file(user_config_file) then
|
2021-10-12 17:33:41 +02:00
|
|
|
Log:warn("Invalid configuration: " .. err)
|
2021-10-12 17:12:55 +02:00
|
|
|
else
|
2022-10-07 04:51:09 +02:00
|
|
|
vim.notify_once(
|
|
|
|
string.format("User-configuration not found. Creating an example configuration in %s", config_path)
|
|
|
|
)
|
|
|
|
local example_config = join_paths(get_lvim_base_dir(), "utils", "installer", "config.example.lua")
|
|
|
|
vim.loop.fs_copyfile(example_config, config_path)
|
2021-10-12 17:12:55 +02:00
|
|
|
end
|
2021-08-25 07:47:48 +02:00
|
|
|
end
|
|
|
|
|
2022-10-06 16:12:12 +02:00
|
|
|
Log:set_level(lvim.log.level)
|
|
|
|
|
2021-10-23 18:12:11 +02:00
|
|
|
handle_deprecated_settings()
|
2021-10-03 22:23:13 +02:00
|
|
|
|
2022-05-21 16:48:47 +02:00
|
|
|
autocmds.define_autocmds(lvim.autocommands)
|
2021-08-26 08:40:25 +02:00
|
|
|
|
2021-11-03 12:32:10 +01:00
|
|
|
vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
|
2021-11-10 21:45:52 +01:00
|
|
|
|
2022-10-04 19:23:52 +02:00
|
|
|
reload("lvim.keymappings").load(lvim.keys)
|
2021-11-03 12:32:10 +01:00
|
|
|
|
2022-01-04 09:47:59 +01:00
|
|
|
if lvim.transparent_window then
|
|
|
|
autocmds.enable_transparent_mode()
|
|
|
|
end
|
2022-10-17 14:06:12 +02:00
|
|
|
|
|
|
|
if lvim.reload_config_on_save then
|
|
|
|
autocmds.enable_reload_config_on_save()
|
|
|
|
end
|
2021-08-25 07:47:48 +02:00
|
|
|
end
|
|
|
|
|
2021-10-10 21:07:41 +02:00
|
|
|
--- Override the configuration with a user provided one
|
|
|
|
-- @param config_path The path to the configuration overrides
|
|
|
|
function M:reload()
|
2022-04-03 14:32:52 +02:00
|
|
|
vim.schedule(function()
|
2022-10-04 19:23:52 +02:00
|
|
|
reload("lvim.utils.hooks").run_pre_reload()
|
2021-10-10 21:07:41 +02:00
|
|
|
|
2022-04-03 14:32:52 +02:00
|
|
|
M:load()
|
2021-10-10 21:07:41 +02:00
|
|
|
|
2022-10-04 19:23:52 +02:00
|
|
|
reload("lvim.core.autocmds").configure_format_on_save()
|
2021-12-09 17:08:53 +01:00
|
|
|
|
2022-10-04 19:23:52 +02:00
|
|
|
local plugins = reload "lvim.plugins"
|
|
|
|
local plugin_loader = reload "lvim.plugin-loader"
|
2021-12-09 17:08:53 +01:00
|
|
|
|
2022-04-03 14:32:52 +02:00
|
|
|
plugin_loader.reload { plugins, lvim.plugins }
|
2022-10-04 19:23:52 +02:00
|
|
|
reload("lvim.core.theme").setup()
|
|
|
|
reload("lvim.utils.hooks").run_post_reload()
|
2022-04-03 14:32:52 +02:00
|
|
|
end)
|
2021-10-10 21:07:41 +02:00
|
|
|
end
|
|
|
|
|
2021-08-25 07:47:48 +02:00
|
|
|
return M
|