139 lines
3.8 KiB
Lua
139 lines
3.8 KiB
Lua
local cmp = require('cmp')
|
|
local luasnip = require('luasnip')
|
|
|
|
local t = function(str)
|
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
|
end
|
|
|
|
local check_back_space = function()
|
|
local col = vim.fn.col('.') - 1
|
|
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
|
|
end
|
|
|
|
cmp.setup({
|
|
|
|
formatting = {
|
|
format = function(entry, vim_item)
|
|
-- fancy icons and a name of kind
|
|
vim_item.kind = require('lspkind').presets.default[vim_item.kind] .. ' ' .. vim_item.kind
|
|
-- set a name for each source
|
|
vim_item.menu = ({
|
|
buffer = '[Buffer]',
|
|
nvim_lsp = '[LSP]',
|
|
ultisnips = '[UltiSnips]',
|
|
nvim_lua = '[Lua]',
|
|
cmp_tabnine = '[TabNine]',
|
|
look = '[Look]',
|
|
path = '[Path]',
|
|
spell = '[Spell]',
|
|
calc = '[Calc]',
|
|
emoji = '[Emoji]',
|
|
})[entry.source.name]
|
|
return vim_item
|
|
end,
|
|
},
|
|
mapping = {
|
|
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }),
|
|
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }),
|
|
['<C-e>'] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }),
|
|
['<CR>'] = cmp.mapping({
|
|
i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }),
|
|
c = cmp.mapping.confirm({ select = false }),
|
|
s = cmp.mapping.confirm({ select = false }),
|
|
}),
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
if luasnip.expand_or_jumpable() then
|
|
vim.api.nvim_feedkeys(t('<Plug>luasnip-expand-or-jump'), '', true)
|
|
else
|
|
fallback()
|
|
end
|
|
end, {
|
|
'i',
|
|
's',
|
|
}),
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
if luasnip.jumpable(-1) then
|
|
vim.api.nvim_feedkeys(t('<Plug>luasnip-jump-prev'), '', true)
|
|
else
|
|
fallback()
|
|
end
|
|
end, {
|
|
'i',
|
|
's',
|
|
}),
|
|
},
|
|
snippet = {
|
|
expand = function(args)
|
|
require('luasnip').lsp_expand(args.body)
|
|
end,
|
|
},
|
|
sources = {
|
|
{ name = 'luasnip' },
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'buffer' },
|
|
{ name = 'nvim_lua' },
|
|
{ name = 'look' },
|
|
{ name = 'path' },
|
|
{ name = 'cmp_tabnine' },
|
|
{ name = 'calc' },
|
|
{ name = 'spell' },
|
|
{ name = 'emoji' },
|
|
},
|
|
completion = { completeopt = 'menu,menuone,noinsert, noselect' },
|
|
sorting = {
|
|
comparators = {
|
|
cmp.config.compare.offset,
|
|
cmp.config.compare.exact,
|
|
cmp.config.compare.recently_used,
|
|
require("clangd_extensions.cmp_scores"),
|
|
cmp.config.compare.kind,
|
|
cmp.config.compare.sort_text,
|
|
cmp.config.compare.length,
|
|
cmp.config.compare.order,
|
|
},
|
|
},
|
|
-- experimental = { native_menu = true }
|
|
})
|
|
|
|
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
|
cmp.setup.cmdline('/', {
|
|
sources = {
|
|
{ name = 'buffer' },
|
|
},
|
|
})
|
|
|
|
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
|
cmp.setup.cmdline(':', {
|
|
sources = cmp.config.sources({
|
|
{ name = 'path' },
|
|
}, {
|
|
{ name = 'cmdline' },
|
|
}, {
|
|
{ name = 'buffer' },
|
|
}),
|
|
})
|
|
|
|
-- Autopairs
|
|
--require("nvim-autopairs.completion.cmp").setup({
|
|
-- map_cr = true,
|
|
-- map_complete = true,
|
|
-- auto_select = true
|
|
--})
|
|
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
|
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } }))
|
|
|
|
-- TabNine
|
|
--local tabnine = require('cmp_tabnine.config')
|
|
--tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true})
|
|
|
|
-- Database completion
|
|
vim.api.nvim_exec(
|
|
[[
|
|
autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })
|
|
]],
|
|
false
|
|
)
|