diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 2e345c0f..248360a9 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -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, }, } diff --git a/lua/lazyvim/plugins/colorscheme.lua b/lua/lazyvim/plugins/colorscheme.lua index 918085a5..d4f85234 100644 --- a/lua/lazyvim/plugins/colorscheme.lua +++ b/lua/lazyvim/plugins/colorscheme.lua @@ -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, }, diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index b7f72ef4..42eeb545 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -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() + opts = { + plugins = { spelling = true }, + key_labels = { [""] = "SPC" }, + }, + config = function(_, opts) local wk = require("which-key") - wk.setup({ - plugins = { spelling = true }, - key_labels = { [""] = "SPC" }, - }) + 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 = { { "xx", "TroubleToggle document_diagnostics", desc = "Document Diagnostics (Trouble)" }, { "xX", "TroubleToggle workspace_diagnostics", desc = "Workspace Diagnostics (Trouble)" }, diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index a8b2e384..26a3502e 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -10,30 +10,46 @@ return { "williamboman/mason-lspconfig.nvim", "hrsh7th/cmp-nvim-lsp", }, - ---@type lspconfig.options - servers = { - jsonls = {}, - sumneko_lua = { - settings = { - Lua = { - workspace = { - checkThirdParty = false, - }, - completion = { - callSnippet = "Replace", + ---@class PluginLspOpts + opts = { + ---@type lspconfig.options + servers = { + jsonls = {}, + sumneko_lua = { + settings = { + Lua = { + workspace = { + checkThirdParty = false, + }, + completion = { + callSnippet = "Replace", + }, }, }, }, }, + -- you can do any additional lsp server setup here + -- return true if you don't want this server to be setup with lspconfig + ---@type table + 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, + }, }, - -- 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) + ---@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() diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index 506c081e..b753142b 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -3,31 +3,36 @@ return { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", event = "BufReadPost", - ensure_installed = { - "bash", - "help", - "html", - "javascript", - "json", - "lua", - "markdown", - "markdown_inline", - "python", - "query", - "regex", - "tsx", - "typescript", - "vim", - "yaml", + ---@type TSConfig + opts = { + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + context_commentstring = { enable = true, enable_autocmd = false }, + ensure_installed = { + "bash", + "help", + "html", + "javascript", + "json", + "lua", + "markdown", + "markdown_inline", + "python", + "query", + "regex", + "tsx", + "typescript", + "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, }, } diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index ceb84cfe..897d5aa5 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -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,15 +280,15 @@ return { { "goolord/alpha-nvim", event = "VimEnter", - config = function() + opts = function() local dashboard = require("alpha.themes.dashboard") local logo = [[ - ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z - ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z - ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z - ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z - ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ - ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ + ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z + ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z + ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z + ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z + ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ + ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ]] dashboard.section.header.val = vim.split(logo, "\n") @@ -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 diff --git a/lua/lazyvim/plugins/util.lua b/lua/lazyvim/plugins/util.lua index 6da3ccd9..7b811be0 100644 --- a/lua/lazyvim/plugins/util.lua +++ b/lua/lazyvim/plugins/util.lua @@ -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 = { { "qs", function() require("persistence").load() end, desc = "Restore Session" }, diff --git a/lua/lazyvim/util.lua b/lua/lazyvim/util.lua index 512ce265..cbf7611b 100644 --- a/lua/lazyvim/util.lua +++ b/lua/lazyvim/util.lua @@ -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