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
|
2022-11-02 23:09:35 +01:00
|
|
|
function M:get_user_config_path()
|
2021-10-10 21:07:41 +02:00
|
|
|
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
|
2022-11-02 23:09:35 +01: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-05-26 16:06:49 +02:00
|
|
|
lvim.builtin.luasnip = {
|
|
|
|
sources = {
|
|
|
|
friendly_snippets = true,
|
|
|
|
},
|
|
|
|
}
|
2022-10-21 07:21:22 +02:00
|
|
|
|
2022-11-04 15:32:09 +01:00
|
|
|
require("lvim.config._deprecated").handle()
|
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
|
2022-11-02 23:09:35 +01:00
|
|
|
function M:load(config_path)
|
2022-10-04 19:23:52 +02:00
|
|
|
local autocmds = reload "lvim.core.autocmds"
|
2022-11-02 23:09:35 +01: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)
|
|
|
|
|
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
|
2022-11-02 23:09:35 +01:00
|
|
|
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
|