commit 61af0cb095e349cd567d995e912341656f5d5d4b
parent 8b50c517ae86e3a133f069dad76bfa5dae775a61
Author: Chris Bracken <chris@bracken.jp>
Date: Sun, 25 Aug 2024 23:28:53 -0700
vim: add completion plugin
Diffstat:
3 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json
@@ -1,11 +1,16 @@
{
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
+ "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
+ "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
+ "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"dressing.nvim": { "branch": "master", "commit": "c5775a888adbc50652cb370073fcfec963eca93e" },
"fzf-lua": { "branch": "main", "commit": "9226c5a2291ef623ef157e0e1ffea034ffc8b8de" },
"gitsigns.nvim": { "branch": "main", "commit": "80214a857ce512cc64964abddc1d8eb5a3e28396" },
"gn": { "branch": "main", "commit": "225e90c5025bf74f41dbee60d9cde4512c846fe7" },
"lazy.nvim": { "branch": "main", "commit": "077102c5bfc578693f12377846d427f49bc50076" },
- "nvim-lspconfig": { "branch": "master", "commit": "911167921d49cd5c1c9b2436031d0da3945e787f" },
+ "lspkind.nvim": { "branch": "master", "commit": "cff4ae321a91ee3473a92ea1a8c637e3a9510aec" },
+ "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
+ "nvim-lspconfig": { "branch": "master", "commit": "8a3610d29df83d8632f8ee7c3afc779c12725531" },
"nvim-tree.lua": { "branch": "master", "commit": "d43ab67d0eb4317961c5e9d15fffe908519debe0" },
"nvim-web-devicons": { "branch": "master", "commit": "3722e3d1fb5fe1896a104eb489e8f8651260b520" },
"rust.vim": { "branch": "master", "commit": "889b9a7515db477f4cb6808bef1769e53493c578" },
diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua
@@ -27,6 +27,8 @@ vim.keymap.set('n', '<leader>fs', '<cmd>FzfLua lsp_document_symbols<CR>')
vim.keymap.set('n', '<leader>d', function()
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
end, { silent = true })
+vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
+vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
-- Key mapping to toggle absolute/relative numbering.
vim.keymap.set('n', '<leader>n', function()
diff --git a/.config/nvim/lua/plugins/languages.lua b/.config/nvim/lua/plugins/languages.lua
@@ -6,14 +6,75 @@ return {
vim.opt.rtp:append(plugin.dir .. "/misc/vim")
end
},
+ {
+ "hrsh7th/nvim-cmp",
+ opts = {},
+ event = "InsertEnter",
+ config = function()
+ local lspkind = require("lspkind")
+ local cmp = require("cmp")
+
+ -- Only override <C-n>, <C-p> if the cmp menu is visible.
+ local function custom_select(select_fn)
+ return cmp.mapping(function(fallback)
+ if cmp.visible() then
+ select_fn()
+ else
+ fallback()
+ end
+ end, { 'i', 'c' })
+ end
+
+ cmp.setup({
+ completion = {
+ autocomplete = false,
+ completeopt = "menu,menuone,preview,noselect",
+ },
+ window = {
+ completion = cmp.config.window.bordered(),
+ documentation = cmp.config.window.bordered(),
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-k>'] = cmp.mapping.select_prev_item(),
+ ['<C-j>'] = cmp.mapping.select_next_item(),
+ ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<C-e>'] = cmp.mapping.abort(),
+ ['<CR>'] = cmp.mapping.confirm({ select = true }),
+ ['<C-n>'] = custom_select(cmp.select_next_item),
+ ['<C-p>'] = custom_select(cmp.select_prev_item),
+ }),
+ sources = cmp.config.sources({
+ { name = "nvim_lsp" },
+ { name = "buffer" },
+ { name = "path" },
+ }),
+ formatting = {
+ format = lspkind.cmp_format({
+ maxwidth = 60,
+ elipsis_char = "...",
+ }),
+ },
+ })
+ end,
+ dependencies = {
+ "hrsh7th/cmp-buffer",
+ "hrsh7th/cmp-nvim-lsp",
+ "hrsh7th/cmp-path",
+ "onsails/lspkind.nvim",
+ },
+ },
{ "nathangrigg/vim-beancount" },
{
"neovim/nvim-lspconfig",
opts = {},
+ event = { "BufReadPre", "BufNewFile" },
config = function()
local lspconfig = require('lspconfig')
lspconfig.clangd.setup({})
lspconfig.dartls.setup({})
+ lspconfig.lua_ls.setup({})
lspconfig.rust_analyzer.setup({})
lspconfig.sourcekit.setup({
capabilities = {
@@ -24,7 +85,20 @@ return {
},
},
})
- end
+
+ vim.api.nvim_create_autocmd("LspAttach", {
+ group = vim.api.nvim_create_augroup("UserLspConfig", {}),
+ callback = function(ev)
+ local opts = { buffer = ev.buf, silent = true }
+ opts.desc = "Show documentation for what is under cursor"
+ vim.keymap.set("n", "<leader>cd", vim.lsp.buf.hover, opts)
+ opts.desc = "See available code actions"
+ vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts)
+ opts.desc = "Smart rename"
+ vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts)
+ end,
+ })
+ end,
},
{ "rhysd/vim-clang-format" },
{ "rust-lang/rust.vim" },