mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-27 03:09:07 +02:00
refactor(plugins)!: plugins now use lazy.nvim's new opts
property to make it far easier to override options
This commit is contained in:
parent
8667b3d54e
commit
2135bc144c
8 changed files with 140 additions and 95 deletions
|
@ -9,7 +9,7 @@ return {
|
|||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
end,
|
||||
},
|
||||
config = {
|
||||
opts = {
|
||||
history = true,
|
||||
delete_check_events = "TextChanged",
|
||||
},
|
||||
|
@ -35,12 +35,11 @@ return {
|
|||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-emoji",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
config = function()
|
||||
opts = function()
|
||||
local cmp = require("cmp")
|
||||
cmp.setup({
|
||||
return {
|
||||
completion = {
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
},
|
||||
|
@ -61,7 +60,6 @@ return {
|
|||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
{ name = "emoji" },
|
||||
}),
|
||||
formatting = {
|
||||
format = function(_, item)
|
||||
|
@ -77,7 +75,7 @@ return {
|
|||
hl_group = "LspCodeLens",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
|
@ -142,9 +140,9 @@ return {
|
|||
end,
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
opts = function()
|
||||
local ai = require("mini.ai")
|
||||
ai.setup({
|
||||
return {
|
||||
n_lines = 500,
|
||||
custom_textobjects = {
|
||||
o = ai.gen_spec.treesitter({
|
||||
|
@ -154,7 +152,11 @@ return {
|
|||
f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}),
|
||||
c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }, {}),
|
||||
},
|
||||
})
|
||||
}
|
||||
end,
|
||||
config = function(_, opts)
|
||||
local ai = require("mini.ai")
|
||||
ai.setup(opts)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ return {
|
|||
"folke/tokyonight.nvim",
|
||||
lazy = false,
|
||||
priority = 1000,
|
||||
config = function()
|
||||
opts = { style = "moon" },
|
||||
config = function(_, opts)
|
||||
local tokyonight = require("tokyonight")
|
||||
tokyonight.setup({ style = "moon" })
|
||||
tokyonight.setup(opts)
|
||||
tokyonight.load()
|
||||
end,
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@ return {
|
|||
init = function()
|
||||
vim.g.neo_tree_remove_legacy_commands = 1
|
||||
end,
|
||||
config = {
|
||||
opts = {
|
||||
filesystem = {
|
||||
follow_current_file = true,
|
||||
hijack_netrw_behavior = "open_current",
|
||||
|
@ -85,7 +85,7 @@ return {
|
|||
desc = "Goto Symbol",
|
||||
},
|
||||
},
|
||||
config = {
|
||||
opts = {
|
||||
defaults = {
|
||||
prompt_prefix = " ",
|
||||
selection_caret = " ",
|
||||
|
@ -116,7 +116,7 @@ return {
|
|||
{
|
||||
"ggandor/leap.nvim",
|
||||
event = "VeryLazy",
|
||||
dependencies = { { "ggandor/flit.nvim", config = { labeled_modes = "nv" } } },
|
||||
dependencies = { { "ggandor/flit.nvim", opts = { labeled_modes = "nv" } } },
|
||||
config = function()
|
||||
require("leap").add_default_mappings(true)
|
||||
end,
|
||||
|
@ -126,12 +126,13 @@ return {
|
|||
{
|
||||
"folke/which-key.nvim",
|
||||
event = "VeryLazy",
|
||||
config = function()
|
||||
local wk = require("which-key")
|
||||
wk.setup({
|
||||
opts = {
|
||||
plugins = { spelling = true },
|
||||
key_labels = { ["<leader>"] = "SPC" },
|
||||
})
|
||||
},
|
||||
config = function(_, opts)
|
||||
local wk = require("which-key")
|
||||
wk.setup(opts)
|
||||
wk.register({
|
||||
mode = { "n", "v" },
|
||||
["g"] = { name = "+goto" },
|
||||
|
@ -158,7 +159,7 @@ return {
|
|||
{
|
||||
"lewis6991/gitsigns.nvim",
|
||||
event = "BufReadPre",
|
||||
config = {
|
||||
opts = {
|
||||
signs = {
|
||||
add = { text = "▎" },
|
||||
change = { text = "▎" },
|
||||
|
@ -219,7 +220,7 @@ return {
|
|||
{
|
||||
"folke/trouble.nvim",
|
||||
cmd = { "TroubleToggle", "Trouble" },
|
||||
config = { use_diagnostic_signs = true },
|
||||
opts = { use_diagnostic_signs = true },
|
||||
keys = {
|
||||
{ "<leader>xx", "<cmd>TroubleToggle document_diagnostics<cr>", desc = "Document Diagnostics (Trouble)" },
|
||||
{ "<leader>xX", "<cmd>TroubleToggle workspace_diagnostics<cr>", desc = "Workspace Diagnostics (Trouble)" },
|
||||
|
|
|
@ -10,6 +10,8 @@ return {
|
|||
"williamboman/mason-lspconfig.nvim",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
---@class PluginLspOpts
|
||||
opts = {
|
||||
---@type lspconfig.options
|
||||
servers = {
|
||||
jsonls = {},
|
||||
|
@ -28,12 +30,26 @@ return {
|
|||
},
|
||||
-- you can do any additional lsp server setup here
|
||||
-- return true if you don't want this server to be setup with lspconfig
|
||||
---@param server string lsp server name
|
||||
---@param opts _.lspconfig.options any options set for the server
|
||||
setup_server = function(server, opts)
|
||||
return false
|
||||
end,
|
||||
config = function(plugin)
|
||||
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
|
||||
setup = {
|
||||
-- example to setup with typescript.nvim
|
||||
-- tsserver = function(_, opts)
|
||||
-- require("typescript").setup({ server = opts })
|
||||
-- return true
|
||||
-- end,
|
||||
-- Specify * to use this function as a fallback for any server
|
||||
-- ["*"] = function(server, opts) end,
|
||||
},
|
||||
},
|
||||
---@param opts PluginLspOpts
|
||||
config = function(plugin, opts)
|
||||
if plugin.servers then
|
||||
require("lazyvim.util").deprecate("lspconfig.servers", "lspconfig.opts.servers")
|
||||
end
|
||||
if plugin.setup_server then
|
||||
require("lazyvim.util").deprecate("lspconfig.setup_server", "lspconfig.opts.setup[SERVER]")
|
||||
end
|
||||
|
||||
-- setup formatting and keymaps
|
||||
require("lazyvim.util").on_attach(function(client, buffer)
|
||||
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
|
||||
|
@ -52,18 +68,24 @@ return {
|
|||
severity_sort = true,
|
||||
})
|
||||
|
||||
---@type lspconfig.options
|
||||
local servers = plugin.servers or {}
|
||||
local servers = opts.servers
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
|
||||
require("mason-lspconfig").setup({ ensure_installed = vim.tbl_keys(servers) })
|
||||
require("mason-lspconfig").setup_handlers({
|
||||
function(server)
|
||||
local opts = servers[server] or {}
|
||||
opts.capabilities = capabilities
|
||||
if not plugin.setup_server(server, opts) then
|
||||
require("lspconfig")[server].setup(opts)
|
||||
local server_opts = servers[server] or {}
|
||||
server_opts.capabilities = capabilities
|
||||
if opts.setup[server] then
|
||||
if opts.setup[server](server, server_opts) then
|
||||
return
|
||||
end
|
||||
elseif opts.setup["*"] then
|
||||
if opts.setup["*"](server, server_opts) then
|
||||
return
|
||||
end
|
||||
end
|
||||
require("lspconfig")[server].setup(server_opts)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
|
@ -74,15 +96,15 @@ return {
|
|||
"jose-elias-alvarez/null-ls.nvim",
|
||||
event = "BufReadPre",
|
||||
dependencies = { "mason.nvim" },
|
||||
config = function()
|
||||
opts = function()
|
||||
local nls = require("null-ls")
|
||||
nls.setup({
|
||||
return {
|
||||
sources = {
|
||||
-- nls.builtins.formatting.prettierd,
|
||||
nls.builtins.formatting.stylua,
|
||||
nls.builtins.diagnostics.flake8,
|
||||
},
|
||||
})
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
|
@ -98,10 +120,11 @@ return {
|
|||
"shfmt",
|
||||
"flake8",
|
||||
},
|
||||
config = function(plugin)
|
||||
require("mason").setup()
|
||||
---@param opts MasonSettings
|
||||
config = function(self, opts)
|
||||
require("mason").setup(opts)
|
||||
local mr = require("mason-registry")
|
||||
for _, tool in ipairs(plugin.ensure_installed) do
|
||||
for _, tool in ipairs(self.ensure_installed) do
|
||||
local p = mr.get_package(tool)
|
||||
if not p:is_installed() then
|
||||
p:install()
|
||||
|
|
|
@ -3,6 +3,12 @@ return {
|
|||
"nvim-treesitter/nvim-treesitter",
|
||||
build = ":TSUpdate",
|
||||
event = "BufReadPost",
|
||||
---@type TSConfig
|
||||
opts = {
|
||||
sync_install = false,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
context_commentstring = { enable = true, enable_autocmd = false },
|
||||
ensure_installed = {
|
||||
"bash",
|
||||
"help",
|
||||
|
@ -20,14 +26,13 @@ return {
|
|||
"vim",
|
||||
"yaml",
|
||||
},
|
||||
config = function(plugin)
|
||||
require("nvim-treesitter.configs").setup({
|
||||
sync_install = false,
|
||||
ensure_installed = plugin.ensure_installed,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
context_commentstring = { enable = true, enable_autocmd = false },
|
||||
})
|
||||
},
|
||||
---@param opts TSConfig
|
||||
config = function(plugin, opts)
|
||||
if plugin.ensure_installed then
|
||||
require("lazyvim.util").deprecate("treesitter.ensure_installed", "treesitter.opts.ensure_installed")
|
||||
end
|
||||
require("nvim-treesitter.configs").setup(opts)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ return {
|
|||
desc = "Delete all Notifications",
|
||||
},
|
||||
},
|
||||
config = {
|
||||
opts = {
|
||||
timeout = 3000,
|
||||
max_height = function()
|
||||
return math.floor(vim.o.lines * 0.75)
|
||||
|
@ -43,7 +43,7 @@ return {
|
|||
{
|
||||
"akinsho/nvim-bufferline.lua",
|
||||
event = "BufAdd",
|
||||
config = {
|
||||
opts = {
|
||||
options = {
|
||||
diagnostics = "nvim_lsp",
|
||||
always_show_bufferline = false,
|
||||
|
@ -69,10 +69,11 @@ return {
|
|||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
event = "VeryLazy",
|
||||
override = function(config)
|
||||
return config
|
||||
end,
|
||||
config = function(plugin)
|
||||
opts = function(plugin)
|
||||
if plugin.override then
|
||||
require("lazyvim.util").deprecate("lualine.override", "lualine.opts")
|
||||
end
|
||||
|
||||
local icons = require("lazyvim.config.settings").icons
|
||||
|
||||
local function fg(name)
|
||||
|
@ -83,7 +84,7 @@ return {
|
|||
end
|
||||
end
|
||||
|
||||
require("lualine").setup(plugin.override({
|
||||
return {
|
||||
options = {
|
||||
theme = "auto",
|
||||
globalstatus = true,
|
||||
|
@ -144,7 +145,7 @@ return {
|
|||
},
|
||||
},
|
||||
extensions = { "nvim-tree" },
|
||||
}))
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
|
@ -152,7 +153,7 @@ return {
|
|||
{
|
||||
"lukas-reineke/indent-blankline.nvim",
|
||||
event = "BufReadPre",
|
||||
config = {
|
||||
opts = {
|
||||
-- char = "▏",
|
||||
char = "│",
|
||||
filetype_exclude = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy" },
|
||||
|
@ -185,7 +186,7 @@ return {
|
|||
{
|
||||
"folke/noice.nvim",
|
||||
event = "VeryLazy",
|
||||
config = {
|
||||
opts = {
|
||||
lsp = {
|
||||
override = {
|
||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
|
@ -279,7 +280,7 @@ return {
|
|||
{
|
||||
"goolord/alpha-nvim",
|
||||
event = "VimEnter",
|
||||
config = function()
|
||||
opts = function()
|
||||
local dashboard = require("alpha.themes.dashboard")
|
||||
local logo = [[
|
||||
██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z
|
||||
|
@ -309,6 +310,9 @@ return {
|
|||
dashboard.section.header.opts.hl = "AlphaHeader"
|
||||
dashboard.section.buttons.opts.hl = "AlphaButtons"
|
||||
dashboard.opts.layout[1].val = 8
|
||||
return dashboard
|
||||
end,
|
||||
config = function(_, dashboard)
|
||||
vim.b.miniindentscope_disable = true
|
||||
|
||||
-- close Lazy and re-open when the dashboard is ready
|
||||
|
@ -347,7 +351,7 @@ return {
|
|||
end
|
||||
end)
|
||||
end,
|
||||
config = { separator = " ", highlight = true, depth_limit = 5 },
|
||||
opts = { separator = " ", highlight = true, depth_limit = 5 },
|
||||
},
|
||||
|
||||
-- icons
|
||||
|
|
|
@ -13,7 +13,7 @@ return {
|
|||
{
|
||||
"folke/persistence.nvim",
|
||||
event = "BufReadPre",
|
||||
config = { options = { "buffers", "curdir", "tabpages", "winsize", "help" } },
|
||||
opts = { options = { "buffers", "curdir", "tabpages", "winsize", "help" } },
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{ "<leader>qs", function() require("persistence").load() end, desc = "Restore Session" },
|
||||
|
|
|
@ -75,6 +75,7 @@ function M.telescope(builtin, opts)
|
|||
end
|
||||
end
|
||||
|
||||
-- FIXME: create a togglable termiminal
|
||||
-- Opens a floating terminal (interactive by default)
|
||||
---@param cmd? string[]|string
|
||||
---@param opts? LazyCmdOptions|{interactive?:boolean}
|
||||
|
@ -122,4 +123,12 @@ function M.toggle_diagnostics()
|
|||
end
|
||||
end
|
||||
|
||||
function M.deprecate(old, new)
|
||||
vim.notify(
|
||||
("`%s` is deprecated. Please use `%s` instead"):format(old, new),
|
||||
vim.log.levels.WARN,
|
||||
{ title = "LazyVim" }
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue