189 lines
4.7 KiB
Lua
189 lines
4.7 KiB
Lua
local Util = require("lazyvim.util")
|
|
|
|
---@class LazyVimConfig: LazyVimOptions
|
|
local M = {}
|
|
|
|
---@class LazyVimOptions
|
|
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,
|
|
-- load the default settings
|
|
defaults = {
|
|
autocmds = true, -- lazyvim.config.autocmds
|
|
keymaps = true, -- lazyvim.config.keymaps
|
|
-- lazyvim.config.options can't be configured here since that's loaded before lazyvim setup
|
|
-- if you want to disable loading options, add `package.loaded["lazyvim.config.options"] = true` to the top of your init.lua
|
|
},
|
|
-- icons used by other plugins
|
|
icons = {
|
|
misc = {
|
|
dots = "",
|
|
},
|
|
dap = {
|
|
Stopped = { " ", "DiagnosticWarn", "DapStoppedLine" },
|
|
Breakpoint = " ",
|
|
BreakpointCondition = " ",
|
|
BreakpointRejected = { " ", "DiagnosticError" },
|
|
LogPoint = ".>",
|
|
},
|
|
diagnostics = {
|
|
Error = " ",
|
|
Warn = " ",
|
|
Hint = " ",
|
|
Info = " ",
|
|
},
|
|
git = {
|
|
added = " ",
|
|
modified = " ",
|
|
removed = " ",
|
|
},
|
|
kinds = {
|
|
Array = " ",
|
|
Boolean = " ",
|
|
Class = " ",
|
|
Codeium = " ",
|
|
Color = " ",
|
|
Constant = " ",
|
|
Constructor = " ",
|
|
Copilot = " ",
|
|
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 LazyVimOptions
|
|
local options
|
|
|
|
---@param opts? LazyVimOptions
|
|
function M.setup(opts)
|
|
options = vim.tbl_deep_extend("force", defaults, opts or {}) or {}
|
|
|
|
-- autocmds can be loaded lazily when not opening a file
|
|
local lazy_autocmds = vim.fn.argc(-1) == 0
|
|
if not lazy_autocmds then
|
|
M.load("autocmds")
|
|
end
|
|
|
|
local group = vim.api.nvim_create_augroup("LazyVim", { clear = true })
|
|
vim.api.nvim_create_autocmd("User", {
|
|
group = group,
|
|
pattern = "VeryLazy",
|
|
callback = function()
|
|
if lazy_autocmds then
|
|
M.load("autocmds")
|
|
end
|
|
M.load("keymaps")
|
|
Util.format.setup()
|
|
end,
|
|
})
|
|
|
|
Util.track("colorscheme")
|
|
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)
|
|
Util.error(msg)
|
|
vim.cmd.colorscheme("habamax")
|
|
end,
|
|
})
|
|
Util.track()
|
|
end
|
|
|
|
---@param name "autocmds" | "options" | "keymaps"
|
|
function M.load(name)
|
|
local function _load(mod)
|
|
if require("lazy.core.cache").find(mod)[1] then
|
|
Util.try(function()
|
|
require(mod)
|
|
end, { msg = "Failed loading " .. mod })
|
|
end
|
|
end
|
|
-- always load lazyvim, then user file
|
|
if M.defaults[name] or name == "options" then
|
|
_load("lazyvim.config." .. name)
|
|
end
|
|
_load("config." .. name)
|
|
if vim.bo.filetype == "lazy" then
|
|
-- HACK: LazyVim may have overwritten options of the Lazy ui, so reset this here
|
|
vim.cmd([[do VimResized]])
|
|
end
|
|
local pattern = "LazyVim" .. name:sub(1, 1):upper() .. name:sub(2)
|
|
vim.api.nvim_exec_autocmds("User", { pattern = pattern, modeline = false })
|
|
end
|
|
|
|
M.did_init = false
|
|
function M.init()
|
|
if M.did_init then
|
|
return
|
|
end
|
|
M.did_init = true
|
|
local plugin = require("lazy.core.config").spec.plugins.LazyVim
|
|
if plugin then
|
|
vim.opt.rtp:append(plugin.dir)
|
|
end
|
|
|
|
package.preload["lazyvim.plugins.lsp.format"] = function()
|
|
Util.deprecate([[require("lazyvim.plugins.lsp.format")]], [[require("lazyvim.util").format]])
|
|
return Util.format
|
|
end
|
|
|
|
-- delay notifications till vim.notify was replaced or after 500ms
|
|
require("lazyvim.util").lazy_notify()
|
|
|
|
-- 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
|
|
M.load("options")
|
|
|
|
Util.plugin.fix_imports()
|
|
Util.plugin.fix_renames()
|
|
Util.plugin.lazy_file()
|
|
end
|
|
|
|
setmetatable(M, {
|
|
__index = function(_, key)
|
|
if options == nil then
|
|
return vim.deepcopy(defaults)[key]
|
|
end
|
|
---@cast options LazyVimConfig
|
|
return options[key]
|
|
end,
|
|
})
|
|
|
|
return M
|