fixed lsp keybindings.

They now work on more than just the first buffer you open of a given
filetype.
This commit is contained in:
Gabe Venberg 2021-12-15 16:23:07 -06:00
parent 83aea3c147
commit 09042586ec
4 changed files with 37 additions and 22 deletions

View file

@ -5,6 +5,7 @@
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local luasnip = require 'luasnip'
local lspconfig = require('lspconfig')
@ -23,6 +24,11 @@ vim.o.completeopt = 'menuone,noselect'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
@ -37,6 +43,8 @@ cmp.setup {
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
@ -44,6 +52,8 @@ cmp.setup {
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
@ -51,5 +61,7 @@ cmp.setup {
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' }
},
}