From 9c884fb8415367e5a0694a56089c120be36b2acf Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Fri, 30 Jun 2023 17:53:02 -0500 Subject: [PATCH] LSP finally working a decent amount --- TODO.md | 1 + lazy-lock.json | 23 ++- lua/keymaps.lua | 15 +- lua/options.lua | 15 +- lua/plugins/comments.lua | 10 ++ lua/plugins/indent-blankline.lua | 30 ++++ lua/plugins/lsp.lua | 206 +++++++++++++++++++++++ lua/plugins/lualine.lua | 42 +++-- lua/plugins/null-ls.lua | 95 ++++++----- lua/plugins/rust-tools.lua | 5 + lua/plugins_disabled/cmp.lua | 138 +++++++++++++++ lua/plugins_disabled/rust-tools.lua | 5 - lua/plugins_disabled/tabstops_sleuth.lua | 3 + lua/tools/scratch-files.lua | 1 + lua/util.lua | 12 -- 15 files changed, 489 insertions(+), 112 deletions(-) create mode 100644 TODO.md create mode 100644 lua/plugins/comments.lua create mode 100644 lua/plugins/indent-blankline.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/rust-tools.lua create mode 100644 lua/plugins_disabled/cmp.lua delete mode 100644 lua/plugins_disabled/rust-tools.lua create mode 100644 lua/plugins_disabled/tabstops_sleuth.lua diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..256e18a --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +FIgure out how to use genemichaels formatter in rust, rust formatting on null_ls is not working right now diff --git a/lazy-lock.json b/lazy-lock.json index eead57b..ded2599 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -2,33 +2,30 @@ "LuaSnip": { "branch": "master", "commit": "105b5f7f72c13e682a3aa5d29eac2408ae513b22" }, "auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" }, "ccc.nvim": { "branch": "main", "commit": "4a0ddaf787cc82796e84ab8a7f70d086f250aeb6" }, - "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, - "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, - "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, - "friendly-snippets": { "branch": "main", "commit": "1723ae01d83f3b3ac1530f1ae22b7b9d5da7749b" }, "glow.nvim": { "branch": "advanced_window", "commit": "f1157d4cb7e46e830c72004e7e1adb81a1f9b04c" }, - "lazy.nvim": { "branch": "main", "commit": "b7043f2983d7aead78ca902f3f2053907081859a" }, - "lsp-zero.nvim": { "branch": "v2.x", "commit": "52582fc91efb40ee347c20570ff7d32849ef4a89" }, - "lualine-lsp-progress": { "branch": "master", "commit": "21938e2a668982d1dbf3b33a43a96bc6d150a91d" }, + "indent-blankline.nvim": { "branch": "master", "commit": "7075d7861f7a6bbf0de0298c83f8a13195e6ec01" }, + "lazy.nvim": { "branch": "main", "commit": "4c8b625bc873ca76b76eee0c28c98f1f7148f17f" }, "lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "4f1c72767bec31397d59554f84096909b2887195" }, + "mason-null-ls.nvim": { "branch": "main", "commit": "73c68abdf65279e41526eb152876511a8ae84ea2" }, "mason.nvim": { "branch": "main", "commit": "b68d3be4b664671002221d43c82e74a0f1006b26" }, "material.nvim": { "branch": "main", "commit": "f3783f2a8e55904887d3ea7cae8d7ab57d7f3e8e" }, "neo-tree.nvim": { "branch": "v2.x", "commit": "20c2f2f5ba083bbb1e37b8bc3d590621434f31e9" }, + "neodev.nvim": { "branch": "main", "commit": "a2b1d8fb9fa4daa35d3fd9123bccccccbd4a3520" }, + "nerdcommenter": { "branch": "master", "commit": "ab2ae4d502a26bc591db78a8548823ddd04bbc9c" }, "nui.nvim": { "branch": "main", "commit": "d146966a423e60699b084eeb28489fe3b6427599" }, "null-ls.nvim": { "branch": "main", "commit": "aac27a1fa550de3d0b2c651168167cc0d5366a9a" }, - "nvim-autopairs": { "branch": "master", "commit": "e8f7dd7a72de3e7b6626c050a802000e69d53ff0" }, - "nvim-cmp": { "branch": "main", "commit": "e1f1b40790a8cb7e64091fb12cc5ffe350363aa0" }, - "nvim-lspconfig": { "branch": "master", "commit": "5da57456597ac2f25f20d6ecfae7b7c9cbd01fc6" }, - "nvim-treesitter": { "branch": "master", "commit": "8d2eb35c5b72a2e2fdb713998bdc906d8f028114" }, + "nvim-cmp": { "branch": "main", "commit": "2743dd989e9b932e1b4813a4927d7b84272a14e2" }, + "nvim-lspconfig": { "branch": "master", "commit": "0011c435282f043a018e23393cae06ed926c3f4a" }, + "nvim-treesitter": { "branch": "master", "commit": "0522bbe90d6f9bb7080621fe70f8ab565e072b98" }, "nvim-web-devicons": { "branch": "master", "commit": "9ab9b0b894b2388a9dbcdee5f00ce72e25d85bf9" }, "openingh.nvim": { "branch": "main", "commit": "2719e5759ecf4b9a2d492fbf52d03d2e6fc6126a" }, "playground": { "branch": "master", "commit": "2b81a018a49f8e476341dfcb228b7b808baba68b" }, - "plenary.nvim": { "branch": "master", "commit": "36aaceb6e93addd20b1b18f94d86aecc552f30c4" }, + "plenary.nvim": { "branch": "master", "commit": "102c02903c74b93c705406bf362049383abc87c8" }, "rest.nvim": { "branch": "main", "commit": "aea7c64bdff1073beed9bd7fddb60cce7796d7ff" }, + "rust-tools.nvim": { "branch": "master", "commit": "71d2cf67b5ed120a0e31b2c8adb210dd2834242f" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "9bc8237565ded606e6c366a71c64c0af25cd7a50" }, "telescope.nvim": { "branch": "master", "commit": "c1a2af0af69e80e14e6b226d3957a064cd080805" }, "undotree": { "branch": "master", "commit": "485f01efde4e22cb1ce547b9e8c9238f36566f21" } diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 4728305..9380149 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -1,6 +1,7 @@ -- Remap space as leader key vim.keymap.set("", "", "", { silent = true }) vim.g.mapleader = " " +vim.g.maplocalleader = " " -- Modes -- normal_mode = "n", @@ -32,15 +33,11 @@ require('util').keymaps({ [""] = { "j", desc = "Move window below current" }, [""] = { "k", desc = "Move window above current" }, [""] = { "l", desc = "Move window right current" }, - -- reformat outside of LSP attachment - ["lf"] = { function() vim.lsp.buf.format() end, desc = "Reformat file" } - - - -- [",j"] = { name = " Jest Tests" }, - -- [",jr"] = { function() require("jester").run() end, desc = "Run test under cursor" }, - -- [",jf"] = { function() require("jester").run_file() end, desc = "Run tests for file" }, - -- [",jl"] = { function() require("jester").run_last() end, desc = "Run last ran test" }, - -- ["lz"] = { ":LspRestart", desc = "Restart LSP Server" }, + -- reformat LSP + ["lf"] = { function() vim.lsp.buf.format() end, desc = "Reformat file" }, + ["ld"] = { function() vim.diagnostic.open_float() end, desc = "Show diagnostic message"}, + ["ll"] = { function() vim.diagnostic.setloclist() end, desc = "Show diagnostic list"}, + ["lz"] = { ":LspRestart", desc = "Restart LSP Server" }, }, v = { ["y"] = { '"*y', desc = "Copy to system clipboard" }, diff --git a/lua/options.lua b/lua/options.lua index 1fd2b5d..9510ec1 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -2,7 +2,7 @@ -- vim.opt.clipboard = "unnamedplus" -- allow use of mouse -vim.opt.mouse = 'a' +vim.opt.mouse = "a" -- line numbering, relative vim.opt.number = true @@ -22,15 +22,15 @@ vim.opt.breakindent = true vim.opt.smartindent = true -- set tab length -vim.opt.tabstop = 2; -vim.opt.softtabstop = 2; -vim.opt.shiftwidth = 2; +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 vim.opt.expandtab = true -- Dont use swap files, use undotree vim.opt.swapfile = false vim.opt.backup = false -vim.opt.undodir = os.getenv('HOME') .. '/.vim/undodir' +vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" vim.opt.undofile = true -- Search settings @@ -41,3 +41,8 @@ vim.opt.incsearch = true vim.opt.splitbelow = true vim.opt.splitright = true +-- Set completeopt to have a better completion experience +vim.o.completeopt = "menuone,noselect" +vim.diagnostic.config{ + float={border="single"} +} diff --git a/lua/plugins/comments.lua b/lua/plugins/comments.lua new file mode 100644 index 0000000..7a1528a --- /dev/null +++ b/lua/plugins/comments.lua @@ -0,0 +1,10 @@ +vim.g.NERDCreateDefaultMappings = 0 +vim.cmd('filetype plugin on') + +return { + "preservim/nerdcommenter", + keys = { + { "/", ':call nerdcommenter#Comment(0, "toggle")', desc = "Toggle comments on selection" }, + { "/", ':call nerdcommenter#Comment(0, "toggle")', desc = "Toggle comments on selection", mode = "v" }, + }, +} diff --git a/lua/plugins/indent-blankline.lua b/lua/plugins/indent-blankline.lua new file mode 100644 index 0000000..ad29568 --- /dev/null +++ b/lua/plugins/indent-blankline.lua @@ -0,0 +1,30 @@ +vim.cmd([[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]]) +vim.cmd([[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]]) +vim.cmd([[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]]) +vim.cmd([[highlight IndentBlanklineIndent4 guifg=#61AFEF gui=nocombine]]) +vim.cmd([[highlight IndentBlanklineIndent5 guifg=#C678DD gui=nocombine]]) + +vim.opt.list = true +-- vim.opt.listchars:append "space:⋅" +vim.opt.listchars:append("eol:↴") + +return { + -- Add indentation guides even on blank lines + "lukas-reineke/indent-blankline.nvim", + -- Enable `lukas-reineke/indent-blankline.nvim` + -- See `:help indent_blankline.txt` + opts = { + -- space_char_blankline = " ", + -- char = '┊', + -- show_trailing_blankline_indent = false, + -- show_current_context = false, + show_current_context_start = true, + char_highlight_list = { + "IndentBlanklineIndent1", + "IndentBlanklineIndent2", + "IndentBlanklineIndent3", + "IndentBlanklineIndent4", + "IndentBlanklineIndent5", + }, + }, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..757c6cf --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,206 @@ +local servers = { + rust_analyzer = { + -- rust + -- to enable rust-analyzer settings visit: + -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + }, + checkOnSave = { + allFeatures = true, + command = "clippy", + }, + }, + }, + tsserver = { + -- typescript/javascript + }, + pyright = { + -- python + }, + lua_ls = { + -- lua + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, + bashls = { + -- bash + }, + cssls = { + -- css + }, + cssmodules_ls = { + -- css modules + }, + dockerls = { + -- docker + }, + docker_compose_language_service = { + -- docker compose + }, + jsonls = { + -- json + }, + marksman = { + -- markdown + }, + taplo = { + -- toml + }, + yamlls = { + -- yaml + }, + lemminx = { + -- xml + }, + rnix = { + -- Nix + }, + ansiblels = { + -- ansible + }, +} + +-- LSP config +-- Took lots of inspiration from this kickstart lua file: https://github.com/hjr3/dotfiles/blob/main/.config/nvim/init.lua + +return { + { + -- Autocompletion + "hrsh7th/nvim-cmp", + dependencies = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" }, + }, + { + "williamboman/mason.nvim", + cmd = { + "Mason", + "MasonUpdate", + "MasonInstall", + "MasonInstallAll", + "MasonUninstall", + "MasonUninstallAll", + "MasonLog", + }, + build = ":MasonUpdate", + opts = {}, + }, + { + "williamboman/mason-lspconfig.nvim", + }, + { "folke/neodev.nvim", opts = {} }, + { + "neovim/nvim-lspconfig", + after = { "nvim-telescope/telescope.nvim" }, + config = function() + local config = require("lspconfig") + local util = require("lspconfig/util") + local mason_lspconfig = require("mason-lspconfig") + local cmp = require("cmp") + local luasnip = require("luasnip") + + -- LSP + -- This function gets run when an LSP connects to a particular buffer. + local on_attach = function(client, bufnr) + local nmap = function(keys, func, desc) + if desc then + desc = "LSP: " .. desc + end + + vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc }) + end + + nmap("lr", vim.lsp.buf.rename, "[R]ename") + nmap("la", vim.lsp.buf.code_action, "Code [A]ction") + + nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition") + nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + nmap("gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation") + nmap("D", vim.lsp.buf.type_definition, "Type [D]efinition") + + -- See `:help K` for why this keymap + nmap("K", vim.lsp.buf.hover, "Hover Documentation") + nmap("", vim.lsp.buf.signature_help, "Signature Documentation") + + -- Lesser used LSP functionality + nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + + -- disable tsserver so it does not conflict with prettier + if client.name == "tsserver" then + client.server_capabilities.document_formatting = false + end + end + + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) + + -- Install servers used + mason_lspconfig.setup({ + ensure_installed = vim.tbl_keys(servers), + }) + + local flags = { + allow_incremental_sync = true, + debounce_text_changes = 200, + } + + mason_lspconfig.setup_handlers({ + function(server_name) + require("lspconfig")[server_name].setup({ + flags = flags, + capabilities = capabilities, + on_attach = on_attach, + settings = servers[server_name], + }) + end, + }) + + -- Completion + luasnip.config.setup({}) + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete({}), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + 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 = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, + }) + end, + }, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index 551a1ea..f4a6d6c 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -1,25 +1,21 @@ -local test = function () - return "test 123" -end - return { - "nvim-lualine/lualine.nvim", - dependencies = { - "RingOfStorms/lualine-lsp-progress", - }, - opts = { - options = { - theme = "codedark", - section_separators = { left = '', right = '' }, - component_separators = '|', - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {'filename', "lsp_progress", test}, - lualine_x = {'encoding', 'filetype', 'filesize'}, - lualine_y = {'searchcount', 'selectioncount'}, - lualine_z = {'location'}, - }, - }, + "nvim-lualine/lualine.nvim", + --dependencies = { + -- "RingOfStorms/lualine-lsp-progress", + --}, + opts = { + options = { + theme = "codedark", + section_separators = { left = "", right = "" }, + component_separators = "|", + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "filetype", "filesize" }, + lualine_y = { "searchcount", "selectioncount" }, + lualine_z = { "location" }, + }, + }, } diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua index c8a8029..86155e0 100644 --- a/lua/plugins/null-ls.lua +++ b/lua/plugins/null-ls.lua @@ -1,55 +1,60 @@ -- npm install -g cspell@latest -local output = vim.fn.system { - "which", - "cspell", -} +local output = vim.fn.system({ + "which", + "cspell", +}) if output == nil or output == "" then - -- if v:shell_error != 0 then - vim.fn.system { - "npm", - "install", - "-g", - "cspell@latest", - } + -- if v:shell_error != 0 then + vim.fn.system({ + "npm", + "install", + "-g", + "cspell@latest", + }) end return { - "jose-elias-alvarez/null-ls.nvim", - dependencies = "williamboman/mason.nvim", - opts = function(_, config) - require('util').ensure_installed_mason({ - "stylua", - "prettier", - "rustfmt", - }) + { + "jose-elias-alvarez/null-ls.nvim", + after = { "williamboman/mason.nvim" }, + opts = function(_, config) - -- config variable is the default definitions table for the setup function call - local null_ls = require "null-ls" + -- config variable is the default definitions table for the setup function call + local null_ls = require("null-ls") - -- Check supported formatters and linters - -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting - -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics - config.sources = { - -- Set a formatter - null_ls.builtins.formatting.prettier, - null_ls.builtins.formatting.stylua, - null_ls.builtins.formatting.rustfmt, - -- null_ls.builtins.formatting.python, - -- null_ls.builtins.code_actions.proselint, -- TODO looks interesting - null_ls.builtins.code_actions.cspell.with { - config = { - find_json = function() return vim.fn.findfile("cspell.json", vim.fn.environ().HOME .. "/.config/nvim/lua/user/;") end, - }, - }, - null_ls.builtins.diagnostics.cspell.with { - extra_args = { "--config", "~/.config/nvim/lua/user/cspell.json" }, - }, + -- Check supported formatters and linters + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics + config.sources = { + -- Set a formatter + null_ls.builtins.formatting.prettier, -- typescript/javascript + null_ls.builtins.formatting.stylua, + null_ls.builtins.formatting.rustfmt, + null_ls.builtins.formatting.black, -- python + -- null_ls.builtins.code_actions.proselint, -- TODO looks interesting + null_ls.builtins.code_actions.cspell.with({ + config = { + find_json = function() + return vim.fn.findfile("cspell.json", vim.fn.environ().HOME .. "/.config/nvim/lua/user/;") + end, + }, + }), + null_ls.builtins.diagnostics.cspell.with({ + extra_args = { "--config", "~/.config/nvim/lua/user/cspell.json" }, + }), + } + + config.update_in_insert = true + config.debug = true + + return config + end, + }, + { + "jay-babu/mason-null-ls.nvim", + opts = { + ensure_installed = { "rustfmt", "stylelua", "prettier", "black" } } - - config.update_in_insert = true - config.debug = true - - return config - end, + } } diff --git a/lua/plugins/rust-tools.lua b/lua/plugins/rust-tools.lua new file mode 100644 index 0000000..2b5d3a1 --- /dev/null +++ b/lua/plugins/rust-tools.lua @@ -0,0 +1,5 @@ +return { + "simrat39/rust-tools.nvim", + event = "BufEnter *.rs", + after = { "mason-lspconfig.nvim", "inlay-hints." }, +} diff --git a/lua/plugins_disabled/cmp.lua b/lua/plugins_disabled/cmp.lua new file mode 100644 index 0000000..43f29e6 --- /dev/null +++ b/lua/plugins_disabled/cmp.lua @@ -0,0 +1,138 @@ +return { + { + "L3MON4D3/LuaSnip", + dependencies = { "rafamadriz/friendly-snippets" }, + opts = { + history = true, + updateevents = "TextChanged,TextChangedI", + opts = { store_selection_keys = "" }, + }, + }, + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + -- Snips + { + "windwp/nvim-autopairs", + opts = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + local cmp_autopairs = require("nvim-autopairs.completion.cmp") + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, + { "saadparwaiz1/cmp_luasnip" }, + -- { "hrsh7th/cmp-nvim-lua" }, + -- { "hrsh7th/cmp-nvim-lsp" }, + -- { "hrsh7th/cmp-vsnip" }, + { "hrsh7th/cmp-buffer" }, + { "hrsh7th/cmp-path" }, + -- { "hrsh7th/cmp-cmdline" }, + { "hrsh7th/cmp-nvim-lsp" }, + }, + config = function() + + vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" }) + vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" }) + + + local cmp = require("cmp") + local snip_status_ok, luasnip = pcall(require, "luasnip") + local lspkind_status_ok, lspkind = pcall(require, "lspkind") + if not snip_status_ok then + return + end + + local border_opts = { + border = "single", + winhighlight = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None", + } + + cmp.setup({ + enabled = function() + local dap_prompt = vim.tbl_contains( + { "dap-repl", "dapui_watches", "dapui_hover" }, + vim.api.nvim_get_option_value("filetype", { buf = 0 }) + ) + if vim.api.nvim_get_option_value("buftype", { buf = 0 }) == "prompt" and not dap_prompt then + return false + end + return vim.g.cmp_enabled + end, + window = { + completion = cmp.config.window.bordered(border_opts), + documentation = cmp.config.window.bordered(border_opts), + }, + preselect = cmp.PreselectMode.None, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = lspkind_status_ok and lspkind.cmp_format(utils.plugin_opts("lspkind.nvim")) or nil, + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + duplicates = { + nvim_lsp = 1, + luasnip = 1, + cmp_tabnine = 1, + buffer = 1, + path = 1, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + mapping = { + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, + [""] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close() }), + [""] = cmp.mapping.confirm({ select = false }), + [""] = 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", priority = 1000 }, + { name = "luasnip", priority = 750 }, + { name = "buffer", priority = 500 }, + { name = "path", priority = 250 }, + }), + }) + end, + }, + { + "folke/neodev.nvim", + opts = {} + } +} diff --git a/lua/plugins_disabled/rust-tools.lua b/lua/plugins_disabled/rust-tools.lua deleted file mode 100644 index 15cf3a9..0000000 --- a/lua/plugins_disabled/rust-tools.lua +++ /dev/null @@ -1,5 +0,0 @@ -return { - "simrat39/rust-tools.nvim", - event = "BufEnter *.rs", - after = { "mason-lspconfig.nvim", "inlay-hints." }, -} diff --git a/lua/plugins_disabled/tabstops_sleuth.lua b/lua/plugins_disabled/tabstops_sleuth.lua new file mode 100644 index 0000000..0884e6b --- /dev/null +++ b/lua/plugins_disabled/tabstops_sleuth.lua @@ -0,0 +1,3 @@ +return { + 'tpope/vim-sleuth', +} diff --git a/lua/tools/scratch-files.lua b/lua/tools/scratch-files.lua index 1cf1cb6..5ec9fab 100644 --- a/lua/tools/scratch-files.lua +++ b/lua/tools/scratch-files.lua @@ -27,6 +27,7 @@ require('util').keymaps({ ["s"] = { "", desc = "Scratch File" }, ["ss"] = { function() scratch ".txt" end, desc = "New text scratch file" }, ["sn"] = { function() scratch ".json" end, desc = "New json scratch file" }, + ["sm"] = { function() scratch ".md" end, desc = "New markdown scratch file" }, ["sq"] = { function() scratch ".sql" end, desc = "New sql scratch file" }, ["st"] = { function() scratch ".ts" end, desc = "New ts scratch file" }, ["sb"] = { function() scratch ".sh" end, desc = "New shell scratch file" }, diff --git a/lua/util.lua b/lua/util.lua index f11ca75..94239a9 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -34,17 +34,5 @@ function M.spread(template) end end -function M.ensure_installed_mason(items) - local registry = require 'mason-registry' - for _, item in ipairs(items) do - if not registry.is_installed(item) then - if registry.has_package(item) then - registry.get_package(item).install() - end - end - end - registry.refresh() -end - return M