From 659037279152762991401fe75a050d168456dc52 Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 17 Feb 2023 22:08:28 +0530 Subject: [PATCH] BREAKING CHANGE: utilize lazy.nvim fully, remove un-needed functions --- lua/core/utils.lua | 31 ----- lua/plugins/configs/cmp.lua | 5 +- lua/plugins/configs/mason.lua | 8 +- lua/plugins/configs/nvimtree.lua | 4 +- lua/plugins/configs/others.lua | 91 +++---------- lua/plugins/configs/telescope.lua | 11 +- lua/plugins/configs/treesitter.lua | 5 +- lua/plugins/configs/whichkey.lua | 4 +- lua/plugins/init.lua | 198 +++++++++++++++++------------ 9 files changed, 140 insertions(+), 217 deletions(-) diff --git a/lua/core/utils.lua b/lua/core/utils.lua index bc20de6..ea8edd0 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -85,37 +85,6 @@ M.load_mappings = function(section, mapping_opt) end end --- merge default/user plugin tables -M.merge_plugins = function(plugins) - local user_plugins = M.load_config().plugins - plugins = merge_tb("force", plugins, M.load_config().plugins) - - local final_table = {} - - for key, val in pairs(plugins) do - if val then - plugins[key] = (val.rm_default_opts and user_plugins[key]) or plugins[key] - plugins[key][1] = key - final_table[#final_table + 1] = plugins[key] - end - end - - return final_table -end - --- override plugin options table with custom ones -M.load_override = function(options_table, name) - local user_plugins = M.load_config().plugins - local plugin_options = {} - - if user_plugins[name] then - plugin_options = user_plugins[name].override_options or {} - plugin_options = type(plugin_options) == "table" and plugin_options or plugin_options() - end - - return merge_tb("force", options_table, plugin_options) -end - M.lazy_load = function(plugin) vim.api.nvim_create_autocmd({ "BufRead", "BufWinEnter", "BufNewFile" }, { group = vim.api.nvim_create_augroup("BeLazyOnFileOpen" .. plugin, {}), diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index 52e7d25..afa890f 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -115,7 +115,4 @@ if cmp_style ~= "atom" and cmp_style ~= "atom_colored" then options.window.completion.border = border "CmpBorder" end --- check for any override -options = require("core.utils").load_override(options, "hrsh7th/nvim-cmp") - -cmp.setup(options) +return options diff --git a/lua/plugins/configs/mason.lua b/lua/plugins/configs/mason.lua index 1fa7556..0777e0c 100644 --- a/lua/plugins/configs/mason.lua +++ b/lua/plugins/configs/mason.lua @@ -27,10 +27,4 @@ local options = { max_concurrent_installers = 10, } -options = require("core.utils").load_override(options, "williamboman/mason.nvim") - -vim.api.nvim_create_user_command("MasonInstallAll", function() - vim.cmd("MasonInstall " .. table.concat(options.ensure_installed, " ")) -end, {}) - -require("mason").setup(options) +return options diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index 1d884f7..1a260c1 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -75,8 +75,6 @@ local options = { }, } --- check for any override -options = require("core.utils").load_override(options, "nvim-tree/nvim-tree.lua") vim.g.nvimtree_side = options.view.side -require("nvim-tree").setup(options) +return options diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index a442e7d..b4bc6b7 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,62 +1,24 @@ local M = {} - -local load_override = require("core.utils").load_override local utils = require "core.utils" -M.autopairs = function() - local options = { - fast_wrap = {}, - disable_filetype = { "TelescopePrompt", "vim" }, - } - - options = load_override(options, "windwp/nvim-autopairs") - require("nvim-autopairs").setup(options) - - -- setup cmp for autopairs - local cmp_autopairs = require "nvim-autopairs.completion.cmp" - require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) -end - -M.blankline = function() - dofile(vim.g.base46_cache .. "blankline") - - local options = { - indentLine_enabled = 1, - filetype_exclude = { - "help", - "terminal", - "lazy", - "lspinfo", - "TelescopePrompt", - "TelescopeResults", - "mason", - "", - }, - buftype_exclude = { "terminal" }, - show_trailing_blankline_indent = false, - show_first_indent_level = false, - show_current_context = true, - show_current_context_start = true, - } - - options = load_override(options, "lukas-reineke/indent-blankline.nvim") - require("indent_blankline").setup(options) -end - -M.colorizer = function() - local options = {} - options = load_override(options, "NvChad/nvim-colorizer.lua") - require("colorizer").setup(options) - - -- execute colorizer as soon as possible - vim.defer_fn(function() - require("colorizer").attach_to_buffer(0) - end, 0) -end - -M.comment = function() - require("Comment").setup(load_override({}, "numToStr/Comment.nvim")) -end +M.blankline = { + indentLine_enabled = 1, + filetype_exclude = { + "help", + "terminal", + "lazy", + "lspinfo", + "TelescopePrompt", + "TelescopeResults", + "mason", + "", + }, + buftype_exclude = { "terminal" }, + show_trailing_blankline_indent = false, + show_first_indent_level = false, + show_current_context = true, + show_current_context_start = true, +} M.luasnip = function() local options = { @@ -64,7 +26,6 @@ M.luasnip = function() updateevents = "TextChanged,TextChangedI", } - options = load_override(options, "L3MON4D3/LuaSnip") require("luasnip").config.set_config(options) require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" } @@ -83,9 +44,7 @@ M.luasnip = function() end M.gitsigns = function() - dofile(vim.g.base46_cache .. "git") - - local options = { + return { signs = { add = { hl = "DiffAdd", text = "│", numhl = "GitSignsAddNr" }, change = { hl = "DiffChange", text = "│", numhl = "GitSignsChangeNr" }, @@ -98,18 +57,6 @@ M.gitsigns = function() utils.load_mappings("gitsigns", { buffer = bufnr }) end, } - - options = load_override(options, "lewis6991/gitsigns.nvim") - require("gitsigns").setup(options) -end - -M.devicons = function() - dofile(vim.g.base46_cache .. "devicons") - - local options = { override = require("nvchad_ui.icons").devicons } - options = require("core.utils").load_override(options, "nvim-tree/nvim-web-devicons") - - require("nvim-web-devicons").setup(options) end return M diff --git a/lua/plugins/configs/telescope.lua b/lua/plugins/configs/telescope.lua index 3c388fe..16eac04 100644 --- a/lua/plugins/configs/telescope.lua +++ b/lua/plugins/configs/telescope.lua @@ -54,13 +54,4 @@ local options = { extensions_list = { "themes", "terms" }, } -local telescope = require "telescope" - --- check for any override -options = require("core.utils").load_override(options, "nvim-telescope/telescope.nvim") -telescope.setup(options) - --- load extensions -for _, ext in ipairs(options.extensions_list) do - telescope.load_extension(ext) -end +return options diff --git a/lua/plugins/configs/treesitter.lua b/lua/plugins/configs/treesitter.lua index 782f36d..edea6ec 100644 --- a/lua/plugins/configs/treesitter.lua +++ b/lua/plugins/configs/treesitter.lua @@ -11,7 +11,4 @@ local options = { indent = { enable = true }, } --- check for any override -options = require("core.utils").load_override(options, "nvim-treesitter/nvim-treesitter") - -require("nvim-treesitter.configs").setup(options) +return options diff --git a/lua/plugins/configs/whichkey.lua b/lua/plugins/configs/whichkey.lua index ac8ae91..9ec4a68 100644 --- a/lua/plugins/configs/whichkey.lua +++ b/lua/plugins/configs/whichkey.lua @@ -30,6 +30,4 @@ local options = { }, } -options = require("core.utils").load_override(options, "folke/which-key.nvim") - -require("which-key").setup(options) +return options diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 0c33db9..77bccbc 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,16 +1,15 @@ -- All plugins have lazy=true by default,to load a plugin on startup just lazy=false -- List of all default plugins & their definitions -local plugins = { +local default_plugins = { - ["nvim-lua/plenary.nvim"] = {}, + "nvim-lua/plenary.nvim", - ["NvChad/extensions"] = { branch = "v2.0" }, + -- nvchad plugins + { "NvChad/extensions", branch = "v2.0" }, + { "NvChad/base46", branch = "v2.0" }, - ["NvChad/base46"] = { - branch = "v2.0", - }, - - ["NvChad/ui"] = { + { + "NvChad/ui", branch = "v2.0", lazy = false, config = function() @@ -18,55 +17,67 @@ local plugins = { end, }, - ["NvChad/nvterm"] = { - config = function() + { + "NvChad/nvterm", + init = require("core.utils").load_mappings "nvterm", + opts = {}, + config = function(_, opts) require "base46.term" - local options = require("core.utils").load_override({}, "NvChad/nvterm") - require("nvterm").setup(options) - end, - init = function() - require("core.utils").load_mappings "nvterm" + require("nvterm").setup(opts) end, }, - ["nvim-tree/nvim-web-devicons"] = { + { + "NvChad/nvim-colorizer.lua", + init = require("core.utils").lazy_load "nvim-colorizer.lua", config = function() - require("plugins.configs.others").devicons() + require("colorizer").setup() + + -- execute colorizer as soon as possible + vim.defer_fn(function() + require("colorizer").attach_to_buffer(0) + end, 0) end, }, - ["lukas-reineke/indent-blankline.nvim"] = { + { + "nvim-tree/nvim-web-devicons", + opts = function() + return { override = require("nvchad_ui.icons").devicons } + end, + config = function(_, opts) + dofile(vim.g.base46_cache .. "devicons") + require("nvim-web-devicons").setup(opts) + end, + }, + + { + "lukas-reineke/indent-blankline.nvim", init = function() require("core.utils").lazy_load "indent-blankline.nvim" require("core.utils").load_mappings "blankline" end, - config = function() - require("plugins.configs.others").blankline() + opts = require("plugins.configs.others").blankline, + config = function(_, opts) + dofile(vim.g.base46_cache .. "blankline") + require("indent_blankline").setup(opts) end, }, - ["NvChad/nvim-colorizer.lua"] = { - init = function() - require("core.utils").lazy_load "nvim-colorizer.lua" - end, - config = function() - require("plugins.configs.others").colorizer() - end, - }, - - ["nvim-treesitter/nvim-treesitter"] = { - init = function() - require("core.utils").lazy_load "nvim-treesitter" - end, - cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" }, + { + "nvim-treesitter/nvim-treesitter", + init = require("core.utils").lazy_load "nvim-treesitter", + cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, build = ":TSUpdate", - config = function() - require "plugins.configs.treesitter" + opts = require "plugins.configs.treesitter", + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) end, }, -- git stuff - ["lewis6991/gitsigns.nvim"] = { + { + "lewis6991/gitsigns.nvim", ft = "gitcommit", init = function() -- load gitsigns only when a git file is opened @@ -83,30 +94,37 @@ local plugins = { end, }) end, - config = function() - require("plugins.configs.others").gitsigns() + opts = require("plugins.configs.others").gitsigns, + config = function(_, opts) + dofile(vim.g.base46_cache .. "git") + require("gitsigns").setup(opts) end, }, -- lsp stuff - ["williamboman/mason.nvim"] = { + { + "williamboman/mason.nvim", cmd = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" }, - config = function() - require "plugins.configs.mason" + config = function(_, opts) + require("mason").setup(opts) + -- custom nvchad cmd to install all mason binaries listed + vim.api.nvim_create_user_command("MasonInstallAll", function() + vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " ")) + end, {}) end, }, - ["neovim/nvim-lspconfig"] = { - init = function() - require("core.utils").lazy_load "nvim-lspconfig" - end, + { + "neovim/nvim-lspconfig", + init = require("core.utils").lazy_load "nvim-lspconfig", config = function() require "plugins.configs.lspconfig" end, }, -- load luasnips + cmp related in insert mode only - ["hrsh7th/nvim-cmp"] = { + { + "hrsh7th/nvim-cmp", event = "InsertEnter", dependencies = { { @@ -121,8 +139,16 @@ local plugins = { -- autopairing of (){}[] etc { "windwp/nvim-autopairs", - config = function() - require("plugins.configs.others").autopairs() + opts = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + + -- setup cmp for autopairs + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) end, }, @@ -136,64 +162,70 @@ local plugins = { }, }, - config = function() - require "plugins.configs.cmp" + opts = function() + return require "plugins.configs.cmp" + end, + config = function(_, opts) + require("cmp").setup(opts) end, }, - ["numToStr/Comment.nvim"] = { + { + "numToStr/Comment.nvim", -- keys = { "gc", "gb" }, + init = require("core.utils").load_mappings "comment", config = function() - require("plugins.configs.others").comment() - end, - init = function() - require("core.utils").load_mappings "comment" + require("Comment").setup() end, }, -- file managing , picker etc - ["nvim-tree/nvim-tree.lua"] = { + { + "nvim-tree/nvim-tree.lua", cmd = { "NvimTreeToggle", "NvimTreeFocus" }, - config = function() - require "plugins.configs.nvimtree" - end, - init = function() - require("core.utils").load_mappings "nvimtree" + init = require("core.utils").load_mappings "nvimtree", + opts = require "plugins.configs.nvimtree", + config = function(_, opts) + require("nvim-tree").setup(opts) end, }, - ["nvim-telescope/telescope.nvim"] = { + { + "nvim-telescope/telescope.nvim", cmd = "Telescope", - config = function() - require "plugins.configs.telescope" + init = require("core.utils").load_mappings "telescope", + + opts = function() + return require "plugins.configs.telescope" end, - init = function() - require("core.utils").load_mappings "telescope" + + config = function(_, opts) + local telescope = require "telescope" + telescope.setup(opts) + + -- load extensions + for _, ext in ipairs(opts.extensions_list) do + telescope.load_extension(ext) + end end, }, -- Only load whichkey after all the gui - ["folke/which-key.nvim"] = { + { + "folke/which-key.nvim", enabled = false, keys = { "", '"', "'", "`" }, - config = function() - require "plugins.configs.whichkey" - end, - init = function() - require("core.utils").load_mappings "whichkey" + init = require("core.utils").load_mappings "whichkey", + opts = require "plugins.configs.whichkey", + config = function(_, opts) + require("which-key").setup(opts) end, }, + + { import = require("core.utils").load_config().plugins }, } --- pin commits for all default plugins -for _, value in pairs(plugins) do - value.pin = true -end - -plugins = require("core.utils").merge_plugins(plugins) - --- load lazy.nvim options +-- load lazy.nvim _,opts local lazy_config = require "plugins.configs.lazy_nvim" -lazy_config = require("core.utils").load_override(lazy_config, "folke/lazy.nvim") -require("lazy").setup(plugins, lazy_config) +require("lazy").setup(default_plugins, lazy_config)