From e307a4eacffcccbec8f8f292558967210a752a52 Mon Sep 17 00:00:00 2001 From: siduck Date: Mon, 4 Mar 2024 08:18:44 +0530 Subject: [PATCH] better plugin structure --- .gitignore | 10 -- .ignore | 1 - lua/nvchad/{plugins => configs}/gitsigns.lua | 11 +- .../configs/{lazy.lua => lazy_nvim.lua} | 0 lua/nvchad/configs/lspconfig.lua | 2 +- lua/nvchad/configs/luasnip.lua | 23 +++ lua/nvchad/configs/mason.lua | 28 ++++ lua/nvchad/{plugins => configs}/nvimtree.lua | 10 +- lua/nvchad/configs/telescope.lua | 63 ++++++++ lua/nvchad/configs/treesitter.lua | 12 ++ lua/nvchad/plugins/cmp.lua | 64 -------- lua/nvchad/plugins/init.lua | 148 ++++++++++++++++++ lua/nvchad/plugins/lsp.lua | 7 - lua/nvchad/plugins/mason.lua | 45 ------ lua/nvchad/plugins/telescope.lua | 80 ---------- lua/nvchad/plugins/treesitter.lua | 23 --- lua/nvchad/plugins/ui.lua | 51 +++--- 17 files changed, 300 insertions(+), 278 deletions(-) delete mode 100644 .gitignore delete mode 100644 .ignore rename lua/nvchad/{plugins => configs}/gitsigns.lua (75%) rename lua/nvchad/configs/{lazy.lua => lazy_nvim.lua} (100%) create mode 100644 lua/nvchad/configs/luasnip.lua create mode 100644 lua/nvchad/configs/mason.lua rename lua/nvchad/{plugins => configs}/nvimtree.lua (87%) create mode 100644 lua/nvchad/configs/telescope.lua create mode 100644 lua/nvchad/configs/treesitter.lua delete mode 100644 lua/nvchad/plugins/cmp.lua create mode 100644 lua/nvchad/plugins/init.lua delete mode 100644 lua/nvchad/plugins/lsp.lua delete mode 100644 lua/nvchad/plugins/mason.lua delete mode 100644 lua/nvchad/plugins/telescope.lua delete mode 100644 lua/nvchad/plugins/treesitter.lua diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d8a93d9..0000000 --- a/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -plugin -custom -spell -ftplugin -syntax -coc-settings.json -.luarc.json -lazy-lock.json -after -**/.DS_Store diff --git a/.ignore b/.ignore deleted file mode 100644 index 42677fb..0000000 --- a/.ignore +++ /dev/null @@ -1 +0,0 @@ -!/lua/custom/ diff --git a/lua/nvchad/plugins/gitsigns.lua b/lua/nvchad/configs/gitsigns.lua similarity index 75% rename from lua/nvchad/plugins/gitsigns.lua rename to lua/nvchad/configs/gitsigns.lua index ca7c70b..27f3105 100644 --- a/lua/nvchad/plugins/gitsigns.lua +++ b/lua/nvchad/configs/gitsigns.lua @@ -23,13 +23,4 @@ local options = { end, } -return { - "lewis6991/gitsigns.nvim", - event = "User FilePost", - opts = options, - - config = function(_, opts) - dofile(vim.g.base46_cache .. "git") - require("gitsigns").setup(opts) - end, -} +return options diff --git a/lua/nvchad/configs/lazy.lua b/lua/nvchad/configs/lazy_nvim.lua similarity index 100% rename from lua/nvchad/configs/lazy.lua rename to lua/nvchad/configs/lazy_nvim.lua diff --git a/lua/nvchad/configs/lspconfig.lua b/lua/nvchad/configs/lspconfig.lua index 3eb71a1..1b5adc9 100644 --- a/lua/nvchad/configs/lspconfig.lua +++ b/lua/nvchad/configs/lspconfig.lua @@ -22,7 +22,7 @@ M.on_attach = function(client, bufnr) map("n", "gd", vim.lsp.buf.definition, opts "Lsp Go to definition") map("n", "K", vim.lsp.buf.hover, opts "Lsp hover information") map("n", "gi", vim.lsp.buf.implementation, opts "Lsp Go to implementation") - map("n", "", vim.lsp.buf.signature_help, opts "Lsp Show signature help") + map("n", "sh", vim.lsp.buf.signature_help, opts "Lsp Show signature help") map("n", "wa", vim.lsp.buf.add_workspace_folder, opts "Lsp Add workspace folder") map("n", "wr", vim.lsp.buf.remove_workspace_folder, opts "Lsp Remove workspace folder") diff --git a/lua/nvchad/configs/luasnip.lua b/lua/nvchad/configs/luasnip.lua new file mode 100644 index 0000000..f40672d --- /dev/null +++ b/lua/nvchad/configs/luasnip.lua @@ -0,0 +1,23 @@ +-- vscode format +require("luasnip.loaders.from_vscode").lazy_load() +require("luasnip.loaders.from_vscode").lazy_load { paths = "your path!" } +require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.vscode_snippets_path or "" } + +-- snipmate format +require("luasnip.loaders.from_snipmate").load() +require("luasnip.loaders.from_snipmate").lazy_load { paths = vim.g.snipmate_snippets_path or "" } + +-- lua format +require("luasnip.loaders.from_lua").load() +require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" } + +vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, +}) diff --git a/lua/nvchad/configs/mason.lua b/lua/nvchad/configs/mason.lua new file mode 100644 index 0000000..3692a15 --- /dev/null +++ b/lua/nvchad/configs/mason.lua @@ -0,0 +1,28 @@ +local options = { + ensure_installed = { "lua-language-server" }, -- not an option from mason.nvim + + PATH = "skip", + + ui = { + icons = { + package_pending = " ", + package_installed = "󰄳 ", + package_uninstalled = " 󰚌", + }, + + keymaps = { + toggle_server_expand = "", + install_server = "i", + update_server = "u", + check_server_version = "c", + update_all_servers = "U", + check_outdated_servers = "C", + uninstall_server = "X", + cancel_installation = "", + }, + }, + + max_concurrent_installers = 10, +} + +return options diff --git a/lua/nvchad/plugins/nvimtree.lua b/lua/nvchad/configs/nvimtree.lua similarity index 87% rename from lua/nvchad/plugins/nvimtree.lua rename to lua/nvchad/configs/nvimtree.lua index cf8bdb0..c54248e 100644 --- a/lua/nvchad/plugins/nvimtree.lua +++ b/lua/nvchad/configs/nvimtree.lua @@ -74,12 +74,4 @@ local options = { }, } -return { - "nvim-tree/nvim-tree.lua", - cmd = { "NvimTreeToggle", "NvimTreeFocus" }, - opts = options, - config = function(_, opts) - dofile(vim.g.base46_cache .. "nvimtree") - require("nvim-tree").setup(opts) - end, -} +return options diff --git a/lua/nvchad/configs/telescope.lua b/lua/nvchad/configs/telescope.lua new file mode 100644 index 0000000..0df500e --- /dev/null +++ b/lua/nvchad/configs/telescope.lua @@ -0,0 +1,63 @@ +local options = { + defaults = { + vimgrep_arguments = { + "rg", + "-L", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.55, + results_width = 0.8, + }, + vertical = { + mirror = false, + }, + width = 0.87, + height = 0.80, + preview_cutoff = 120, + }, + file_sorter = require("telescope.sorters").get_fuzzy_file, + file_ignore_patterns = { "node_modules" }, + generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, + path_display = { "truncate" }, + winblend = 0, + border = {}, + borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + color_devicons = true, + set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, + mappings = { + n = { ["q"] = require("telescope.actions").close }, + }, + }, + + extensions_list = { "themes", "terms" }, + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case", + }, + }, +} + +return options diff --git a/lua/nvchad/configs/treesitter.lua b/lua/nvchad/configs/treesitter.lua new file mode 100644 index 0000000..897c4e3 --- /dev/null +++ b/lua/nvchad/configs/treesitter.lua @@ -0,0 +1,12 @@ +local options = { + ensure_installed = { "lua", "vim", "vimdoc" }, + + highlight = { + enable = true, + use_languagetree = true, + }, + + indent = { enable = true }, +} + +return options diff --git a/lua/nvchad/plugins/cmp.lua b/lua/nvchad/plugins/cmp.lua deleted file mode 100644 index 44fb8be..0000000 --- a/lua/nvchad/plugins/cmp.lua +++ /dev/null @@ -1,64 +0,0 @@ -return { - "hrsh7th/nvim-cmp", - event = "InsertEnter", - - opts = function() - return require "nvchad.configs.cmp" - end, - - config = function(_, opts) - require("cmp").setup(opts) - end, - - dependencies = { - { - -- snippet plugin - "L3MON4D3/LuaSnip", - dependencies = "rafamadriz/friendly-snippets", - opts = { history = true, updateevents = "TextChanged,TextChangedI" }, - config = function(_, opts) - require("luasnip").config.set_config(opts) - - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_snipmate").load() - require("luasnip.loaders.from_lua").load() - - vim.api.nvim_create_autocmd("InsertLeave", { - callback = function() - if - require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] - and not require("luasnip").session.jump_active - then - require("luasnip").unlink_current() - end - end, - }) - end, - }, - - -- autopairing of (){}[] etc - { - "windwp/nvim-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, - }, - - -- cmp sources plugins - { - "saadparwaiz1/cmp_luasnip", - "hrsh7th/cmp-nvim-lua", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - }, - }, -} diff --git a/lua/nvchad/plugins/init.lua b/lua/nvchad/plugins/init.lua new file mode 100644 index 0000000..7785c48 --- /dev/null +++ b/lua/nvchad/plugins/init.lua @@ -0,0 +1,148 @@ +return { + + "nvim-lua/plenary.nvim", + + { + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile" }, + cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, + build = ":TSUpdate", + opts = function() + return require "nvchad.configs.treesitter" + end, + config = function(_, opts) + dofile(vim.g.base46_cache .. "syntax") + dofile(vim.g.base46_cache .. "treesitter") + require("nvim-treesitter.configs").setup(opts) + end, + }, + + -- git stuff + { + "lewis6991/gitsigns.nvim", + event = "User FilePost", + opts = function() + return require "nvchad.configs.gitsigns" + end, + config = function(_, opts) + dofile(vim.g.base46_cache .. "git") + require("gitsigns").setup(opts) + end, + }, + + -- lsp stuff + { + "williamboman/mason.nvim", + cmd = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUpdate" }, + opts = function() + return require "nvchad.configs.mason" + end, + config = function(_, opts) + dofile(vim.g.base46_cache .. "mason") + require("mason").setup(opts) + + -- custom nvchad cmd to install all mason binaries listed + vim.api.nvim_create_user_command("MasonInstallAll", function() + if opts.ensure_installed and #opts.ensure_installed > 0 then + vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " ")) + end + end, {}) + + vim.g.mason_binaries_list = opts.ensure_installed + end, + }, + + { + "neovim/nvim-lspconfig", + event = "User FilePost", + config = function() + require("nvchad.configs.lspconfig").defaults() + end, + }, + + -- load luasnips + cmp related in insert mode only + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + { + -- snippet plugin + "L3MON4D3/LuaSnip", + dependencies = "rafamadriz/friendly-snippets", + opts = { history = true, updateevents = "TextChanged,TextChangedI" }, + config = function(_, opts) + require("luasnip").config.set_config(opts) + require "nvchad.configs.luasnip" + end, + }, + + -- autopairing of (){}[] etc + { + "windwp/nvim-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, + }, + + -- cmp sources plugins + { + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + }, + }, + opts = function() + return require "nvchad.configs.cmp" + end, + config = function(_, opts) + require("cmp").setup(opts) + end, + }, + + { + "numToStr/Comment.nvim", + keys = { + { "gcc", mode = "n", desc = "Comment toggle current line" }, + { "gc", mode = { "n", "o" }, desc = "Comment toggle linewise" }, + { "gc", mode = "x", desc = "Comment toggle linewise (visual)" }, + { "gbc", mode = "n", desc = "Comment toggle current block" }, + { "gb", mode = { "n", "o" }, desc = "Comment toggle blockwise" }, + { "gb", mode = "x", desc = "Comment toggle blockwise (visual)" }, + }, + init = function() + vim.g.comment_maps = true + end, + config = function(_, opts) + require("Comment").setup(opts) + end, + }, + + { + "nvim-telescope/telescope.nvim", + dependencies = { "nvim-treesitter/nvim-treesitter" }, + cmd = "Telescope", + opts = function() + return require "nvchad.configs.telescope" + end, + config = function(_, opts) + dofile(vim.g.base46_cache .. "telescope") + local telescope = require "telescope" + telescope.setup(opts) + + -- load extensions + for _, ext in ipairs(opts.extensions_list) do + telescope.load_extension(ext) + end + end, + }, +} diff --git a/lua/nvchad/plugins/lsp.lua b/lua/nvchad/plugins/lsp.lua deleted file mode 100644 index e42fa1a..0000000 --- a/lua/nvchad/plugins/lsp.lua +++ /dev/null @@ -1,7 +0,0 @@ -return { - "neovim/nvim-lspconfig", - event = "User FilePost", - config = function() - require("nvchad.configs.lspconfig").defaults() - end, -} diff --git a/lua/nvchad/plugins/mason.lua b/lua/nvchad/plugins/mason.lua deleted file mode 100644 index 9f8248f..0000000 --- a/lua/nvchad/plugins/mason.lua +++ /dev/null @@ -1,45 +0,0 @@ -local options = { - ensure_installed = { "lua-language-server" }, -- not an option from mason.nvim - - PATH = "skip", - - ui = { - icons = { - package_pending = " ", - package_installed = "󰄳 ", - package_uninstalled = " 󰚌", - }, - - keymaps = { - toggle_server_expand = "", - install_server = "i", - update_server = "u", - check_server_version = "c", - update_all_servers = "U", - check_outdated_servers = "C", - uninstall_server = "X", - cancel_installation = "", - }, - }, - - max_concurrent_installers = 10, -} - -return { - "williamboman/mason.nvim", - cmd = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUpdate" }, - opts = options, - config = function(_, opts) - dofile(vim.g.base46_cache .. "mason") - require("mason").setup(opts) - - -- custom nvchad cmd to install all mason binaries listed - vim.api.nvim_create_user_command("MasonInstallAll", function() - if opts.ensure_installed and #opts.ensure_installed > 0 then - vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " ")) - end - end, {}) - - vim.g.mason_binaries_list = opts.ensure_installed - end, -} diff --git a/lua/nvchad/plugins/telescope.lua b/lua/nvchad/plugins/telescope.lua deleted file mode 100644 index c441438..0000000 --- a/lua/nvchad/plugins/telescope.lua +++ /dev/null @@ -1,80 +0,0 @@ -return { - "nvim-telescope/telescope.nvim", - dependencies = { "nvim-treesitter/nvim-treesitter" }, - cmd = "Telescope", - opts = function() - local options = { - defaults = { - vimgrep_arguments = { - "rg", - "-L", - "--color=never", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - "--smart-case", - }, - prompt_prefix = "  ", - selection_caret = " ", - entry_prefix = " ", - initial_mode = "insert", - selection_strategy = "reset", - sorting_strategy = "ascending", - layout_strategy = "horizontal", - layout_config = { - horizontal = { - prompt_position = "top", - preview_width = 0.55, - results_width = 0.8, - }, - vertical = { - mirror = false, - }, - width = 0.87, - height = 0.80, - preview_cutoff = 120, - }, - file_sorter = require("telescope.sorters").get_fuzzy_file, - file_ignore_patterns = { "node_modules" }, - generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, - path_display = { "truncate" }, - winblend = 0, - border = {}, - borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, - color_devicons = true, - set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, - file_previewer = require("telescope.previewers").vim_buffer_cat.new, - grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, - qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, - -- Developer configurations: Not meant for general override - buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, - mappings = { - n = { ["q"] = require("telescope.actions").close }, - }, - }, - - extensions_list = { "themes", "terms" }, - extensions = { - fzf = { - fuzzy = true, - override_generic_sorter = true, - override_file_sorter = true, - case_mode = "smart_case", - }, - }, - } - - return options - end, - config = function(_, opts) - dofile(vim.g.base46_cache .. "telescope") - local telescope = require "telescope" - telescope.setup(opts) - - -- load extensions - for _, ext in ipairs(opts.extensions_list) do - telescope.load_extension(ext) - end - end, -} diff --git a/lua/nvchad/plugins/treesitter.lua b/lua/nvchad/plugins/treesitter.lua deleted file mode 100644 index d940c95..0000000 --- a/lua/nvchad/plugins/treesitter.lua +++ /dev/null @@ -1,23 +0,0 @@ -local config = { - ensure_installed = { "lua", "vim", "vimdoc" }, - - highlight = { - enable = true, - use_languagetree = true, - }, - - indent = { enable = true }, -} - -return { - "nvim-treesitter/nvim-treesitter", - event = { "BufReadPost", "BufNewFile" }, - cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, - build = ":TSUpdate", - opts = config, - config = function(_, opts) - dofile(vim.g.base46_cache .. "syntax") - dofile(vim.g.base46_cache .. "treesitter") - require("nvim-treesitter.configs").setup(opts) - end, -} diff --git a/lua/nvchad/plugins/ui.lua b/lua/nvchad/plugins/ui.lua index 0c5fad3..34a6a97 100644 --- a/lua/nvchad/plugins/ui.lua +++ b/lua/nvchad/plugins/ui.lua @@ -1,5 +1,4 @@ return { - "nvim-lua/plenary.nvim", { "NvChad/base46", @@ -42,40 +41,13 @@ return { end, }, - { - "folke/which-key.nvim", - keys = { "", "", "", '"', "'", "`", "c", "v", "g" }, - cmd = "WhichKey", - config = function(_, opts) - dofile(vim.g.base46_cache .. "whichkey") - require("which-key").setup(opts) - end, - }, - - { - "numToStr/Comment.nvim", - keys = { - { "gcc", mode = "n", desc = "Comment toggle current line" }, - { "gc", mode = { "n", "o" }, desc = "Comment toggle linewise" }, - { "gc", mode = "x", desc = "Comment toggle linewise (visual)" }, - { "gbc", mode = "n", desc = "Comment toggle current block" }, - { "gb", mode = { "n", "o" }, desc = "Comment toggle blockwise" }, - { "gb", mode = "x", desc = "Comment toggle blockwise (visual)" }, - }, - config = function(_, opts) - require("Comment").setup(opts) - end, - }, - { "lukas-reineke/indent-blankline.nvim", event = "User FilePost", - opts = { indent = { char = "│", highlight = "IblChar" }, scope = { char = "│", highlight = "IblScopeChar" }, }, - config = function(_, opts) dofile(vim.g.base46_cache .. "blankline") @@ -84,4 +56,27 @@ return { require("ibl").setup(opts) end, }, + + -- file managing , picker etc + { + "nvim-tree/nvim-tree.lua", + cmd = { "NvimTreeToggle", "NvimTreeFocus" }, + opts = function() + return require "nvchad.configs.nvimtree" + end, + config = function(_, opts) + dofile(vim.g.base46_cache .. "nvimtree") + require("nvim-tree").setup(opts) + end, + }, + + { + "folke/which-key.nvim", + keys = { "", "", "", '"', "'", "`", "c", "v", "g" }, + cmd = "WhichKey", + config = function(_, opts) + dofile(vim.g.base46_cache .. "whichkey") + require("which-key").setup(opts) + end, + }, }