2022-10-13 17:31:11 +02:00
|
|
|
-- Completion
|
|
|
|
|
|
|
|
local completion = {}
|
2022-10-18 17:42:03 +02:00
|
|
|
local cmp = require('cmp')
|
|
|
|
local lspkind = require('lspkind')
|
2022-10-13 17:31:11 +02:00
|
|
|
|
|
|
|
vim.opt.shortmess:append 'c'
|
|
|
|
|
|
|
|
cmp.setup({
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require('luasnip').lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
|
|
|
|
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
|
|
|
|
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
|
|
|
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
|
|
|
['<C-s>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
|
|
|
['<C-y>'] = cmp.mapping.confirm({
|
|
|
|
behavior = cmp.ConfirmBehavior.Insert,
|
|
|
|
select = true
|
|
|
|
}),
|
|
|
|
['<C-e>'] = cmp.mapping({
|
|
|
|
i = cmp.mapping.abort(),
|
|
|
|
c = cmp.mapping.close(),
|
|
|
|
}),
|
|
|
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
|
|
|
}),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'nvim_lua' },
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'path' },
|
|
|
|
{ name = 'luasnip' },
|
|
|
|
{ name = 'nvim_lsp_signature_help' },
|
|
|
|
}, {
|
|
|
|
{ name = 'buffer', keyword_length = 5 },
|
|
|
|
}),
|
|
|
|
formatting = {
|
|
|
|
format = lspkind.cmp_format {
|
|
|
|
with_text = true,
|
|
|
|
menu = {
|
|
|
|
buffer = "[buf]",
|
|
|
|
nvim_lsp = "[LSP]",
|
|
|
|
nvim_lua = "[api]",
|
|
|
|
path = "[path]",
|
|
|
|
luasnip = "[snip]",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Use buffer source for `/` (basically search words in buffer)
|
|
|
|
cmp.setup.cmdline('/', {
|
|
|
|
sources = {
|
|
|
|
{ name = 'buffer' }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Use cmdline & path source for ':'
|
|
|
|
cmp.setup.cmdline(':', {
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'path' }
|
|
|
|
}, {
|
|
|
|
{ name = 'cmdline' }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
-- autopair
|
|
|
|
require('nvim-autopairs').setup {}
|
|
|
|
|
|
|
|
return completion
|