From 1f97480ac0dc48c1b271a5bdd5c0f313f32d9804 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Tue, 14 Feb 2023 01:52:56 +0000 Subject: [PATCH] refactor(nvim): remove comments and refactor binds --- dot_config/nvim/lua/lsp/init.lua | 75 +++++++++------------- dot_config/nvim/lua/lsp/java.lua | 30 +++------ dot_config/nvim/lua/plugins/alpha.lua | 23 ++----- dot_config/nvim/lua/plugins/cmp.lua | 28 +------- dot_config/nvim/lua/plugins/dap.lua | 2 - dot_config/nvim/lua/plugins/feline.lua | 1 - dot_config/nvim/lua/plugins/gitsigns.lua | 5 -- dot_config/nvim/lua/plugins/lsp.lua | 45 +++++++++---- dot_config/nvim/lua/plugins/surround.lua | 5 +- dot_config/nvim/lua/plugins/treesitter.lua | 4 ++ 10 files changed, 88 insertions(+), 130 deletions(-) diff --git a/dot_config/nvim/lua/lsp/init.lua b/dot_config/nvim/lua/lsp/init.lua index 52a2de9..200b316 100644 --- a/dot_config/nvim/lua/lsp/init.lua +++ b/dot_config/nvim/lua/lsp/init.lua @@ -1,53 +1,38 @@ local M = {} -M.default_config = { - on_attach = function(client, bufnr) - require("lsp_signature").on_attach({}, bufnr) - - -- add lsp-only keybinds - local map = function(sequence, cmd, desc) - vim.keymap.set("n", sequence, cmd, { buffer = bufnr, desc = desc }) - end +local map = function(mode, lhs, rhs, opts) + vim.keymap.set(mode, lhs, rhs, { buffer = opts[1], desc = opts[2] }) +end +M.map = map - map("K", vim.lsp.buf.hover, "Hover") - map("]d", vim.diagnostic.goto_next, "Next diagnostic") - map("[d", vim.diagnostic.goto_prev, "Previous diagnostic") +M.default_config = { + on_attach = function(_, bufnr) + map("n", "K", vim.lsp.buf.hover, { bufnr, "Hover Information" }) + map("n", "]d", vim.diagnostic.goto_next, { bufnr, "Next Diagnostic" }) + map("n", "[d", vim.diagnostic.goto_prev, { bufnr, "Previous Diagnostic" }) - map("gs", vim.lsp.buf.signature_help, "LSP Signature Help") - map("gD", vim.lsp.buf.declaration, "LSP Declarations") - map("gd", function() - require("telescope.builtin").lsp_definitions() - end, "LSP Definitions") - map("gT", function() - require("telescope.builtin").lsp_type_definitions() - end, "LSP Type Definitions") - map("gr", function() - require("telescope.builtin").lsp_references() - end, "LSP References") - map("gI", function() - require("telescope.builtin").lsp_implementations() - end, "LSP Implementations") - map("gl", function() - vim.diagnostic.open_float(0, { - scope = "line", - }) - end) + map("n", "gs", vim.lsp.buf.signature_help, { bufnr, "Signature Help" }) + map("n", "gD", vim.lsp.buf.declaration, { bufnr, "Declarations" }) + map("n", "gd", "Telescope lsp_definitions", { bufnr, "Definitions" }) + map("n", "gT", "Telescope lsp_type_definitions", { bufnr, "Type Definitions" }) + map("n", "gr", "Telescope lsp_references", { bufnr, "References" }) + map("n", "gI", "Telescope lsp_implementations", { bufnr, "Implementations" }) + map("n", "gl", function() + vim.diagnostic.open_float(0, { scope = "line" }) + end, { bufnr, "LSP Line Diagnostics" }) - map("la", vim.lsp.buf.code_action, "Code Action") - map("lr", vim.lsp.buf.rename, "Rename") - map("lf", vim.lsp.buf.format, "Format") - map("ld", function() - require("telescope.builtin").diagnostics() - end, "LSP Workplace Diagnostics") - map("lD", function() - require("telescope.builtin").diagnostics({ bufnr = 0 }) - end, "LSP Buffer Diagnostics") - map("ls", function() - require("telescope.builtin").lsp_document_symbols() - end, "LSP Document Symbols") - map("lS", function() - require("telescope.builtin").lsp_workspace_symbols() - end, "LSP Workplace Symbols") + map("n", "la", vim.lsp.buf.code_action, { bufnr, "Code Action" }) + map("n", "lr", vim.lsp.buf.rename, { bufnr, "Rename" }) + map("n", "lf", vim.lsp.buf.format, { bufnr, "Format" }) + map("n", "ld", "Telescope diagnostics", { bufnr, "Workspace Diagnostics" }) + map("n", "lD", "Telescope diagnostics bufnr=0", { bufnr, "Buffer Diagnostics" }) + map("n", "ls", "Telescope lsp_document_symbols", { bufnr, "Document Symbols" }) + map("n", "lS", "Telescope lsp_workspace_symbols", { bufnr, "Workspace Symbols" }) + map("n", "lwa", vim.lsp.buf.add_workspace_folder, { bufnr, "Add Workspace Folder" }) + map("n", "lwr", vim.lsp.buf.remove_workspace_folder, { bufnr, "Remove Workspace Folder" }) + map("n", "lwl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, { bufnr, "List Workspace Folders" }) end, } diff --git a/dot_config/nvim/lua/lsp/java.lua b/dot_config/nvim/lua/lsp/java.lua index ab49801..bd13ac8 100644 --- a/dot_config/nvim/lua/lsp/java.lua +++ b/dot_config/nvim/lua/lsp/java.lua @@ -2,7 +2,10 @@ local M = {} local HOME = os.getenv("HOME") local SDKMAN_DIR = os.getenv("SDKMAN_DIR") + local lsp = require("lsp") +local map = lsp.map + local jdtls = require("jdtls") local bundles = {} @@ -25,31 +28,18 @@ local function nnoremap(rhs, lhs, bufopts, desc) end local on_attach = function(client, bufnr) + lsp.default_config.on_attach(client, bufnr) require("jdtls").setup_dap({ hotcodereplace = "auto" }) require("jdtls.dap").setup_dap_main_class_configs() require("jdtls.setup").add_commands() - lsp.default_config.on_attach(client, bufnr) - - -- Regular Neovim LSP client keymappings - local bufopts = { noremap = true, silent = true, buffer = bufnr } - nnoremap("lwa", vim.lsp.buf.add_workspace_folder, bufopts, "Add workspace folder") - nnoremap("lwr", vim.lsp.buf.remove_workspace_folder, bufopts, "Remove workspace folder") - nnoremap("lwl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts, "List workspace folders") -- Java extensions provided by jdtls - nnoremap("lo", jdtls.organize_imports, bufopts, "Organize imports") - nnoremap("le", jdtls.extract_variable, bufopts, "Extract variable") - nnoremap("lc", jdtls.extract_constant, bufopts, "Extract constant") - vim.keymap.set( - "v", - "lm", - [[lua require('jdtls').extract_method(true)]], - { noremap = true, silent = true, buffer = bufnr, desc = "Extract method" } - ) - nnoremap("tc", jdtls.test_class, bufopts, "Test class (DAP)") - nnoremap("tm", jdtls.test_nearest_method, bufopts, "Test method (DAP)") + map("n", "lo", jdtls.organize_imports, { bufnr, "Organize Imports" }) + map("n", "lle", jdtls.extract_variable, { bufnr, "Extract Variable" }) + map("n", "llc", jdtls.extract_constant, { bufnr, "Extract Constant" }) + map("v", "llm", "lua require('jdtls').extract_method(true)", { bufnr, "Extract Method" }) + map("n", "ltc", jdtls.test_class, { bufnr, "Test Class (DAP)" }) + map("n", "ltm", jdtls.test_nearest_method, { bufnr, "Test Method (DAP)" }) end function M.make_jdtls_config(root_dir, workspace_folder) diff --git a/dot_config/nvim/lua/plugins/alpha.lua b/dot_config/nvim/lua/plugins/alpha.lua index d199551..6b3c7f5 100644 --- a/dot_config/nvim/lua/plugins/alpha.lua +++ b/dot_config/nvim/lua/plugins/alpha.lua @@ -3,7 +3,6 @@ return { "goolord/alpha-nvim", config = function() local alpha = require("alpha") - -- require("alpha.term") local dashboard = require("alpha.themes.dashboard") dashboard.section.header.val = { [[================= =============== =============== ======== ========]], @@ -28,16 +27,15 @@ return { } dashboard.section.buttons.val = { - dashboard.button("f", " Find a file", ":Telescope find_files"), - dashboard.button("e", " New file", ":ene startinsert"), - dashboard.button("p", " Find a project", ":Telescope projects"), - dashboard.button("r", " Recently used files", ":Telescope oldfiles"), - dashboard.button("t", " Find text", ":Telescope live_grep"), + dashboard.button("f", " Find File", ":Telescope find_files"), + dashboard.button("e", " New File", ":ene startinsert"), + dashboard.button("p", " Find Project", ":Telescope projects"), + dashboard.button("r", " Recent Files", ":Telescope oldfiles"), + dashboard.button("t", " Find Text", ":Telescope live_grep"), dashboard.button("c", " Configuration", ":e $MYVIMRC"), dashboard.button("q", " Quit Neovim", ":qa"), } local function footer() - -- Number of plugins local total_plugins = require("lazy").stats().count local datetime = os.date("%d-%m-%Y %H:%M:%S") local plugins_text = "  " @@ -56,18 +54,10 @@ return { dashboard.section.footer.val = footer() dashboard.section.footer.opts.hl = "Type" - -- dashboard.section.header.opts.hl = "Include" dashboard.section.buttons.opts.hl = "Keyword" dashboard.opts.opts.noautocmd = false - -- local width = 52 -- 104 - -- local height = 15 -- 28 - -- dashboard.section.terminal.command = "cat | " .. os.getenv("HOME") .. "/.config/nvim/doom/render.sh" - -- dashboard.section.terminal.width = width - -- dashboard.section.terminal.height = height - -- dashboard.section.terminal.opts.redraw = true - -- dashboard.config.layout = { { type = "padding", val = 3 }, dashboard.section.header, @@ -76,9 +66,6 @@ return { { type = "padding", val = 1 }, dashboard.section.footer, } - dashboard.config.setup = function() - vim.b.miniindentscope_disable = true - end alpha.setup(dashboard.opts) end, diff --git a/dot_config/nvim/lua/plugins/cmp.lua b/dot_config/nvim/lua/plugins/cmp.lua index dd31f14..50f5df6 100644 --- a/dot_config/nvim/lua/plugins/cmp.lua +++ b/dot_config/nvim/lua/plugins/cmp.lua @@ -1,10 +1,4 @@ --- local has_words_before = function() --- local line, col = unpack(vim.api.nvim_win_get_cursor(0)) --- return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil --- end --- return { - -- snippets { "L3MON4D3/LuaSnip", dependencies = { @@ -59,27 +53,6 @@ return { [""] = cmp.mapping.complete({}), [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), - -- [""] = cmp.mapping(function(fallback) - -- if cmp.visible() then - -- cmp.select_next_item() - -- elseif luasnip.expand_or_jumpable() then - -- luasnip.expand_or_jump() - -- elseif has_words_before() then - -- cmp.complete() - -- else - -- fallback() - -- end - -- end, { "i", "s" }), - -- - -- [""] = cmp.mapping(function(fallback) - -- if cmp.visible() then - -- cmp.select_prev_item() - -- elseif luasnip.jumpable(-1) then - -- luasnip.jump(-1) - -- else - -- fallback() - -- end - -- end, { "i", "s" }), }), sources = cmp.config.sources({ { name = "nvim_lsp" }, @@ -134,6 +107,7 @@ return { "hrsh7th/cmp-cmdline", "saadparwaiz1/cmp_luasnip", "lukas-reineke/cmp-under-comparator", + "onsails/lspkind.nvim", }, }, } diff --git a/dot_config/nvim/lua/plugins/dap.lua b/dot_config/nvim/lua/plugins/dap.lua index db8c7aa..52cfd75 100644 --- a/dot_config/nvim/lua/plugins/dap.lua +++ b/dot_config/nvim/lua/plugins/dap.lua @@ -67,7 +67,6 @@ return { -- apply suggestions from catppuccin theme local sign = vim.fn.sign_define - sign("DapBreakpoint", { text = "●", texthl = "DapBreakpoint", linehl = "DapBreakpointLinehl", numhl = "" }) sign("DapStopped", { text = "", texthl = "Error", linehl = "DapStoppedLinehl", numhl = "" }) sign("DapBreakpointCondition", { text = "●", texthl = "DapBreakpointCondition", linehl = "", numhl = "" }) @@ -116,7 +115,6 @@ return { { id = "stacks", size = 0.15, }, { id = "repl", size = 0.05, }, { id = "scopes", size = 0.40, }, - -- { id = "breakpoints", size = 0.25, }, { id = "watches", size = 0.40, }, }, position = "left", diff --git a/dot_config/nvim/lua/plugins/feline.lua b/dot_config/nvim/lua/plugins/feline.lua index 6074233..1f8d95e 100644 --- a/dot_config/nvim/lua/plugins/feline.lua +++ b/dot_config/nvim/lua/plugins/feline.lua @@ -9,7 +9,6 @@ return { components = ctp_feline.get(), force_inactive = { filetypes = { - -- "^NvimTree$", "^packer$", "^startify$", "^fugitive$", diff --git a/dot_config/nvim/lua/plugins/gitsigns.lua b/dot_config/nvim/lua/plugins/gitsigns.lua index 141ba66..f2dac72 100644 --- a/dot_config/nvim/lua/plugins/gitsigns.lua +++ b/dot_config/nvim/lua/plugins/gitsigns.lua @@ -1,7 +1,6 @@ return { { "lewis6991/gitsigns.nvim", - priority = 500, config = function() require("gitsigns").setup({ on_attach = function(bufnr) @@ -47,10 +46,6 @@ return { gs.blame_line({ full = true }) end, {}, "Show Blame") map("n", "gb", gs.toggle_current_line_blame, {}, "Current Line Blame") - -- map("n", "gd", gs.diffthis, {}, "Diff This") - -- map("n", "gD", function() - -- gs.diffthis("~") - -- end, {}, "") map("n", "gd", gs.toggle_deleted, {}, "Show Deleted") -- Text object diff --git a/dot_config/nvim/lua/plugins/lsp.lua b/dot_config/nvim/lua/plugins/lsp.lua index 8a7f6dc..46f5d40 100644 --- a/dot_config/nvim/lua/plugins/lsp.lua +++ b/dot_config/nvim/lua/plugins/lsp.lua @@ -36,13 +36,26 @@ return { "williamboman/mason-lspconfig.nvim", config = function() require("mason-lspconfig").setup({ - ensure_installed = { "rust_analyzer", "pyright", "sumneko_lua" }, + ensure_installed = { "rust_analyzer", "pyright", "lua_ls" }, }) require("mason-lspconfig").setup_handlers({ -- default handler function(server_name) require("lspconfig")[server_name].setup(lsp.default_config) end, + + ["ltex"] = function() + require("lspconfig")["ltex"].setup({ + on_attach = function(_, _) + require("ltex_extra").setup({ + load_langs = { "es-AR", "en-US" }, + init_check = true, + path = vim.fn.stdpath("data") .. "/dictionary", + }) + end, + }) + end, + ["rust_analyzer"] = function() -- https://github.com/simrat39/rust-tools.nvim/issues/300 local config = custom_config({ @@ -67,9 +80,11 @@ return { }, }) end, + ["pyright"] = function() require("py_lsp").setup(lsp.default_config) end, + ["hls"] = function() local ht = require("haskell-tools") local def_opts = { noremap = true, silent = true } @@ -86,15 +101,16 @@ return { }) -- Suggested keymaps that do not depend on haskell-language-server -- Toggle a GHCi repl for the current package - vim.keymap.set("n", "rr", ht.repl.toggle, def_opts) + -- vim.keymap.set("n", "rr", ht.repl.toggle, def_opts) -- Toggle a GHCi repl for the current buffer - vim.keymap.set("n", "rf", function() - ht.repl.toggle(vim.api.nvim_buf_get_name(0)) - end, def_opts) - vim.keymap.set("n", "rq", ht.repl.quit, def_opts) + -- vim.keymap.set("n", "rf", function() + -- ht.repl.toggle(vim.api.nvim_buf_get_name(0)) + -- end, def_opts) + -- vim.keymap.set("n", "rq", ht.repl.quit, def_opts) end, - ["sumneko_lua"] = function() - require("lspconfig")["sumneko_lua"].setup(custom_config({ + + ["lua_ls"] = function() + require("lspconfig")["lua_ls"].setup(custom_config({ settings = { Lua = { format = { @@ -126,8 +142,15 @@ return { "mrcjkb/haskell-tools.nvim", "HallerPatrick/py_lsp.nvim", "mfussenegger/nvim-jdtls", - "onsails/lspkind.nvim", - "ray-x/lsp_signature.nvim" , + { + "ray-x/lsp_signature.nvim", + opts = { + hint_enable = false, + hint_prefix = "", + }, + }, + "barreiroleo/ltex_extra.nvim", + "lervag/vimtex", }, }, { @@ -155,7 +178,7 @@ return { { "jay-babu/mason-null-ls.nvim", opts = { - ensure_installed = { "stylua" }, + ensure_installed = { "stylua", "markdownlint", "clang-format" }, }, }, } diff --git a/dot_config/nvim/lua/plugins/surround.lua b/dot_config/nvim/lua/plugins/surround.lua index f3863df..b779ed0 100644 --- a/dot_config/nvim/lua/plugins/surround.lua +++ b/dot_config/nvim/lua/plugins/surround.lua @@ -1,3 +1,6 @@ return { - { "kylechui/nvim-surround", config = true }, + { + "kylechui/nvim-surround", + config = true, + }, } diff --git a/dot_config/nvim/lua/plugins/treesitter.lua b/dot_config/nvim/lua/plugins/treesitter.lua index 86bd94e..66e2122 100644 --- a/dot_config/nvim/lua/plugins/treesitter.lua +++ b/dot_config/nvim/lua/plugins/treesitter.lua @@ -29,6 +29,10 @@ return { dependencies = { "nvim-treesitter/nvim-treesitter-textobjects", "nvim-treesitter/playground", + { + "kana/vim-textobj-entire", + dependencies = { "kana/vim-textobj-user" }, + }, }, }, }