Skip to content

Commit

Permalink
docs: add recipe for lspkind + nvim-web-devicons, thanks @marovira!
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Feb 4, 2025
1 parent 85d0ca0 commit 66ed234
Showing 1 changed file with 78 additions and 27 deletions.
105 changes: 78 additions & 27 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66ed234

Please sign in to comment.