2023-09-05 07:24:34 +01:00
local cmp_status_ok , cmp = pcall ( require , " cmp " )
if not cmp_status_ok then
return
end
local snip_status_ok , luasnip = pcall ( require , " luasnip " )
if not snip_status_ok then
return
end
vim.opt . shortmess : append " c "
cmp.setup {
snippet = {
expand = function ( args )
luasnip.lsp_expand ( args.body )
end ,
} ,
mapping = cmp.mapping . preset.insert {
[ " <C-e> " ] = cmp.mapping . close ( ) ,
2024-02-26 15:40:12 +00:00
[ " <C-h> " ] = cmp.mapping ( function ( )
if luasnip.locally_jumpable ( - 1 ) then
luasnip.jump ( - 1 )
end
end , { " i " , " s " } ) ,
[ " <C-l> " ] = cmp.mapping ( function ( )
if luasnip.expand_or_locally_jumpable ( ) then
luasnip.expand_or_jump ( )
end
end , { " i " , " s " } ) ,
2023-09-05 07:24:34 +01:00
[ " <C-y> " ] = cmp.mapping . confirm { select = true } ,
[ " <tab> " ] = cmp.config . disable ,
} ,
sources = {
{ name = " nvim_lsp " } ,
{ name = " nvim_lua " } ,
{ name = " luasnip " } ,
} ,
sorting = {
comparators = {
cmp.config . compare.offset ,
cmp.config . compare.exact ,
cmp.config . compare.score ,
cmp.config . compare.kind ,
cmp.config . compare.sort_text ,
cmp.config . compare.length ,
cmp.config . compare.order ,
} ,
} ,
formatting = {
format = require ( " lspkind " ) . cmp_format {
with_text = true ,
menu = {
buffer = " [buf] " ,
cmp_tabnine = " [tn] " ,
luasnip = " [snip] " ,
nvim_lsp = " [lsp] " ,
nvim_lua = " [lua] " ,
path = " [path] " ,
} ,
} ,
} ,
experimental = {
2023-09-15 19:20:40 +01:00
ghost_text = true ,
2023-09-05 07:24:34 +01:00
native_menu = false ,
} ,
}
2023-10-27 21:12:23 +01:00
cmp.setup . cmdline ( { " / " , " ? " } , {
mapping = cmp.mapping . preset.cmdline ( ) ,
sources = {
{ name = " buffer " } ,
} ,
} )
2024-05-14 13:03:47 +01:00
cmp.setup . filetype ( { " sql " } , {
sources = {
{ name = " vim-dadbod-completion " } ,
{ name = " buffer " } ,
} ,
} )