From a2ee74b73adce481dd5f94e66621e4714ae46a36 Mon Sep 17 00:00:00 2001 From: Andrzej Stepien Date: Tue, 12 Mar 2024 16:13:19 +0100 Subject: [PATCH] rationalise plugin structure --- lua/plugins/bufferline.lua | 8 +++ lua/plugins/comment.lua | 6 ++ lua/plugins/completion.lua | 106 +++++++++++++++++++++++++++++++ lua/plugins/formatting.lua | 38 +++++++++++ lua/plugins/lazygit.lua | 16 +++++ lua/plugins/linting.lua | 43 +++++++++++++ lua/plugins/lsp/lspconfig.lua | 35 ++++++++++ lua/plugins/lsp/mason.lua | 41 ++++++++++++ lua/plugins/lualine.lua | 16 +++++ lua/plugins/neotree.lua | 9 +++ lua/plugins/themes/gruvbox.lua | 1 + lua/plugins/themes/rose-pine.lua | 2 + lua/plugins/treesitter.lua | 3 + lua/plugins/twilight.lua | 1 + lua/plugins/vim-pencil.lua | 1 + lua/plugins/which-key.lua | 12 ++++ lua/plugins/zen-mode.lua | 4 ++ 17 files changed, 342 insertions(+) create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/comment.lua create mode 100644 lua/plugins/completion.lua create mode 100644 lua/plugins/formatting.lua create mode 100644 lua/plugins/lazygit.lua create mode 100644 lua/plugins/linting.lua create mode 100644 lua/plugins/lsp/lspconfig.lua create mode 100644 lua/plugins/lsp/mason.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/neotree.lua create mode 100644 lua/plugins/themes/gruvbox.lua create mode 100644 lua/plugins/themes/rose-pine.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/plugins/twilight.lua create mode 100644 lua/plugins/vim-pencil.lua create mode 100644 lua/plugins/which-key.lua create mode 100644 lua/plugins/zen-mode.lua diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..de0df47 --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,8 @@ +return { + "akinsho/bufferline.nvim", + version = "*", + dependencies = "nvim-tree/nvim-web-devicons", + config = function() + require("bufferline").setup({}) + end, +} diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..3ab4c83 --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,6 @@ +return {'numToStr/Comment.nvim', + opts = { + -- add any options here + }, + lazy = false, + } diff --git a/lua/plugins/completion.lua b/lua/plugins/completion.lua new file mode 100644 index 0000000..fdf5751 --- /dev/null +++ b/lua/plugins/completion.lua @@ -0,0 +1,106 @@ +return { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + { + "L3MON4D3/LuaSnip", + -- follow latest release. + version = "v2.*", -- Replace by the latest released major (first number of latest release) + -- install jsregexp (optional!). + build = "make install_jsregexp", + dependencies = { "rafamadriz/friendly-snippets" }, + }, + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", + { + "hrsh7th/nvim-cmp", + config = function() + vim.opt.completeopt = { "menu", "menuone", "noselect" } + local cmp = require("cmp") + local luasnip = require("luasnip") + local select_opts = { behavior = cmp.SelectBehavior.Select } + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + sources = { + { name = "path" }, + { name = "nvim_lsp", keyword_length = 1 }, + { name = "buffer", keyword_length = 3 }, + { name = "luasnip", keyword_length = 2 }, + }, + window = { + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = { "menu", "abbr", "kind" }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = "λ", + luasnip = "⋗", + buffer = "Ω", + path = "🖫", + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(select_opts), + [""] = cmp.mapping.select_next_item(select_opts), + + [""] = cmp.mapping.select_prev_item(select_opts), + [""] = cmp.mapping.select_next_item(select_opts), + + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.confirm({ select = false }), + + [""] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + local col = vim.fn.col(".") - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then + fallback() + else + cmp.complete() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, { "i", "s" }), + }, + }) + end, + }, +} diff --git a/lua/plugins/formatting.lua b/lua/plugins/formatting.lua new file mode 100644 index 0000000..29a3f86 --- /dev/null +++ b/lua/plugins/formatting.lua @@ -0,0 +1,38 @@ +return { + "stevearc/conform.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = function() + local conform = require("conform") + + conform.setup({ + formatters_by_ft = { + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + svelte = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + markdown = { "prettier" }, + graphql = { "prettier" }, + lua = { "stylua" }, + python = { "isort", "black" }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500, + }, + }) + + vim.keymap.set({ "n", "v" }, "mp", function() + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 500, + }) + end, { desc = "Format file or range (in visual mode)" }) + end, +} diff --git a/lua/plugins/lazygit.lua b/lua/plugins/lazygit.lua new file mode 100644 index 0000000..8501574 --- /dev/null +++ b/lua/plugins/lazygit.lua @@ -0,0 +1,16 @@ +return { + { + "kdheepak/lazygit.nvim", + cmd = { + "LazyGit", + "LazyGitConfig", + "LazyGitCurrentFile", + "LazyGitFilter", + "LazyGitFilterCurrentFile", + }, + -- optional for floating window border decoration + dependencies = { + "nvim-lua/plenary.nvim", + }, + }, +} diff --git a/lua/plugins/linting.lua b/lua/plugins/linting.lua new file mode 100644 index 0000000..830ed82 --- /dev/null +++ b/lua/plugins/linting.lua @@ -0,0 +1,43 @@ +return { + { + "mfussenegger/nvim-lint", + event = { + "BufReadPre", + "BufNewFile", + }, + config = function() + local lint = require("lint") + + lint.linters_by_ft = { + javascript = { "eslint_d" }, + typescript = { "eslint_d" }, + javascriptreact = { "eslint_d" }, + typescriptreact = { "eslint_d" }, + svelte = { "eslint_d" }, + python = { "pylint" }, + markdown = { "proselint" }, + } + + local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true }) + + vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { + group = lint_augroup, + callback = function() + lint.try_lint() + end, + }) + + vim.keymap.set("n", "l", function() + lint.try_lint() + end, { desc = "Trigger linting for current file" }) + end, + }, + { + "WhoIsSethDaniel/toggle-lsp-diagnostics.nvim", + config = function() + require("toggle_lsp_diagnostics").init({ + start_on = false, + }) + end, + }, +} diff --git a/lua/plugins/lsp/lspconfig.lua b/lua/plugins/lsp/lspconfig.lua new file mode 100644 index 0000000..340998c --- /dev/null +++ b/lua/plugins/lsp/lspconfig.lua @@ -0,0 +1,35 @@ +return {"neovim/nvim-lspconfig", + config = function() + +local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities() +local lspconfig = require('lspconfig') +lspconfig.lua_ls.setup { + capabilities = lsp_capabilities, + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + }, + }, +} +-- lspconfig.ltex.setup { +-- capabilities = lsp_capabilities, +-- } +-- lspconfig.grammarly.setup { +-- capabilities = lsp_capabilities, +-- filetypes = { "markdown", "tex", "text", }, +-- init_options = { +-- clientId = "client_" +-- }, +-- root_dir = function(fname) +-- return require'lspconfig'.util.find_git_ancestor(fname) or vim.loop.os_homedir() +-- end, +-- } +-- lspconfig.marksman.setup { +-- capabilities = lsp_capabilities, +-- } + + end + + } diff --git a/lua/plugins/lsp/mason.lua b/lua/plugins/lsp/mason.lua new file mode 100644 index 0000000..e7b09e4 --- /dev/null +++ b/lua/plugins/lsp/mason.lua @@ -0,0 +1,41 @@ +return { + { + "williamboman/mason.nvim", + dependencies = { "WhoIsSethDaniel/mason-tool-installer.nvim" }, + config = function() + -- import mason + local mason = require("mason") + local mason_tool_installer = require("mason-tool-installer") + + -- enable mason and configure icons + mason.setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗", + }, + }, + }) + + mason_tool_installer.setup({ + ensure_installed = { + "prettier", -- prettier formatter + "stylua", -- lua formatter + "isort", -- python formatter + "black", -- python formatter + "pylint", -- python linter + "eslint_d", -- js linter + }, + }) + end, + }, + -- {"williamboman/mason-lspconfig.nvim", + -- config = function() + -- local mason_lspconfig = require("mason-lspconfig") + -- mason_lspconfig.setup { + -- ensure_installed = { "grammarly", "ltex" }, + -- } + -- end + -- } +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..5fe7015 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,16 @@ +return { + "nvim-lualine/lualine.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + config = function() + local function getWords() + return tostring(vim.fn.wordcount().words) + end + require("lualine").setup({ + sections = { + lualine_z = { getWords }, + }, + }) + end, +} diff --git a/lua/plugins/neotree.lua b/lua/plugins/neotree.lua new file mode 100644 index 0000000..1e06bc3 --- /dev/null +++ b/lua/plugins/neotree.lua @@ -0,0 +1,9 @@ +return {"nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information + } + } diff --git a/lua/plugins/themes/gruvbox.lua b/lua/plugins/themes/gruvbox.lua new file mode 100644 index 0000000..4c6a42e --- /dev/null +++ b/lua/plugins/themes/gruvbox.lua @@ -0,0 +1 @@ +return { "ellisonleao/gruvbox.nvim", priority = 1000 , config = true, opts = ...} diff --git a/lua/plugins/themes/rose-pine.lua b/lua/plugins/themes/rose-pine.lua new file mode 100644 index 0000000..8e1ba95 --- /dev/null +++ b/lua/plugins/themes/rose-pine.lua @@ -0,0 +1,2 @@ + +return {"rose-pine/neovim", name = "rose-pine"} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..aedc30d --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,3 @@ +return { + "nvim-treesitter/nvim-treesitter" + } diff --git a/lua/plugins/twilight.lua b/lua/plugins/twilight.lua new file mode 100644 index 0000000..331f88b --- /dev/null +++ b/lua/plugins/twilight.lua @@ -0,0 +1 @@ +return {"folke/twilight.nvim", opts = {context = 1}} diff --git a/lua/plugins/vim-pencil.lua b/lua/plugins/vim-pencil.lua new file mode 100644 index 0000000..14a85cf --- /dev/null +++ b/lua/plugins/vim-pencil.lua @@ -0,0 +1 @@ +return {"preservim/vim-pencil"} diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 0000000..2152461 --- /dev/null +++ b/lua/plugins/which-key.lua @@ -0,0 +1,12 @@ +return {"folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + } + } diff --git a/lua/plugins/zen-mode.lua b/lua/plugins/zen-mode.lua new file mode 100644 index 0000000..2f8fb25 --- /dev/null +++ b/lua/plugins/zen-mode.lua @@ -0,0 +1,4 @@ +return {"folke/zen-mode.nvim", + opts = { + window = {width = 60}} + }