2021-12-14 07:32:00 +01:00
|
|
|
--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)
|
|
|
|
|
2021-12-15 23:23:07 +01:00
|
|
|
local luasnip = require 'luasnip'
|
2021-12-14 07:32:00 +01:00
|
|
|
|
|
|
|
local lspconfig = require('lspconfig')
|
|
|
|
|
|
|
|
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
|
2022-04-21 21:51:01 +02:00
|
|
|
local servers = {'texlab', 'rust_analyzer', 'pyright'}
|
2021-12-14 07:32:00 +01:00
|
|
|
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'
|
2021-12-14 07:32:00 +01:00
|
|
|
|
|
|
|
-- nvim-cmp setup
|
|
|
|
local cmp = require 'cmp'
|
|
|
|
cmp.setup {
|
2021-12-15 23:23:07 +01:00
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require('luasnip').lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
2021-12-14 07:32:00 +01:00
|
|
|
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,
|
2022-02-07 20:47:57 +01:00
|
|
|
select = false,
|
2021-12-14 07:32:00 +01:00
|
|
|
},
|
2022-02-07 20:41:50 +01:00
|
|
|
['<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,
|
2021-12-14 07:32:00 +01:00
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = 'nvim_lsp' },
|
2022-04-21 21:51:01 +02:00
|
|
|
{ name = 'path' },
|
2021-12-15 23:23:07 +01:00
|
|
|
{ name = 'luasnip' },
|
2022-04-21 21:51:01 +02:00
|
|
|
{ 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' },
|
2021-12-14 07:32:00 +01:00
|
|
|
},
|
|
|
|
}
|
2022-04-21 21:51:01 +02:00
|
|
|
|
|
|
|
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-21 21:51:01 +02:00
|
|
|
}, {
|
2022-04-23 20:52:30 +02:00
|
|
|
-- { name = 'buffer' }
|
2022-04-21 21:51:01 +02:00
|
|
|
})
|
|
|
|
})
|