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,40 +32,52 @@ 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
-- REQUIRED - you must specify a snippet engine opts.snippet = {
expand = function(args) -- REQUIRED - you must specify a snippet engine
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. expand = function(args)
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. -- Uncomment and use the snippet engine you prefer:
-- require('snippy').expand_snippet(args.body) -- For `snippy` users. -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
end, -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
}, vim.snippet.expand(args.body) -- For native Neovim snippets (Neovim v0.10+)
mapping = cmp.mapping.preset.insert({ end,
['<C-b>'] = cmp.mapping.scroll_docs(-4), }
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(), opts.mapping = cmp.mapping.preset.insert({
['<C-e>'] = cmp.mapping.abort(), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. ['<C-f>'] = cmp.mapping.scroll_docs(4),
}), ['<C-Space>'] = cmp.mapping.complete(),
sources = cmp.config.sources({ ['<C-e>'] = cmp.mapping.abort(),
{ name = 'nvim_lsp' }, ['<tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
{ 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' }
})
}) })
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 = {
{ "<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)",
},
},
}