From 56951c0225147f054f9001400fe193d803817bff Mon Sep 17 00:00:00 2001 From: Christian Nieves Date: Mon, 26 Jun 2023 13:01:09 -0500 Subject: [PATCH] Separate configs --- vim/.vim/lua/config/lsp.lua | 341 ----------------------- vim/.vim/lua/config/neotree.lua | 6 - vim/.vim/lua/config/notify.lua | 5 - vim/.vim/lua/config/null-ls.lua | 23 -- vim/.vim/lua/config/nvim-treesitter.lua | 28 -- vim/.vim/lua/plugins/base.lua | 162 ----------- vim/.vim/lua/plugins/cmp.lua | 189 +++++++++++++ vim/.vim/lua/plugins/lsp.lua | 222 +++++++++++++++ vim/.vim/lua/plugins/lsp_lines.lua | 2 +- vim/.vim/lua/plugins/lualine.lua | 2 +- vim/.vim/lua/plugins/mason.lua | 10 + vim/.vim/lua/plugins/neotree.lua | 16 ++ vim/.vim/lua/plugins/nerdcommenter.lua | 16 ++ vim/.vim/lua/plugins/null-ls.lua | 29 ++ vim/.vim/lua/plugins/nvim-notify.lua | 10 + vim/.vim/lua/plugins/nvim-treesitter.lua | 27 ++ vim/.vim/lua/plugins/refactoring.lua | 61 ++++ 17 files changed, 582 insertions(+), 567 deletions(-) delete mode 100644 vim/.vim/lua/config/lsp.lua delete mode 100644 vim/.vim/lua/config/neotree.lua delete mode 100644 vim/.vim/lua/config/notify.lua delete mode 100644 vim/.vim/lua/config/null-ls.lua delete mode 100644 vim/.vim/lua/config/nvim-treesitter.lua create mode 100644 vim/.vim/lua/plugins/cmp.lua create mode 100644 vim/.vim/lua/plugins/lsp.lua create mode 100644 vim/.vim/lua/plugins/mason.lua create mode 100644 vim/.vim/lua/plugins/neotree.lua create mode 100644 vim/.vim/lua/plugins/nerdcommenter.lua create mode 100644 vim/.vim/lua/plugins/null-ls.lua create mode 100644 vim/.vim/lua/plugins/nvim-notify.lua create mode 100644 vim/.vim/lua/plugins/nvim-treesitter.lua create mode 100644 vim/.vim/lua/plugins/refactoring.lua diff --git a/vim/.vim/lua/config/lsp.lua b/vim/.vim/lua/config/lsp.lua deleted file mode 100644 index 3dc86bd..0000000 --- a/vim/.vim/lua/config/lsp.lua +++ /dev/null @@ -1,341 +0,0 @@ -local use_google = require("utils").use_google -local log = require("utils").log -local notify = require("notify") - -local lsp_status = require("lsp-status") -lsp_status.register_progress() - -require("mason").setup() -require("mason-lspconfig").setup({ - ensure_installed = { "lua_ls", "rust_analyzer" }, -}) - --- CiderLSP -vim.opt.completeopt = { "menu", "menuone", "noselect" } --- Don't show the dumb matching stuff -vim.opt.shortmess:append("c") - -vim.opt.spell = true -vim.opt.spelllang = { "en_us" } - -local lspconfig = require("lspconfig") -local configs = require("lspconfig.configs") - -vim.lsp.handlers["window/showMessage"] = function(_, result, ctx) - local client = vim.lsp.get_client_by_id(ctx.client_id) - local lvl = ({ - "ERROR", - "WARN", - "INFO", - "DEBUG", - })[result.type] - notify({ result.message }, lvl, { - title = "LSP | " .. client.name, - timeout = 1000, - keep = function() - return lvl == "ERROR" or lvl == "WARN" - end, - }) -end - -if use_google() then - configs.ciderlsp = { - default_config = { - cmd = { "/google/bin/releases/cider/ciderlsp/ciderlsp", "--tooltag=nvim-cmp", "--forward_sync_responses" }, - filetypes = { - "c", - "cpp", - "java", - "kotlin", - "objc", - "proto", - "textproto", - "go", - "python", - "bzl", - "typescript", - }, - root_dir = lspconfig.util.root_pattern("BUILD"), - -- root_dir = function(fname) - -- return string.match(fname, '(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$') - -- end; - settings = {}, - }, - } - - configs.analysislsp = { - default_config = { - cmd = { "/google/bin/users/lerm/glint-ale/analysis_lsp/server", "--lint_on_save=false", "--max_qps=10" }, - filetypes = { - "c", - "cpp", - "java", - "kotlin", - "objc", - "proto", - "textproto", - "go", - "python", - "bzl", - "markdown", - "typescript", - "javascript", - }, - root_dir = lspconfig.util.root_pattern("BUILD"), - -- root_dir = function(fname) - -- return string.match(fname, '(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$') - -- end; - settings = {}, - }, - } -end - -local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) -capabilities["codeLens"] = { dynamicRegistration = false } -capabilities.textDocument.publishDiagnostics = { - relatedInformation = true, - versionSupport = false, - tagSupport = { - valueSet = { - 1, - 2, - }, - }, - codeDescriptionSupport = true, - dataSupport = true, - layeredDiagnostics = true, -} - -capabilities = vim.tbl_extend("keep", capabilities or {}, lsp_status.capabilities) - -local runtime_path = vim.split(package.path, ";") -table.insert(runtime_path, "lua/?.lua") -table.insert(runtime_path, "lua/?/init.lua") - -local lspkind = require("lspkind") -lspkind.init() -local cmp = require("cmp") - -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 - -local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) -end - --- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline({ "/", "?" }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer", max_item_count = 5 }, - }, -}) - --- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "nvim_lsp_document_symbol" }, - }, { - { name = "path" }, - }, { - { name = "cmdline" }, - }), -}) - -local conditionalSources = { - { name = "nvim_lua" }, - { name = "nvim_lsp" }, - { name = "nvim_lsp_signature_help", priority = 5 }, - { name = "path" }, - { name = "treesitter" }, - { name = "crates" }, - { name = "vim_vsnip" }, - { name = "buffer", max_item_count = 5, keyword_length = 5, group_index = 2 }, - { - name = "spell", - option = { - keep_all_entries = false, - enable_in_context = function() - return true - end, - }, - }, -} - -local my_on_attach = function(client, bufnr) - require("lualine").refresh() - - vim.api.nvim_command("autocmd CursorHold lua vim.lsp.buf.document_highlight()") - vim.api.nvim_command("autocmd CursorHoldI lua vim.lsp.buf.document_highlight()") - vim.api.nvim_command("autocmd CursorMoved lua vim.lsp.util.buf_clear_references()") - - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - if vim.lsp.formatexpr then -- Neovim v0.6.0+ only. - vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr") - end - if vim.lsp.tagfunc then - vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc") - end - - lsp_status.on_attach(client) - - local opts = { noremap = true, silent = true } - vim.api.nvim_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) - vim.api.nvim_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) - vim.api.nvim_set_keymap("n", "L", "lua vim.lsp.buf.hover()", opts) - vim.api.nvim_set_keymap("n", "g0", "lua vim.lsp.buf.document_symbol()", opts) - vim.api.nvim_set_keymap("n", "gW", "lua vim.lsp.buf.workspace_symbol()", opts) - vim.api.nvim_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - vim.api.nvim_set_keymap("n", "gD", "tab split | lua vim.lsp.buf.definition()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) - vim.api.nvim_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_set_keymap("n", "gI", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_set_keymap("n", "gR", "lua vim.lsp.buf.references()", opts) -- diagnostics controls references - vim.api.nvim_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) - vim.api.nvim_set_keymap("i", "", "lua vim.lsp.buf.signature_help()", opts) - - vim.api.nvim_set_keymap("n", "gt", "lua vim.lsp.buf.type_definition()", opts) -end - -if use_google() then - require("cmp_nvim_ciderlsp").setup() - - -- 3. Set up CiderLSP - local cider_on_attach = function(client, bufnr) - my_on_attach(client, bufnr) - vim.b["is_cider_lsp_attached"] = "no" - end - - local cider_lsp_handlers = { - ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = true, - }), - } - - cider_lsp_handlers["$/syncResponse"] = function(_, result, ctx) - -- is_cider_lsp_attached has been setup via on_init, but hasn't received - -- sync response yet. - local first_fire = vim.b["is_cider_lsp_attached"] == "no" - vim.b["is_cider_lsp_attached"] = "yes" - if first_fire then - notify("CiderLSP attached", "info", { timeout = 500 }) - require("lualine").refresh() - end - end - - capabilities = require("cmp_nvim_ciderlsp").update_capabilities(capabilities) - capabilities.workspace.codeLens = { refreshSupport = true } - capabilities.workspace.diagnostics = { refreshSupport = true } - lspconfig.analysislsp.setup({ - capabilities = capabilities, - }) - table.insert(conditionalSources, { name = "analysislsp" }) - lspconfig.ciderlsp.setup({ - capabilities = capabilities, - on_attach = cider_on_attach, - handlers = cider_lsp_handlers, - }) - table.insert(conditionalSources, { name = "nvim_ciderlsp", priority = 9 }) -else - table.insert(conditionalSources, { name = "cmp_tabnine" }) -end - -cmp.setup({ - mapping = { - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.close(), - [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() - else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. - end - end, { "i", "s" }), - - [""] = cmp.mapping(function() - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn["vsnip#jumpable"](-1) == 1 then - feedkey("(vsnip-jump-prev)", "") - end - end, { "i", "s" }), - - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-jump-prev)", "") - else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. - end - end), - - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. - end - end), - }, - - sources = conditionalSources, - - sorting = { - comparators = { - cmp.config.compare.offset, - cmp.config.compare.exact, - cmp.config.compare.score, - require("cmp-under-comparator").under, - cmp.config.compare.kind, - cmp.config.compare.sort_text, - cmp.config.compare.length, - cmp.config.compare.order, - }, - }, - - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - - formatting = { - format = lspkind.cmp_format({ - with_text = true, - maxwidth = 40, -- half max width - menu = { - nvim_ciderlsp = "", - buffer = "", - crates = "📦", - nvim_lsp = "[CiderLSP]", - cmp_tabnine = "[TabNine]", - nvim_lua = "[API]", - path = "[path]", - tmux = "[TMUX]", - vim_vsnip = "[snip]", - }, - }), - }, - - experimental = { - ghost_text = true, - }, -}) - -vim.cmd( - [[ augroup CmpZsh au! autocmd Filetype zsh lua require'cmp'.setup.buffer { sources = { { name = "zsh" }, } } augroup END ]] -) diff --git a/vim/.vim/lua/config/neotree.lua b/vim/.vim/lua/config/neotree.lua deleted file mode 100644 index 71b5fc0..0000000 --- a/vim/.vim/lua/config/neotree.lua +++ /dev/null @@ -1,6 +0,0 @@ -local map = require("utils").map -require("neo-tree").setup({ - hijack_netrw_behavior = "open_current", -}) - -map("n", "", ":Neotree filesystem reveal toggle reveal_force_cwd") diff --git a/vim/.vim/lua/config/notify.lua b/vim/.vim/lua/config/notify.lua deleted file mode 100644 index e909aa8..0000000 --- a/vim/.vim/lua/config/notify.lua +++ /dev/null @@ -1,5 +0,0 @@ -local colors = require("catppuccin.palettes").get_palette() -require("notify").setup({ - background_colour = colors.base, -}) -vim.notify = require("notify") diff --git a/vim/.vim/lua/config/null-ls.lua b/vim/.vim/lua/config/null-ls.lua deleted file mode 100644 index 96f6413..0000000 --- a/vim/.vim/lua/config/null-ls.lua +++ /dev/null @@ -1,23 +0,0 @@ -local null_ls = require("null-ls") - -local sources = { - -- Catch insensitive, inconsiderate writing. - null_ls.builtins.diagnostics.alex, - - -- buildifier is a tool for formatting and linting bazel BUILD, WORKSPACE, and .bzl files. - null_ls.builtins.diagnostics.buildifier, - - -- Codespell finds common misspellings in text files. - -- null_ls.builtins.diagnostics.codespell, - -- null_ls.builtins.diagnostics.cspell, null_ls.builtins.code_actions.cspell, - - -- An English prose linter. Can fix some issues via code actions. - null_ls.builtins.code_actions.proselint, - - -- Reformats Java source code according to Google Java Style. - null_ls.builtins.formatting.google_java_format, -} - -null_ls.setup({ - sources = sources, -}) diff --git a/vim/.vim/lua/config/nvim-treesitter.lua b/vim/.vim/lua/config/nvim-treesitter.lua deleted file mode 100644 index b5a8b84..0000000 --- a/vim/.vim/lua/config/nvim-treesitter.lua +++ /dev/null @@ -1,28 +0,0 @@ -require("nvim-treesitter.configs").setup({ - -- A list of parser names, or "all" - -- ensure_installed = { "c", "lua", "vim", "java", "kotlin"}, - ensure_installed = "all", - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - highlight = { - -- `false` will disable the whole extension - enable = true, - indent = { - enable = true, - }, - -- disable = {"java"}, - -- - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - -- additional_vim_regex_highlighting = true, - -- additional_vim_regex_highlighting = { "java" }, - }, - -- rainbow = { - -- enable = true, - -- extended_mode = true, - -- } -}) diff --git a/vim/.vim/lua/plugins/base.lua b/vim/.vim/lua/plugins/base.lua index 223e6bd..2ca3a18 100644 --- a/vim/.vim/lua/plugins/base.lua +++ b/vim/.vim/lua/plugins/base.lua @@ -19,47 +19,6 @@ return { "tversteeg/registers.nvim", "jremmen/vim-ripgrep", "nvim-lua/plenary.nvim", - - { - "preservim/nerdcommenter", - init = function() - require("config.nerdcommenter") - end, - keys = { - { "c", ":call nerdcommenter#Comment(0, 'toggle')" }, - { "c", ":call nerdcommenter#Comment(0, 'toggle')", mode = "v" }, - - { "cS", ":call nerdcommenter#Comment(0, 'sexy')" }, - { "cS", ":call nerdcommenter#Comment(0, 'sexy')", mode = "v" }, - - { "c$", ":call nerdcommenter#Comment(0, 'ToEOL')" }, - { "c$", ":call nerdcommenter#Comment(0, 'ToEOL')", mode = "v" }, - }, - }, - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - config = function() - require("config.nvim-treesitter") - end, - lazy = false, - }, - - { - "nvim-neo-tree/neo-tree.nvim", - branch = "v2.x", - config = function() - require("config.neotree") - end, - dependencies = { - "nvim-lua/plenary.nvim", - "MunifTanjim/nui.nvim", - }, - keys = { - { "", ":Neotree filesystem reveal toggle reveal_force_cwd", desc = "Open NeoTree" }, - }, - }, - -- Undo tree { "mbbill/undotree", @@ -81,47 +40,6 @@ return { { "ray-x/go.nvim", ft = "go" }, { "ray-x/guihua.lua", ft = "go" }, - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - "nvim-lua/lsp-status.nvim", - "VonHeikemen/lsp-zero.nvim", - - -- Completion and linting - { - "hrsh7th/nvim-cmp", - event = "VimEnter", - dependencies = { - "onsails/lspkind.nvim", - "neovim/nvim-lspconfig", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "lukas-reineke/cmp-under-comparator", - "hrsh7th/cmp-cmdline", - "f3fora/cmp-spell", - "hrsh7th/cmp-nvim-lsp-document-symbol", - "hrsh7th/cmp-nvim-lsp-signature-help", - "hrsh7th/cmp-nvim-lua", - "hrsh7th/cmp-path", - "hrsh7th/cmp-vsnip", - "ray-x/cmp-treesitter", - }, - config = function() - require("config.lsp") - end, - }, - { - "tzachar/cmp-tabnine", - build = "./install.sh", - event = "InsertEnter", - cond = not use_google(), - }, - { - "jose-elias-alvarez/null-ls.nvim", - event = "VimEnter", - config = function() - require("config.null-ls") - end, - }, -- Rust { "saecki/crates.nvim", @@ -132,77 +50,8 @@ return { require("crates").setup() end, }, - { "simrat39/rust-tools.nvim", ft = "rust" }, - { - "ThePrimeagen/refactoring.nvim", - dependencies = { - { "nvim-lua/plenary.nvim" }, - { "nvim-treesitter/nvim-treesitter" }, - }, - config = function() - require("config.refactoring") - end, - keys = { - -- remap to open the Telescope refactoring menu in visual mode - { - "rr", - "lua require('telescope').extensions.refactoring.refactors()", - { noremap = true }, - }, - - -- Remaps for the refactoring operations currently offered by the plugin - { - "rx", - [[ lua require('refactoring').refactor('Extract Function')]], - mode = "v", - { noremap = true, silent = true, expr = false }, - }, - { - "rxf", - [[ lua require('refactoring').refactor('Extract Function To File')]], - mode = "v", - { noremap = true, silent = true, expr = false }, - }, - { - "rxv", - [[ lua require('refactoring').refactor('Extract Variable')]], - mode = "v", - { noremap = true, silent = true, expr = false }, - }, - { - "ri", - [[ lua require('refactoring').refactor('Inline Variable')]], - mode = "v", - { noremap = true, silent = true, expr = false }, - }, - - -- Extract block doesn't need visual mode - { - "rxb", - [[ lua require('refactoring').refactor('Extract Block')]], - { noremap = true, silent = true, expr = false }, - }, - { - "rxbf", - [[ lua require('refactoring').refactor('Extract Block To File')]], - { noremap = true, silent = true, expr = false }, - }, - - -- Inline variable can also pick up the identifier currently under the cursor without visual mode - { - "ri", - [[ lua require('refactoring').refactor('Inline Variable')]], - { noremap = true, silent = true, expr = false }, - }, - { - "rx", - [[ lua require('refactoring').refactor('Extract Variable')]], - { noremap = true, silent = true, expr = false }, - }, - }, - }, { "andymass/vim-matchup", event = "VimEnter" }, { "stevearc/aerial.nvim", @@ -223,7 +72,6 @@ return { end, lazy = false, }, - { "rmagatti/auto-session", config = function() @@ -233,19 +81,12 @@ return { }) end, }, - { "ipod825/libp.nvim", config = function() require("libp").setup() end, }, - { - "rcarriga/nvim-notify", - config = function() - require("config.notify") - end, - }, { "catppuccin/nvim", name = "catppuccin", @@ -261,13 +102,10 @@ return { require("config.oscyank") end, }, - - -- mine { "squk/java-syntax.vim", lazy = false, }, - { "folke/which-key.nvim", config = function() diff --git a/vim/.vim/lua/plugins/cmp.lua b/vim/.vim/lua/plugins/cmp.lua new file mode 100644 index 0000000..10768ec --- /dev/null +++ b/vim/.vim/lua/plugins/cmp.lua @@ -0,0 +1,189 @@ +local use_google = require("utils").use_google + +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 + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + +return { + { + "tzachar/cmp-tabnine", + build = "./install.sh", + event = "InsertEnter", + cond = not use_google(), + dependencies = { + "onsails/lspkind.nvim", + "hrsh7th/nvim-cmp", + }, + }, + { + "hrsh7th/nvim-cmp", + event = "VimEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "lukas-reineke/cmp-under-comparator", + "hrsh7th/cmp-cmdline", + "f3fora/cmp-spell", + "hrsh7th/cmp-nvim-lsp-document-symbol", + "hrsh7th/cmp-nvim-lsp-signature-help", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-path", + "hrsh7th/cmp-vsnip", + "ray-x/cmp-treesitter", + }, + config = function() + local cmp = require("cmp") + + local conditionalSources = cmp.config.sources({ + { name = "buffer", max_item_count = 5, keyword_length = 5, group_index = 2 }, + { name = "crates" }, + { name = "nvim_lsp" }, + { name = "nvim_lsp_signature_help", priority = 5 }, + { name = "nvim_lua" }, + { name = "path" }, + { name = "treesitter" }, + { name = "vim_vsnip" }, + { + name = "spell", + option = { + keep_all_entries = false, + enable_in_context = function() + return true + end, + }, + }, + }) + + if use_google() then + table.insert(conditionalSources, { name = "analysislsp" }) + table.insert(conditionalSources, { name = "nvim_ciderlsp", priority = 9 }) + else + table.insert(conditionalSources, { name = "cmp_tabnine" }) + end + + local lspkind = require("lspkind") + lspkind.init() + + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "nvim_lsp_document_symbol" }, + { name = "buffer", max_item_count = 5 }, + }), + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "nvim_lsp_document_symbol" }, + { name = "path" }, + { name = "cmdline" }, + }), + }) + + cmp.setup({ + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.close(), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-jump-prev)", "") + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end), + }, + + sources = conditionalSources, + + sorting = { + comparators = { + cmp.config.compare.offset, + cmp.config.compare.exact, + cmp.config.compare.score, + require("cmp-under-comparator").under, + cmp.config.compare.kind, + cmp.config.compare.sort_text, + cmp.config.compare.length, + cmp.config.compare.order, + }, + }, + + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + + formatting = { + format = lspkind.cmp_format({ + with_text = true, + maxwidth = 40, -- half max width + menu = { + nvim_ciderlsp = "", + buffer = "", + crates = "📦", + nvim_lsp = "[CiderLSP]", + cmp_tabnine = "[TabNine]", + nvim_lua = "[API]", + path = "[path]", + tmux = "[TMUX]", + vim_vsnip = "[snip]", + }, + }), + }, + + experimental = { + ghost_text = false, + }, + }) + + vim.cmd( + [[ augroup CmpZsh au! autocmd Filetype zsh lua require'cmp'.setup.buffer { sources = { { name = "zsh" }, } } augroup END ]] + ) + end, + }, +} diff --git a/vim/.vim/lua/plugins/lsp.lua b/vim/.vim/lua/plugins/lsp.lua new file mode 100644 index 0000000..6191308 --- /dev/null +++ b/vim/.vim/lua/plugins/lsp.lua @@ -0,0 +1,222 @@ +return { + { + "neovim/nvim-lspconfig", + dependencies = { + "nvim-lua/lsp-status.nvim", + "VonHeikemen/lsp-zero.nvim", + "rcarriga/nvim-notify", + }, + config = function() + local use_google = require("utils").use_google + local log = require("utils").log + local notify = require("notify") + + local lspconfig = require("lspconfig") + local configs = require("lspconfig.configs") + local lsp_status = require("lsp-status") + lsp_status.register_progress() + + -- CiderLSP + vim.opt.completeopt = { "menu", "menuone", "noselect" } + -- Don't show the dumb matching stuff + vim.opt.shortmess:append("c") + + vim.opt.spell = true + vim.opt.spelllang = { "en_us" } + vim.lsp.handlers["window/showMessage"] = function(_, result, ctx) + local client = vim.lsp.get_client_by_id(ctx.client_id) + local lvl = ({ + "ERROR", + "WARN", + "INFO", + "DEBUG", + })[result.type] + notify({ result.message }, lvl, { + title = "LSP | " .. client.name, + timeout = 1000, + keep = function() + return lvl == "ERROR" or lvl == "WARN" + end, + }) + end + + configs.ast_grep = { + default_config = { + cmd = { "sg", "lsp" }, + filetypes = { + "c", + "cpp", + "java", + "kotlin", + "objc", + "proto", + "textproto", + "go", + "python", + "bzl", + "typescript", + }, + single_file_support = true, + root_dir = lspconfig.util.root_pattern("BUILD", ".git", "sgconfig.yml"), + }, + } + + if use_google() then + configs.ciderlsp = { + default_config = { + cmd = { + "/google/bin/releases/cider/ciderlsp/ciderlsp", + "--tooltag=nvim-cmp", + "--forward_sync_responses", + }, + filetypes = { + "c", + "cpp", + "java", + "kotlin", + "objc", + "proto", + "textproto", + "go", + "python", + "bzl", + "typescript", + }, + root_dir = lspconfig.util.root_pattern("BUILD"), + -- root_dir = function(fname) + -- return string.match(fname, '(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$') + -- end; + settings = {}, + }, + } + + configs.analysislsp = { + default_config = { + cmd = { + "/google/bin/users/lerm/glint-ale/analysis_lsp/server", + "--lint_on_save=false", + "--max_qps=10", + }, + filetypes = { + "c", + "cpp", + "java", + "kotlin", + "objc", + "proto", + "textproto", + "go", + "python", + "bzl", + "markdown", + "typescript", + "javascript", + }, + root_dir = lspconfig.util.root_pattern("BUILD"), + -- root_dir = function(fname) + -- return string.match(fname, '(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$') + -- end; + settings = {}, + }, + } + end + + local capabilities = + require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + capabilities["codeLens"] = { dynamicRegistration = false } + capabilities.textDocument.publishDiagnostics = { + relatedInformation = true, + versionSupport = false, + tagSupport = { + valueSet = { + 1, + 2, + }, + }, + codeDescriptionSupport = true, + dataSupport = true, + layeredDiagnostics = true, + } + + capabilities = vim.tbl_extend("keep", capabilities or {}, lsp_status.capabilities) + + local runtime_path = vim.split(package.path, ";") + table.insert(runtime_path, "lua/?.lua") + table.insert(runtime_path, "lua/?/init.lua") + + local my_on_attach = function(client, bufnr) + require("lualine").refresh() + + vim.api.nvim_command("autocmd CursorHold lua vim.lsp.buf.document_highlight()") + vim.api.nvim_command("autocmd CursorHoldI lua vim.lsp.buf.document_highlight()") + vim.api.nvim_command("autocmd CursorMoved lua vim.lsp.util.buf_clear_references()") + + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") + if vim.lsp.formatexpr then -- Neovim v0.6.0+ only. + vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr") + end + if vim.lsp.tagfunc then + vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc") + end + + lsp_status.on_attach(client) + + local opts = { noremap = true, silent = true } + vim.api.nvim_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) + vim.api.nvim_set_keymap("n", "L", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_set_keymap("n", "g0", "lua vim.lsp.buf.document_symbol()", opts) + vim.api.nvim_set_keymap("n", "gW", "lua vim.lsp.buf.workspace_symbol()", opts) + vim.api.nvim_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_set_keymap("n", "gD", "tab split | lua vim.lsp.buf.definition()", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + vim.api.nvim_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_set_keymap("n", "gI", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_set_keymap("n", "gR", "lua vim.lsp.buf.references()", opts) -- diagnostics controls references + vim.api.nvim_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) + vim.api.nvim_set_keymap("i", "", "lua vim.lsp.buf.signature_help()", opts) + + vim.api.nvim_set_keymap("n", "gt", "lua vim.lsp.buf.type_definition()", opts) + end + + if use_google() then + require("cmp_nvim_ciderlsp").setup() + + -- 3. Set up CiderLSP + local cider_on_attach = function(client, bufnr) + my_on_attach(client, bufnr) + vim.b["is_cider_lsp_attached"] = "no" + end + + local cider_lsp_handlers = { + ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = true, + }), + } + + cider_lsp_handlers["$/syncResponse"] = function(_, result, ctx) + -- is_cider_lsp_attached has been setup via on_init, but hasn't received + -- sync response yet. + local first_fire = vim.b["is_cider_lsp_attached"] == "no" + vim.b["is_cider_lsp_attached"] = "yes" + if first_fire then + notify("CiderLSP attached", "info", { timeout = 500 }) + require("lualine").refresh() + end + end + + capabilities = require("cmp_nvim_ciderlsp").update_capabilities(capabilities) + capabilities.workspace.codeLens = { refreshSupport = true } + capabilities.workspace.diagnostics = { refreshSupport = true } + lspconfig.analysislsp.setup({ + capabilities = capabilities, + }) + lspconfig.ciderlsp.setup({ + capabilities = capabilities, + on_attach = cider_on_attach, + handlers = cider_lsp_handlers, + }) + end + end, + }, +} diff --git a/vim/.vim/lua/plugins/lsp_lines.lua b/vim/.vim/lua/plugins/lsp_lines.lua index 72f6253..52aaeb3 100644 --- a/vim/.vim/lua/plugins/lsp_lines.lua +++ b/vim/.vim/lua/plugins/lsp_lines.lua @@ -6,7 +6,7 @@ return { vim.diagnostic.config({ virtual_lines = { only_current_line = true }, - update_in_insert = true, + -- update_in_insert = true, virtual_text = false, }) diff --git a/vim/.vim/lua/plugins/lualine.lua b/vim/.vim/lua/plugins/lualine.lua index 5d7c0e9..f560a83 100644 --- a/vim/.vim/lua/plugins/lualine.lua +++ b/vim/.vim/lua/plugins/lualine.lua @@ -96,7 +96,7 @@ return { lualine_c = { { "diagnostics", - sources = { "nvim_lsp", "nvim_workspace_diagnostic" }, + sources = { "nvim_workspace_diagnostic" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, }, }, diff --git a/vim/.vim/lua/plugins/mason.lua b/vim/.vim/lua/plugins/mason.lua new file mode 100644 index 0000000..b07a9cf --- /dev/null +++ b/vim/.vim/lua/plugins/mason.lua @@ -0,0 +1,10 @@ +return { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + config = function() + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = { "lua_ls", "rust_analyzer" }, + }) + end, +} diff --git a/vim/.vim/lua/plugins/neotree.lua b/vim/.vim/lua/plugins/neotree.lua new file mode 100644 index 0000000..5b6989a --- /dev/null +++ b/vim/.vim/lua/plugins/neotree.lua @@ -0,0 +1,16 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + config = function() + require("neo-tree").setup({ + hijack_netrw_behavior = "open_current", + }) + end, + dependencies = { + "nvim-lua/plenary.nvim", + "MunifTanjim/nui.nvim", + }, + keys = { + { "", ":Neotree filesystem reveal toggle reveal_force_cwd", desc = "Open NeoTree" }, + }, +} diff --git a/vim/.vim/lua/plugins/nerdcommenter.lua b/vim/.vim/lua/plugins/nerdcommenter.lua new file mode 100644 index 0000000..ab922c9 --- /dev/null +++ b/vim/.vim/lua/plugins/nerdcommenter.lua @@ -0,0 +1,16 @@ +return { + "preservim/nerdcommenter", + init = function() + require("config.nerdcommenter") + end, + keys = { + { "c", ":call nerdcommenter#Comment(0, 'toggle')" }, + { "c", ":call nerdcommenter#Comment(0, 'toggle')", mode = "v" }, + + { "cS", ":call nerdcommenter#Comment(0, 'sexy')" }, + { "cS", ":call nerdcommenter#Comment(0, 'sexy')", mode = "v" }, + + { "c$", ":call nerdcommenter#Comment(0, 'ToEOL')" }, + { "c$", ":call nerdcommenter#Comment(0, 'ToEOL')", mode = "v" }, + }, +} diff --git a/vim/.vim/lua/plugins/null-ls.lua b/vim/.vim/lua/plugins/null-ls.lua new file mode 100644 index 0000000..5b4c165 --- /dev/null +++ b/vim/.vim/lua/plugins/null-ls.lua @@ -0,0 +1,29 @@ +return { + "jose-elias-alvarez/null-ls.nvim", + event = "VimEnter", + config = function() + local null_ls = require("null-ls") + + local sources = { + -- Catch insensitive, inconsiderate writing. + null_ls.builtins.diagnostics.alex, + + -- buildifier is a tool for formatting and linting bazel BUILD, WORKSPACE, and .bzl files. + null_ls.builtins.diagnostics.buildifier, + + -- Codespell finds common misspellings in text files. + -- null_ls.builtins.diagnostics.codespell, + -- null_ls.builtins.diagnostics.cspell, null_ls.builtins.code_actions.cspell, + + -- An English prose linter. Can fix some issues via code actions. + null_ls.builtins.code_actions.proselint, + + -- Reformats Java source code according to Google Java Style. + null_ls.builtins.formatting.google_java_format, + } + + null_ls.setup({ + sources = sources, + }) + end, +} diff --git a/vim/.vim/lua/plugins/nvim-notify.lua b/vim/.vim/lua/plugins/nvim-notify.lua new file mode 100644 index 0000000..8a23dc5 --- /dev/null +++ b/vim/.vim/lua/plugins/nvim-notify.lua @@ -0,0 +1,10 @@ +return { + "rcarriga/nvim-notify", + config = function() + local colors = require("catppuccin.palettes").get_palette() + require("notify").setup({ + background_colour = colors.base, + }) + vim.notify = require("notify") + end, +} diff --git a/vim/.vim/lua/plugins/nvim-treesitter.lua b/vim/.vim/lua/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..373297d --- /dev/null +++ b/vim/.vim/lua/plugins/nvim-treesitter.lua @@ -0,0 +1,27 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + -- A list of parser names, or "all" + -- ensure_installed = { "c", "lua", "vim", "java", "kotlin"}, + ensure_installed = "all", + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + highlight = { + -- `false` will disable the whole extension + enable = true, + indent = { + enable = true, + }, + }, + -- rainbow = { + -- enable = true, + -- extended_mode = true, + -- } + }) + end, + lazy = false, +} diff --git a/vim/.vim/lua/plugins/refactoring.lua b/vim/.vim/lua/plugins/refactoring.lua new file mode 100644 index 0000000..a2f7996 --- /dev/null +++ b/vim/.vim/lua/plugins/refactoring.lua @@ -0,0 +1,61 @@ +return { + { + "ThePrimeagen/refactoring.nvim", + dependencies = { + { "nvim-lua/plenary.nvim" }, + { "nvim-treesitter/nvim-treesitter" }, + }, + config = function() + require("config.refactoring") + end, + keys = { + -- remap to open the Telescope refactoring menu in visual mode + { + "rr", + "lua require('telescope').extensions.refactoring.refactors()", + }, + + -- Remaps for the refactoring operations currently offered by the plugin + { + "rx", + [[ lua require('refactoring').refactor('Extract Function')]], + mode = "v", + }, + { + "rxf", + [[ lua require('refactoring').refactor('Extract Function To File')]], + mode = "v", + }, + { + "rxv", + [[ lua require('refactoring').refactor('Extract Variable')]], + mode = "v", + }, + { + "ri", + [[ lua require('refactoring').refactor('Inline Variable')]], + mode = "v", + }, + + -- Extract block doesn't need visual mode + { + "rxb", + [[ lua require('refactoring').refactor('Extract Block')]], + }, + { + "rxbf", + [[ lua require('refactoring').refactor('Extract Block To File')]], + }, + + -- Inline variable can also pick up the identifier currently under the cursor without visual mode + { + "ri", + [[ lua require('refactoring').refactor('Inline Variable')]], + }, + { + "rx", + [[ lua require('refactoring').refactor('Extract Variable')]], + }, + }, + }, +}