Update .config/nvim/lua/plugins/lsp.lua

Add .config/nvim/lua/plugins/which-key.lua
This commit is contained in:
Anthony Rodriguez 2024-08-12 16:07:43 +02:00
parent cf348c2fb3
commit 73261dcdc3
2 changed files with 70 additions and 32 deletions

View file

@ -12,7 +12,15 @@ return {
config = function() config = function()
require("lspconfig").gopls.setup {} require("lspconfig").gopls.setup {}
require("lspconfig").lua_ls.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" },
{ "<leader>r", vim.lsp.buf.rename, desc = "Rename Symbol" }
},
}, },
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
@ -24,29 +32,33 @@ return {
"hrsh7th/cmp-cmdline", "hrsh7th/cmp-cmdline",
"hrsh7th/cmp-vsnip", "hrsh7th/cmp-vsnip",
"hrsh7th/vim-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" local cmp = require "cmp"
cmp.setup({
snippet = { -- Setup cmp with options
opts.snippet = {
-- REQUIRED - you must specify a snippet engine -- REQUIRED - you must specify a snippet engine
expand = function(args) expand = function(args)
-- Uncomment and use the snippet engine you prefer:
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users. -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) vim.snippet.expand(args.body) -- For native Neovim snippets (Neovim v0.10+)
end, end,
}, }
mapping = cmp.mapping.preset.insert({
opts.mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(), ['<C-e>'] = cmp.mapping.abort(),
['<tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. ['<tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}), })
sources = cmp.config.sources({
opts.sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users. { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users. -- { name = 'luasnip' }, -- For luasnip users.
@ -56,8 +68,16 @@ return {
{ name = 'buffer' }, { name = 'buffer' },
{ name = 'nvim_lsp_signature_help' } { name = 'nvim_lsp_signature_help' }
}) })
})
end return opts
end,
keys = {
{ "<C-b>", function() require('cmp').mapping.scroll_docs(-4) end, mode = "i", desc = "Scroll docs up" },
{ "<C-f>", function() require('cmp').mapping.scroll_docs(4) end, mode = "i", desc = "Scroll docs down" },
{ "<C-Space>", function() require('cmp').mapping.complete() end, mode = "i", desc = "Trigger completion" },
{ "<C-e>", function() require('cmp').mapping.abort() end, mode = "i", desc = "Abort completion" },
{ "<Tab>", function() require('cmp').mapping.confirm({ select = true }) end, mode = "i", desc = "Confirm selection" },
},
}, },
{ {
'numToStr/Comment.nvim', 'numToStr/Comment.nvim',

View file

@ -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 = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Local Keymaps (which-key)",
},
},
}