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

89 lines
2.1 KiB
Lua
Raw Normal View History

--configure nvim-cmp for use with lsp and luasnip.
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local luasnip = require 'luasnip'
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = {'texlab', 'rust_analyzer', 'pyright'}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end
-- 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' }
})
})