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 = require('lspkind').cmp_format({ mode = 'symbol_text', -- show only symbol annotations maxwidth = 80, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) }) }, mapping = { [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }), [''] = cmp.mapping({ i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }), c = cmp.mapping.confirm({ select = false }), s = cmp.mapping.confirm({ select = false }), }), [''] = cmp.mapping(function(fallback) if luasnip.expand_or_jumpable() then vim.api.nvim_feedkeys(t('luasnip-expand-or-jump'), '', true) else fallback() end end, { 'i', 's', }), [''] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then vim.api.nvim_feedkeys(t('luasnip-jump-prev'), '', true) else fallback() end end, { 'i', 's', }), }, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, sources = { { name = 'luasnip', priority = 8 }, { name = 'nvim_lsp', priority = 7 }, { name = 'nvim_lsp_signature_help', priority = 7 }, { name = 'treesitter', priority = 6 }, { name = 'buffer', priority = 5 }, -- { name = 'nvim_lua' }, -- { name = 'look' }, -- { name = 'path' }, -- { name = 'cmp_tabnine' }, -- { name = 'calc' }, -- { name = 'spell' }, -- { name = 'emoji' }, }, enabled = function() return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt" or require("cmp_dap").is_dap_buffer() end, completion = { completeopt = 'menu,menuone,noinsert, noselect' }, window = { -- completion = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(), }, sorting = { comparators = { require('clangd_extensions.cmp_scores'), cmp.config.compare.locality, -- cmp.config.compare.recently_used, -- -- cmp.config.compare.offset, -- cmp.config.compare.exact, -- cmp.config.compare.recently_used, -- 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 = { { name = 'cmdline' }, { name = 'cmdline_history' }, { name = 'path' }, { name = 'buffer' }, }, }) require('cmp').setup.filetype({ 'dap-repl', 'dapui_watches', 'dapui_hover' }, { sources = { { name = 'dap' }, }, }) -- 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 = '' } }))