diff --git a/docs/recipes.md b/docs/recipes.md index 053aca27..ad621b26 100644 --- a/docs/recipes.md +++ b/docs/recipes.md @@ -90,33 +90,6 @@ completion = { } ``` -### `mini.icons` - -[Original discussion](https://github.com/Saghen/blink.cmp/discussions/458) - -```lua -completion = { - menu = { - draw = { - components = { - kind_icon = { - ellipsis = false, - text = function(ctx) - local kind_icon, _, _ = require('mini.icons').get('lsp', ctx.kind) - return kind_icon - end, - -- Optionally, you may also use the highlights from mini.icons - highlight = function(ctx) - local _, hl, _ = require('mini.icons').get('lsp', ctx.kind) - return hl - end, - } - } - } - } -} -``` - ### Hide Copilot on suggestion ```lua @@ -152,6 +125,84 @@ sources.providers.lsp.override.get_trigger_characters = function(self) end ``` +## Completion menu drawing + +### `mini.icons` + +[Original discussion](https://github.com/Saghen/blink.cmp/discussions/458) + +```lua +completion = { + menu = { + draw = { + components = { + kind_icon = { + ellipsis = false, + text = function(ctx) + local kind_icon, _, _ = require('mini.icons').get('lsp', ctx.kind) + return kind_icon + end, + -- Optionally, you may also use the highlights from mini.icons + highlight = function(ctx) + local _, hl, _ = require('mini.icons').get('lsp', ctx.kind) + return hl + end, + } + } + } + } +} +``` + +### `nvim-web-devicons` + `lspkind` + +[Original discussion](https://github.com/Saghen/blink.cmp/discussions/1146) + +```lua +completion = { + menu = { + draw = { + components = { + kind_icon = { + ellipsis = false, + text = function(ctx) + local lspkind = require("lspkind") + 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").symbolic(ctx.kind, { + mode = "symbol", + }) + 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 = "BlinkCmpKind" .. ctx.kind + or require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx) + 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, + } + } + } + } +} +``` + ## Sources ### Buffer completion from all open buffers