|
@@ -1,29 +1,39 @@
|
|
|
+local utils = require "lvim.utils"
|
|
|
+local Log = require "lvim.core.log"
|
|
|
+
|
|
|
local M = {}
|
|
|
|
|
|
---- Initialize lvim default configuration
|
|
|
--- Define lvim global variable
|
|
|
-function M:init(opts)
|
|
|
- opts = opts or {}
|
|
|
- self.path = opts.path
|
|
|
- local utils = require "utils"
|
|
|
+local user_config_dir = get_config_dir()
|
|
|
+local user_config_file = utils.join_paths(user_config_dir, "config.lua")
|
|
|
|
|
|
- require "config.defaults"
|
|
|
+-- Fallback config.lua to lv-config.lua
|
|
|
+if not utils.is_file(user_config_file) then
|
|
|
+ local lv_config = utils.join_paths(user_config_dir, "lv-config.lua")
|
|
|
+ Log:warn(string.format("[%s] not found, falling back to [%s]", user_config_file, lv_config))
|
|
|
+ user_config_file = lv_config
|
|
|
+end
|
|
|
|
|
|
- -- Fallback config.lua to lv-config.lua
|
|
|
- if not utils.is_file(self.path) then
|
|
|
- local lv_config = self.path:gsub("config.lua$", "lv-config.lua")
|
|
|
- print(self.path, "not found, falling back to", lv_config)
|
|
|
+function M:get_user_config_path()
|
|
|
+ return user_config_file
|
|
|
+end
|
|
|
|
|
|
- self.path = lv_config
|
|
|
+--- Initialize lvim default configuration
|
|
|
+-- Define lvim global variable
|
|
|
+function M:init()
|
|
|
+ if vim.tbl_isempty(lvim or {}) then
|
|
|
+ lvim = require "lvim.config.defaults"
|
|
|
+ local home_dir = vim.loop.os_homedir()
|
|
|
+ lvim.vsnip_dir = utils.join_paths(home_dir, ".config", "snippets")
|
|
|
+ lvim.database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 }
|
|
|
end
|
|
|
|
|
|
- local builtins = require "core.builtins"
|
|
|
- builtins.config(self)
|
|
|
+ local builtins = require "lvim.core.builtins"
|
|
|
+ builtins.config { user_config_file = user_config_file }
|
|
|
|
|
|
- local settings = require "config.settings"
|
|
|
+ local settings = require "lvim.config.settings"
|
|
|
settings.load_options()
|
|
|
|
|
|
- local lvim_lsp_config = require "lsp.config"
|
|
|
+ local lvim_lsp_config = require "lvim.lsp.config"
|
|
|
lvim.lsp = vim.deepcopy(lvim_lsp_config)
|
|
|
|
|
|
local supported_languages = {
|
|
@@ -121,7 +131,7 @@ function M:init(opts)
|
|
|
"zig",
|
|
|
}
|
|
|
|
|
|
- require("lsp.manager").init_defaults(supported_languages)
|
|
|
+ require("lvim.lsp.manager").init_defaults(supported_languages)
|
|
|
end
|
|
|
|
|
|
local function deprecation_notice()
|
|
@@ -131,7 +141,7 @@ local function deprecation_notice()
|
|
|
end
|
|
|
|
|
|
for lang, entry in pairs(lvim.lang) do
|
|
|
- local deprecated_config = entry["lsp"] or {}
|
|
|
+ local deprecated_config = entry["lvim.lsp"] or {}
|
|
|
if not vim.tbl_isempty(deprecated_config) then
|
|
|
local msg = string.format(
|
|
|
"Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
|
|
@@ -147,24 +157,46 @@ end
|
|
|
--- Override the configuration with a user provided one
|
|
|
-- @param config_path The path to the configuration overrides
|
|
|
function M:load(config_path)
|
|
|
- local autocmds = require "core.autocmds"
|
|
|
-
|
|
|
- config_path = config_path or self.path
|
|
|
- local ok, err = pcall(vim.cmd, "luafile " .. config_path)
|
|
|
+ config_path = config_path or self.get_user_config_path()
|
|
|
+ local ok, _ = pcall(dofile, config_path)
|
|
|
if not ok then
|
|
|
- print("Invalid configuration", config_path)
|
|
|
- print(err)
|
|
|
- return
|
|
|
+ Log:warn("Invalid configuration: " .. config_path)
|
|
|
end
|
|
|
|
|
|
deprecation_notice()
|
|
|
|
|
|
- self.path = config_path
|
|
|
-
|
|
|
+ local autocmds = require "lvim.core.autocmds"
|
|
|
autocmds.define_augroups(lvim.autocommands)
|
|
|
|
|
|
- local settings = require "config.settings"
|
|
|
+ local settings = require "lvim.config.settings"
|
|
|
settings.load_commands()
|
|
|
end
|
|
|
|
|
|
+--- Override the configuration with a user provided one
|
|
|
+-- @param config_path The path to the configuration overrides
|
|
|
+function M:reload()
|
|
|
+ local lvim_modules = {}
|
|
|
+ for module, _ in pairs(package.loaded) do
|
|
|
+ if module:match "lvim" then
|
|
|
+ package.loaded.module = nil
|
|
|
+ table.insert(lvim_modules, module)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ M:init()
|
|
|
+ M:load()
|
|
|
+
|
|
|
+ require("lvim.keymappings").setup() -- this should be done before loading the plugins
|
|
|
+ local plugins = require "lvim.plugins"
|
|
|
+ utils.toggle_autoformat()
|
|
|
+ local plugin_loader = require "lvim.plugin-loader"
|
|
|
+ plugin_loader:cache_reset()
|
|
|
+ plugin_loader:load { plugins, lvim.plugins }
|
|
|
+ vim.cmd ":PackerInstall"
|
|
|
+ vim.cmd ":PackerCompile"
|
|
|
+ -- vim.cmd ":PackerClean"
|
|
|
+ require("lvim.lsp").setup()
|
|
|
+ Log:info "Reloaded configuration"
|
|
|
+end
|
|
|
+
|
|
|
return M
|