local cmp_status_ok, cmp = pcall(require, "cmp") if not cmp_status_ok then return end local luasnip_status_ok, luasnip = pcall(require, "luasnip") if not luasnip_status_ok then return end local kind_icons = { Text = "", Method = "", Function = "", Constructor = "", Field = "", Variable = "", Class = "", Interface = "", Module = "", Property = "", Unit = "", Value = "", Enum = "", Keyword = "", Snippet = "", Color = "", File = "", Reference = "", Folder = "", EnumMember = "", Constant = "", Struct = "", Event = "", Operator = "", TypeParameter = "", } cmp.setup({ mapping = { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), -- Accept currently selected item. If none selected, `select` first item. -- Set `select` to `false` to only confirm explicitly selected items. [""] = cmp.mapping.confirm({ select = true }), }, sources = { { name = "gh_issues" }, { name = "nvim_lua" }, { name = "nvim_lsp" }, { name = "path" }, { name = "luasnip" }, { name = "buffer", keyword_length = 1 }, }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, formatting = { fields = { "kind", "abbr", "menu" }, format = function(entry, vim_item) vim_item.kind = kind_icons[vim_item.kind] vim_item.menu = ({ nvim_lsp = "[LSP]", nvim_lua = "[api]", luasnip = "[snip]", buffer = "[buf]", path = "[path]", emoji = "[emoji]", gh_issues = "[issues]", })[entry.source.name] return vim_item end, }, experimental = { ghost_text = true, native_menu = false, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, confirm_opts = { behavior = cmp.ConfirmBehavior.Replace, select = false, }, })