142 lines
3.2 KiB
Lua
142 lines
3.2 KiB
Lua
---@type LazyVimConfig
|
|
local M = {}
|
|
|
|
M.lazy_version = ">=9.1.0"
|
|
|
|
---@class LazyVimConfig
|
|
local defaults = {
|
|
-- colorscheme can be a string like `catppuccin` or a function that will load the colorscheme
|
|
---@type string|fun()
|
|
colorscheme = function()
|
|
require("tokyonight").load()
|
|
end,
|
|
-- icons used by other plugins
|
|
icons = {
|
|
diagnostics = {
|
|
Error = " ",
|
|
Warn = " ",
|
|
Hint = " ",
|
|
Info = " ",
|
|
},
|
|
git = {
|
|
added = " ",
|
|
modified = " ",
|
|
removed = " ",
|
|
},
|
|
kinds = {
|
|
Array = " ",
|
|
Boolean = " ",
|
|
Class = " ",
|
|
Color = " ",
|
|
Constant = " ",
|
|
Constructor = " ",
|
|
Enum = " ",
|
|
EnumMember = " ",
|
|
Event = " ",
|
|
Field = " ",
|
|
File = " ",
|
|
Folder = " ",
|
|
Function = " ",
|
|
Interface = " ",
|
|
Key = " ",
|
|
Keyword = " ",
|
|
Method = " ",
|
|
Module = " ",
|
|
Namespace = " ",
|
|
Null = "ﳠ ",
|
|
Number = " ",
|
|
Object = " ",
|
|
Operator = " ",
|
|
Package = " ",
|
|
Property = " ",
|
|
Reference = " ",
|
|
Snippet = " ",
|
|
String = " ",
|
|
Struct = " ",
|
|
Text = " ",
|
|
TypeParameter = " ",
|
|
Unit = " ",
|
|
Value = " ",
|
|
Variable = " ",
|
|
},
|
|
},
|
|
}
|
|
|
|
---@type LazyVimConfig
|
|
local options
|
|
|
|
---@param opts? LazyVimConfig
|
|
function M.setup(opts)
|
|
options = vim.tbl_deep_extend("force", defaults, opts or {})
|
|
if not M.has() then
|
|
require("lazy.core.util").error(
|
|
"**LazyVim** needs **lazy.nvim** version "
|
|
.. M.lazy_version
|
|
.. " to work properly.\n"
|
|
.. "Please upgrade **lazy.nvim**",
|
|
{ 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,
|
|
})
|
|
|
|
require("lazy.core.util").try(function()
|
|
if type(M.colorscheme) == "function" then
|
|
M.colorscheme()
|
|
else
|
|
vim.cmd.colorscheme(M.colorscheme)
|
|
end
|
|
end, {
|
|
msg = "Could not load your colorscheme",
|
|
on_error = function(msg)
|
|
require("lazy.core.util").error(msg)
|
|
vim.cmd.colorscheme("habamax")
|
|
end,
|
|
})
|
|
end
|
|
|
|
---@param range? string
|
|
function M.has(range)
|
|
local Semver = require("lazy.manage.semver")
|
|
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
|
|
M.setup()
|
|
end
|
|
---@cast options LazyVimConfig
|
|
return options[key]
|
|
end,
|
|
})
|
|
|
|
return M
|