refactor(plugins)!: plugins now use lazy.nvim's new opts property to make it far easier to override options

This commit is contained in:
Folke Lemaitre 2023-01-08 15:05:34 +01:00
parent 8667b3d54e
commit 2135bc144c
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
8 changed files with 140 additions and 95 deletions

View file

@ -9,7 +9,7 @@ return {
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
end, end,
}, },
config = { opts = {
history = true, history = true,
delete_check_events = "TextChanged", delete_check_events = "TextChanged",
}, },
@ -35,12 +35,11 @@ return {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
"hrsh7th/cmp-path", "hrsh7th/cmp-path",
"hrsh7th/cmp-emoji",
"saadparwaiz1/cmp_luasnip", "saadparwaiz1/cmp_luasnip",
}, },
config = function() opts = function()
local cmp = require("cmp") local cmp = require("cmp")
cmp.setup({ return {
completion = { completion = {
completeopt = "menu,menuone,noinsert", completeopt = "menu,menuone,noinsert",
}, },
@ -61,7 +60,6 @@ return {
{ name = "luasnip" }, { name = "luasnip" },
{ name = "buffer" }, { name = "buffer" },
{ name = "path" }, { name = "path" },
{ name = "emoji" },
}), }),
formatting = { formatting = {
format = function(_, item) format = function(_, item)
@ -77,7 +75,7 @@ return {
hl_group = "LspCodeLens", hl_group = "LspCodeLens",
}, },
}, },
}) }
end, end,
}, },
@ -142,9 +140,9 @@ return {
end, end,
}, },
}, },
config = function() opts = function()
local ai = require("mini.ai") local ai = require("mini.ai")
ai.setup({ return {
n_lines = 500, n_lines = 500,
custom_textobjects = { custom_textobjects = {
o = ai.gen_spec.treesitter({ o = ai.gen_spec.treesitter({
@ -154,7 +152,11 @@ return {
f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}), f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}),
c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.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, end,
}, },
} }

View file

@ -5,9 +5,10 @@ return {
"folke/tokyonight.nvim", "folke/tokyonight.nvim",
lazy = false, lazy = false,
priority = 1000, priority = 1000,
config = function() opts = { style = "moon" },
config = function(_, opts)
local tokyonight = require("tokyonight") local tokyonight = require("tokyonight")
tokyonight.setup({ style = "moon" }) tokyonight.setup(opts)
tokyonight.load() tokyonight.load()
end, end,
}, },

View file

@ -19,7 +19,7 @@ return {
init = function() init = function()
vim.g.neo_tree_remove_legacy_commands = 1 vim.g.neo_tree_remove_legacy_commands = 1
end, end,
config = { opts = {
filesystem = { filesystem = {
follow_current_file = true, follow_current_file = true,
hijack_netrw_behavior = "open_current", hijack_netrw_behavior = "open_current",
@ -85,7 +85,7 @@ return {
desc = "Goto Symbol", desc = "Goto Symbol",
}, },
}, },
config = { opts = {
defaults = { defaults = {
prompt_prefix = "", prompt_prefix = "",
selection_caret = "", selection_caret = "",
@ -116,7 +116,7 @@ return {
{ {
"ggandor/leap.nvim", "ggandor/leap.nvim",
event = "VeryLazy", event = "VeryLazy",
dependencies = { { "ggandor/flit.nvim", config = { labeled_modes = "nv" } } }, dependencies = { { "ggandor/flit.nvim", opts = { labeled_modes = "nv" } } },
config = function() config = function()
require("leap").add_default_mappings(true) require("leap").add_default_mappings(true)
end, end,
@ -126,12 +126,13 @@ return {
{ {
"folke/which-key.nvim", "folke/which-key.nvim",
event = "VeryLazy", event = "VeryLazy",
config = function() opts = {
local wk = require("which-key")
wk.setup({
plugins = { spelling = true }, plugins = { spelling = true },
key_labels = { ["<leader>"] = "SPC" }, key_labels = { ["<leader>"] = "SPC" },
}) },
config = function(_, opts)
local wk = require("which-key")
wk.setup(opts)
wk.register({ wk.register({
mode = { "n", "v" }, mode = { "n", "v" },
["g"] = { name = "+goto" }, ["g"] = { name = "+goto" },
@ -158,7 +159,7 @@ return {
{ {
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
event = "BufReadPre", event = "BufReadPre",
config = { opts = {
signs = { signs = {
add = { text = "" }, add = { text = "" },
change = { text = "" }, change = { text = "" },
@ -219,7 +220,7 @@ return {
{ {
"folke/trouble.nvim", "folke/trouble.nvim",
cmd = { "TroubleToggle", "Trouble" }, cmd = { "TroubleToggle", "Trouble" },
config = { use_diagnostic_signs = true }, opts = { use_diagnostic_signs = true },
keys = { keys = {
{ "<leader>xx", "<cmd>TroubleToggle document_diagnostics<cr>", desc = "Document Diagnostics (Trouble)" }, { "<leader>xx", "<cmd>TroubleToggle document_diagnostics<cr>", desc = "Document Diagnostics (Trouble)" },
{ "<leader>xX", "<cmd>TroubleToggle workspace_diagnostics<cr>", desc = "Workspace Diagnostics (Trouble)" }, { "<leader>xX", "<cmd>TroubleToggle workspace_diagnostics<cr>", desc = "Workspace Diagnostics (Trouble)" },

View file

@ -10,6 +10,8 @@ return {
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
}, },
---@class PluginLspOpts
opts = {
---@type lspconfig.options ---@type lspconfig.options
servers = { servers = {
jsonls = {}, jsonls = {},
@ -28,12 +30,26 @@ return {
}, },
-- you can do any additional lsp server setup here -- you can do any additional lsp server setup here
-- return true if you don't want this server to be setup with lspconfig -- return true if you don't want this server to be setup with lspconfig
---@param server string lsp server name ---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
---@param opts _.lspconfig.options any options set for the server setup = {
setup_server = function(server, opts) -- example to setup with typescript.nvim
return false -- tsserver = function(_, opts)
end, -- require("typescript").setup({ server = opts })
config = function(plugin) -- 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 -- setup formatting and keymaps
require("lazyvim.util").on_attach(function(client, buffer) require("lazyvim.util").on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.format").on_attach(client, buffer) require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
@ -52,18 +68,24 @@ return {
severity_sort = true, severity_sort = true,
}) })
---@type lspconfig.options local servers = opts.servers
local servers = plugin.servers or {}
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) 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({ ensure_installed = vim.tbl_keys(servers) })
require("mason-lspconfig").setup_handlers({ require("mason-lspconfig").setup_handlers({
function(server) function(server)
local opts = servers[server] or {} local server_opts = servers[server] or {}
opts.capabilities = capabilities server_opts.capabilities = capabilities
if not plugin.setup_server(server, opts) then if opts.setup[server] then
require("lspconfig")[server].setup(opts) if opts.setup[server](server, server_opts) then
return
end end
elseif opts.setup["*"] then
if opts.setup["*"](server, server_opts) then
return
end
end
require("lspconfig")[server].setup(server_opts)
end, end,
}) })
end, end,
@ -74,15 +96,15 @@ return {
"jose-elias-alvarez/null-ls.nvim", "jose-elias-alvarez/null-ls.nvim",
event = "BufReadPre", event = "BufReadPre",
dependencies = { "mason.nvim" }, dependencies = { "mason.nvim" },
config = function() opts = function()
local nls = require("null-ls") local nls = require("null-ls")
nls.setup({ return {
sources = { sources = {
-- nls.builtins.formatting.prettierd, -- nls.builtins.formatting.prettierd,
nls.builtins.formatting.stylua, nls.builtins.formatting.stylua,
nls.builtins.diagnostics.flake8, nls.builtins.diagnostics.flake8,
}, },
}) }
end, end,
}, },
@ -98,10 +120,11 @@ return {
"shfmt", "shfmt",
"flake8", "flake8",
}, },
config = function(plugin) ---@param opts MasonSettings
require("mason").setup() config = function(self, opts)
require("mason").setup(opts)
local mr = require("mason-registry") 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) local p = mr.get_package(tool)
if not p:is_installed() then if not p:is_installed() then
p:install() p:install()

View file

@ -3,6 +3,12 @@ return {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
build = ":TSUpdate", build = ":TSUpdate",
event = "BufReadPost", event = "BufReadPost",
---@type TSConfig
opts = {
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
context_commentstring = { enable = true, enable_autocmd = false },
ensure_installed = { ensure_installed = {
"bash", "bash",
"help", "help",
@ -20,14 +26,13 @@ return {
"vim", "vim",
"yaml", "yaml",
}, },
config = function(plugin) },
require("nvim-treesitter.configs").setup({ ---@param opts TSConfig
sync_install = false, config = function(plugin, opts)
ensure_installed = plugin.ensure_installed, if plugin.ensure_installed then
highlight = { enable = true }, require("lazyvim.util").deprecate("treesitter.ensure_installed", "treesitter.opts.ensure_installed")
indent = { enable = true }, end
context_commentstring = { enable = true, enable_autocmd = false }, require("nvim-treesitter.configs").setup(opts)
})
end, end,
}, },
} }

View file

@ -11,7 +11,7 @@ return {
desc = "Delete all Notifications", desc = "Delete all Notifications",
}, },
}, },
config = { opts = {
timeout = 3000, timeout = 3000,
max_height = function() max_height = function()
return math.floor(vim.o.lines * 0.75) return math.floor(vim.o.lines * 0.75)
@ -43,7 +43,7 @@ return {
{ {
"akinsho/nvim-bufferline.lua", "akinsho/nvim-bufferline.lua",
event = "BufAdd", event = "BufAdd",
config = { opts = {
options = { options = {
diagnostics = "nvim_lsp", diagnostics = "nvim_lsp",
always_show_bufferline = false, always_show_bufferline = false,
@ -69,10 +69,11 @@ return {
{ {
"nvim-lualine/lualine.nvim", "nvim-lualine/lualine.nvim",
event = "VeryLazy", event = "VeryLazy",
override = function(config) opts = function(plugin)
return config if plugin.override then
end, require("lazyvim.util").deprecate("lualine.override", "lualine.opts")
config = function(plugin) end
local icons = require("lazyvim.config.settings").icons local icons = require("lazyvim.config.settings").icons
local function fg(name) local function fg(name)
@ -83,7 +84,7 @@ return {
end end
end end
require("lualine").setup(plugin.override({ return {
options = { options = {
theme = "auto", theme = "auto",
globalstatus = true, globalstatus = true,
@ -144,7 +145,7 @@ return {
}, },
}, },
extensions = { "nvim-tree" }, extensions = { "nvim-tree" },
})) }
end, end,
}, },
@ -152,7 +153,7 @@ return {
{ {
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
event = "BufReadPre", event = "BufReadPre",
config = { opts = {
-- char = "▏", -- char = "▏",
char = "", char = "",
filetype_exclude = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy" }, filetype_exclude = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy" },
@ -185,7 +186,7 @@ return {
{ {
"folke/noice.nvim", "folke/noice.nvim",
event = "VeryLazy", event = "VeryLazy",
config = { opts = {
lsp = { lsp = {
override = { override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
@ -279,7 +280,7 @@ return {
{ {
"goolord/alpha-nvim", "goolord/alpha-nvim",
event = "VimEnter", event = "VimEnter",
config = function() opts = function()
local dashboard = require("alpha.themes.dashboard") local dashboard = require("alpha.themes.dashboard")
local logo = [[ local logo = [[
Z Z
@ -309,6 +310,9 @@ return {
dashboard.section.header.opts.hl = "AlphaHeader" dashboard.section.header.opts.hl = "AlphaHeader"
dashboard.section.buttons.opts.hl = "AlphaButtons" dashboard.section.buttons.opts.hl = "AlphaButtons"
dashboard.opts.layout[1].val = 8 dashboard.opts.layout[1].val = 8
return dashboard
end,
config = function(_, dashboard)
vim.b.miniindentscope_disable = true vim.b.miniindentscope_disable = true
-- close Lazy and re-open when the dashboard is ready -- close Lazy and re-open when the dashboard is ready
@ -347,7 +351,7 @@ return {
end end
end) end)
end, end,
config = { separator = " ", highlight = true, depth_limit = 5 }, opts = { separator = " ", highlight = true, depth_limit = 5 },
}, },
-- icons -- icons

View file

@ -13,7 +13,7 @@ return {
{ {
"folke/persistence.nvim", "folke/persistence.nvim",
event = "BufReadPre", event = "BufReadPre",
config = { options = { "buffers", "curdir", "tabpages", "winsize", "help" } }, opts = { options = { "buffers", "curdir", "tabpages", "winsize", "help" } },
-- stylua: ignore -- stylua: ignore
keys = { keys = {
{ "<leader>qs", function() require("persistence").load() end, desc = "Restore Session" }, { "<leader>qs", function() require("persistence").load() end, desc = "Restore Session" },

View file

@ -75,6 +75,7 @@ function M.telescope(builtin, opts)
end end
end end
-- FIXME: create a togglable termiminal
-- Opens a floating terminal (interactive by default) -- Opens a floating terminal (interactive by default)
---@param cmd? string[]|string ---@param cmd? string[]|string
---@param opts? LazyCmdOptions|{interactive?:boolean} ---@param opts? LazyCmdOptions|{interactive?:boolean}
@ -122,4 +123,12 @@ function M.toggle_diagnostics()
end end
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 return M