refactor(config): moved loading of options, keymaps and autocmds to lazyvim.config

This commit is contained in:
Folke Lemaitre
2023-01-10 10:20:28 +01:00
parent 7b943822db
commit dcf520f3a7
4 changed files with 38 additions and 34 deletions

View File

@ -71,6 +71,16 @@ function M.setup(opts)
{ title = "LazyVim" }
)
end
-- autocmds and keymaps can wait to load
vim.api.nvim_create_autocmd("User", {
group = vim.api.nvim_create_augroup("LazyVim", { clear = true }),
pattern = "VeryLazy",
callback = function()
M.load("autocmds")
M.load("keymaps")
end,
})
end
---@param range? string
@ -79,6 +89,25 @@ function M.has(range)
return Semver.range(range or M.lazy_version):matches(require("lazy.core.config").version or "0.0.0")
end
---@param name "autocmds" | "options" | "keymaps"
function M.load(name)
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
Util.try(function()
require(mod)
end, {
msg = "Failed loading " .. mod,
on_error = function(msg)
local modpath = require("lazy.core.cache").find(mod)
if modpath then
Util.error(msg)
end
end,
})
end
end
setmetatable(M, {
__index = function(_, key)
if options == nil then

View File

@ -1,33 +0,0 @@
local function load(name)
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
Util.try(function()
require(mod)
end, {
msg = "Failed loading " .. mod,
on_error = function(msg)
local modpath = require("lazy.core.cache").find(mod)
if modpath then
Util.error(msg)
end
end,
})
end
end
-- load options here, before lazy init while sourcing plugin modules
-- this is needed to make sure options will be correctly applied
-- after installing missing plugins
load("options")
-- autocmds and keymaps can wait to load
vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
callback = function()
load("autocmds")
load("keymaps")
end,
})
return {}

View File

@ -5,7 +5,9 @@ local specs = {
-- only add for >=9.0.1, since there's an endless loop in earlier versions
if require("lazyvim.config").has(">=9.1.0") then
specs[#specs + 1] = { "LazyVim/LazyVim", priority = 10000, lazy = true }
specs[#specs + 1] = { "LazyVim/LazyVim", priority = 10000, lazy = false, config = true }
else
require("lazyvim.config").setup()
end
return specs

View File

@ -0,0 +1,6 @@
-- load options here, before lazy init while sourcing plugin modules
-- this is needed to make sure options will be correctly applied
-- after installing missing plugins
require("lazyvim.config").load("options")
return {}