dotfiles/neovim/.config/nvim/lua/cmp-lsp.lua

74 lines
1.6 KiB
Lua
Raw Normal View History

--configure nvim-cmp for use with lsp and luasnip.
local luasnip = require 'luasnip'
-- Set completeopt to have a better completion experience
2022-01-19 07:17:58 +01:00
vim.o.completeopt='menu,menuone,preview,noinsert'
-- 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(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'dictionary' },
{ name = 'spell' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'emoji' },
{ name = 'latex_symbols' },
2022-04-21 22:04:30 +02:00
-- { name = 'digraphs' },
},
}
cmp.setup.cmdline(':', {
sources = {
{ name = 'cmdline' }
}
})
cmp.setup.cmdline('/', {
sources = cmp.config.sources({
2022-04-21 22:04:30 +02:00
{ name = 'nvim_lsp_document_symbol' },
{ name = 'treesitter' },
}, {
2022-04-23 20:52:30 +02:00
-- { name = 'buffer' }
})
})