return { 'saghen/blink.cmp', -- optional: provides snippets for the snippet source dependencies = { 'rafamadriz/friendly-snippets', "onsails/lspkind.nvim", "xzbdmw/colorful-menu.nvim", "nvim-tree/nvim-web-devicons" }, -- use a release tag to download pre-built binaries version = "v1.10.2", -- AND/OR build from source -- build = 'cargo build --release', -- If you use nix, you can build from source with: -- build = 'nix run .#build-plugin', ---@module 'blink.cmp' ---@type blink.cmp.Config opts = { -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) -- 'super-tab' for mappings similar to vscode (tab to accept) -- 'enter' for enter to accept -- 'none' for no mappings -- -- All presets have the following mappings: -- C-space: Open menu or open docs if already open -- C-n/C-p or Up/Down: Select next/previous item -- C-e: Hide menu -- C-k: Toggle signature help (if signature.enabled = true) -- -- See :h blink-cmp-config-keymap for defining your own keymap -- in your blink configuration keymap = { preset = 'none', -- If completion hasn't been triggered yet, insert the first suggestion; if it has, cycle to the next suggestion. [''] = { 'show', 'show_documentation', 'hide_documentation' }, [''] = { 'hide', 'fallback' }, [""] = { "select_next", "snippet_forward", "fallback" }, [""] = { "select_prev", "snippet_backward", "fallback" }, -- Selection with Enter [""] = { "accept", "fallback" }, [''] = { 'select_prev', 'fallback' }, [''] = { 'select_next', 'fallback' }, [''] = { 'select_prev', 'fallback_to_mappings' }, [''] = { 'select_next', 'fallback_to_mappings' }, [''] = { 'scroll_documentation_up', 'fallback' }, [''] = { 'scroll_documentation_down', 'fallback' }, [''] = { 'show_signature', 'hide_signature', 'fallback' }, }, appearance = { -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' -- Adjusts spacing to ensure icons are aligned nerd_font_variant = 'mono' }, -- (Default) Only show the documentation popup when manually triggered completion = { ghost_text = { enabled = true }, accept = { create_undo_point = true, auto_brackets = { enabled = true, kind_resolution = { enabled = true, }, semantic_token_resolution = { enabled = true, }, }, }, menu = { direction_priority = function() local ctx = require('blink.cmp').get_context() local item = require('blink.cmp').get_selected_item() if ctx == nil or item == nil then return { 's', 'n' } end local item_text = item.textEdit ~= nil and item.textEdit.newText or item.insertText or item.label local is_multi_line = item_text:find('\n') ~= nil -- after showing the menu upwards, we want to maintain that direction -- until we re-open the menu, so store the context id in a global variable if is_multi_line or vim.g.blink_cmp_upwards_ctx_id == ctx.id then vim.g.blink_cmp_upwards_ctx_id = ctx.id return { 'n', 's' } end return { 's', 'n' } end, draw = { columns = { { "kind_icon" }, { "label", gap = 1 } }, components = { kind_icon = { text = function(ctx) local icon = ctx.kind_icon if vim.tbl_contains({ "Path" }, ctx.source_name) then local dev_icon, _ = require("nvim-web-devicons").get_icon(ctx.label) if dev_icon then icon = dev_icon end else icon = require("lspkind").symbol_map[ctx.kind] or "" end return icon .. ctx.icon_gap end, -- Optionally, use the highlight groups from nvim-web-devicons -- You can also add the same function for `kind.highlight` if you want to -- keep the highlight groups in sync with the icons. highlight = function(ctx) local hl = ctx.kind_hl if vim.tbl_contains({ "Path" }, ctx.source_name) then local dev_icon, dev_hl = require("nvim-web-devicons").get_icon(ctx.label) if dev_icon then hl = dev_hl end end return hl end, }, label = { width = { fill = true, max = 60 }, text = function(ctx) local highlights_info = require("colorful-menu").blink_highlights(ctx) if highlights_info ~= nil then -- Or you want to add more item to label return highlights_info.label else return ctx.label end end, highlight = function(ctx) local highlights = {} local highlights_info = require("colorful-menu").blink_highlights(ctx) if highlights_info ~= nil then highlights = highlights_info.highlights end for _, idx in ipairs(ctx.label_matched_indices) do table.insert(highlights, { idx, idx + 1, group = "BlinkCmpLabelMatch" }) end -- Do something else return highlights end, }, }, } }, documentation = { auto_show = true, draw = function(opts) if opts.item and opts.item.documentation and opts.item.documentation.value then local out = require("pretty_hover.parser").parse(opts.item.documentation.value) opts.item.documentation.value = out:string() end opts.default_implementation(opts) end, }, list = { selection = { preselect = false, auto_insert = false } } }, -- Default list of enabled providers defined so that you can extend it -- elsewhere in your config, without redefining it, due to `opts_extend` sources = { default = { 'lsp', 'path', 'snippets', 'buffer' }, }, -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation, -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"` -- -- See the fuzzy documentation for more information fuzzy = { implementation = "prefer_rust_with_warning" }, signature = { enabled = true } }, opts_extend = { "sources.default" } }