return { 'hrsh7th/nvim-cmp', dependencies = { { 'onsails/lspkind-nvim' }, { 'hrsh7th/cmp-buffer' }, { 'hrsh7th/cmp-nvim-lsp' }, { 'L3MON4D3/LuaSnip' }, { 'saadparwaiz1/cmp_luasnip' }, { 'hrsh7th/cmp-nvim-lua' }, { 'octaltree/cmp-look' }, { 'hrsh7th/cmp-path' }, { 'hrsh7th/cmp-calc' }, { 'f3fora/cmp-spell' }, { 'hrsh7th/cmp-emoji' }, { 'hrsh7th/cmp-cmdline' }, { 'dmitmel/cmp-cmdline-history' }, { 'ray-x/cmp-treesitter' }, { 'hrsh7th/cmp-nvim-lsp-signature-help' }, { 'p00f/clangd_extensions.nvim' }, { 'windwp/nvim-autopairs', config = true, }, }, config = function() local cmp = require('cmp') local luasnip = require('luasnip') local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end cmp.setup({ preselect = cmp.PreselectMode.None, mapping = { [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }), [''] = 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 = function(fallback) if cmp.visible() and cmp.get_active_entry() then cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }) else fallback() end end, c = cmp.mapping.confirm({ select = false }), s = cmp.mapping.confirm({ select = false }), }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif 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 cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then vim.api.nvim_feedkeys(t('luasnip-jump-prev'), '', true) else fallback() end end, { 'i', 's', }), [''] = cmp.mapping(cmp.mapping.complete( { config = { sources = { { name = 'cmdline_history' } } } } ), { 'c' }), }, 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, option = { get_bufnrs = function() local bufs = {} for _, win in ipairs(vim.api.nvim_list_wins()) do bufs[vim.api.nvim_win_get_buf(win)] = true end return vim.tbl_keys(bufs) end } }, -- { 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 vim.api.nvim_buf_get_option(0, 'filetype') == 'dap-repl' or vim.api.nvim_buf_get_option(0, 'filetype') == 'dapui_watches' or vim.api.nvim_buf_get_option(0, 'filetype') == 'dapui_hover' end, -- completion = { -- completeopt = 'menu,menuone,noinsert, noselect', -- border = 'rounded', -- }, window = { completion = cmp.config.window.bordered({ col_offset = -3, side_padding = 0, winhighlight = 'Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None', }), documentation = cmp.config.window.bordered({ winhighlight = 'Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None', }), }, formatting = { fields = { 'kind', 'abbr', 'menu' }, format = function(entry, vim_item) local kind = require('lspkind').cmp_format({ mode = 'symbol_text', maxwidth = 50, })(entry, vim_item) local strings = vim.split(kind.kind, '%s', { trimempty = true }) kind.kind = ' ' .. strings[1] .. ' ' -- kind.menu = ' (' .. strings[2] .. ')' return kind end, }, 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 = { { 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 = '' } })) end, event = { 'InsertEnter', 'CmdLineEnter' }, }