From 73261dcdc36fd4b2d3fb83158f54c2473368a1e9 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Mon, 12 Aug 2024 16:07:43 +0200 Subject: [PATCH] Update .config/nvim/lua/plugins/lsp.lua Add .config/nvim/lua/plugins/which-key.lua --- dot_config/nvim/lua/plugins/lsp.lua | 84 ++++++++++++++--------- dot_config/nvim/lua/plugins/which-key.lua | 18 +++++ 2 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 dot_config/nvim/lua/plugins/which-key.lua diff --git a/dot_config/nvim/lua/plugins/lsp.lua b/dot_config/nvim/lua/plugins/lsp.lua index 2efd030..971340a 100644 --- a/dot_config/nvim/lua/plugins/lsp.lua +++ b/dot_config/nvim/lua/plugins/lsp.lua @@ -12,7 +12,15 @@ return { config = function() require("lspconfig").gopls.setup {} require("lspconfig").lua_ls.setup {} - end + end, + keys = { + -- Keymap for LSP actions + { "gd", vim.lsp.buf.definition, desc = "Go to Definition" }, + { "gr", vim.lsp.buf.references, desc = "Go to References" }, + { "gi", vim.lsp.buf.implementation, desc = "Go to Implementation" }, + { "K", vim.lsp.buf.hover, desc = "Hover Documentation" }, + { "r", vim.lsp.buf.rename, desc = "Rename Symbol" } + }, }, { "hrsh7th/nvim-cmp", @@ -24,40 +32,52 @@ return { "hrsh7th/cmp-cmdline", "hrsh7th/cmp-vsnip", "hrsh7th/vim-vsnip", - "hrsh7th/cmp-nvim-lsp-signature-help" + "hrsh7th/cmp-nvim-lsp-signature-help", }, - config = function() + opts = function(_, opts) local cmp = require "cmp" - cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'vsnip' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = 'buffer' }, - { name = 'nvim_lsp_signature_help' } - }) + + -- Setup cmp with options + opts.snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + -- Uncomment and use the snippet engine you prefer: + -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + vim.snippet.expand(args.body) -- For native Neovim snippets (Neovim v0.10+) + end, + } + + opts.mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }) - end + + opts.sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + { name = 'nvim_lsp_signature_help' } + }) + + return opts + end, + keys = { + { "", function() require('cmp').mapping.scroll_docs(-4) end, mode = "i", desc = "Scroll docs up" }, + { "", function() require('cmp').mapping.scroll_docs(4) end, mode = "i", desc = "Scroll docs down" }, + { "", function() require('cmp').mapping.complete() end, mode = "i", desc = "Trigger completion" }, + { "", function() require('cmp').mapping.abort() end, mode = "i", desc = "Abort completion" }, + { "", function() require('cmp').mapping.confirm({ select = true }) end, mode = "i", desc = "Confirm selection" }, + }, }, { 'numToStr/Comment.nvim', diff --git a/dot_config/nvim/lua/plugins/which-key.lua b/dot_config/nvim/lua/plugins/which-key.lua new file mode 100644 index 0000000..8b85fc2 --- /dev/null +++ b/dot_config/nvim/lua/plugins/which-key.lua @@ -0,0 +1,18 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }, + keys = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Local Keymaps (which-key)", + }, + }, +}