Skip to content

Commit d5f62f9

Browse files
tim3ndSaghen
andauthored
feat(render): support source_id and source_name in menu render (#400)
* feat(render): support `source_id` and `source_name` in menu render * doc: fix inconsistent readme * docs: add source_name hl group and draw docs --------- Co-authored-by: Liam Dyer <[email protected]>
1 parent b94172c commit d5f62f9

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ MiniDeps.add({
422422
text = function(ctx) return ctx.label_description end,
423423
highlight = 'BlinkCmpLabelDescription',
424424
},
425+
426+
source_name = {
427+
width = { max = 30 },
428+
text = function(ctx) return ctx.source_name end,
429+
highlight = 'BlinkCmpSource',
430+
},
425431
},
426432
},
427433
},
@@ -655,9 +661,10 @@ MiniDeps.add({
655661
| `BlinkCmpLabel` | Pmenu | Label of the completion item |
656662
| `BlinkCmpLabelDeprecated` | Comment | Deprecated label of the completion item |
657663
| `BlinkCmpLabelMatch` | Pmenu | (Currently unused) Label of the completion item when it matches the query |
658-
| `BlinkCmpGhostText` | Comment | Preview item with ghost text |
659664
| `BlinkCmpKind` | Special | Kind icon/text of the completion item |
660665
| `BlinkCmpKind<kind>` | Special | Kind icon/text of the completion item |
666+
| `BlinkCmpSourceName` | NonText | Source name of the completion item |
667+
| `BlinkCmpGhostText` | Comment | Preview item with ghost text |
661668
| `BlinkCmpDoc` | NormalFloat | The documentation window |
662669
| `BlinkCmpDocBorder` | NormalFloat | The documentation window border |
663670
| `BlinkCmpDocCursorLine` | Visual | The documentation window cursor line |
@@ -796,6 +803,13 @@ completion.menu.draw = {
796803
text = function(ctx) return ctx.label_description end,
797804
highlight = 'BlinkCmpLabelDescription',
798805
},
806+
807+
source_name = {
808+
width = { max = 30 },
809+
-- source_name or source_id are supported
810+
text = function(ctx) return ctx.source_name end,
811+
highlight = 'BlinkCmpSource',
812+
},
799813
},
800814
}
801815
```

lua/blink/cmp/completion/windows/render/context.lua

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
--- @field kind_icon string
1010
--- @field icon_gap string
1111
--- @field deprecated boolean
12+
--- @field source_id string
13+
--- @field source_name string
1214

1315
local context = {}
1416

@@ -46,6 +48,8 @@ function context.new(draw, item, matched_indices)
4648

4749
local label_detail = (item.labelDetails and item.labelDetails.detail or ''):gsub('\n', newline_char)
4850
local label_description = (item.labelDetails and item.labelDetails.description or ''):gsub('\n', newline_char)
51+
local source_id = item.source_id
52+
local source_name = item.source_name
4953

5054
return {
5155
self = draw,
@@ -58,6 +62,8 @@ function context.new(draw, item, matched_indices)
5862
kind_icon = kind_icon,
5963
icon_gap = config.nerd_font_variant == 'mono' and '' or ' ',
6064
deprecated = item.deprecated or (item.tags and vim.tbl_contains(item.tags, 1)) or false,
65+
source_id = source_id,
66+
source_name = source_name,
6167
}
6268
end
6369

lua/blink/cmp/config/completion/menu.lua

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ local window = {
9696
text = function(ctx) return ctx.label_description end,
9797
highlight = 'BlinkCmpLabelDescription',
9898
},
99+
100+
source_name = {
101+
width = { max = 30 },
102+
-- source_name or source_id are supported
103+
text = function(ctx) return ctx.source_name end,
104+
highlight = 'BlinkCmpSource',
105+
},
99106
},
100107
},
101108
},

lua/blink/cmp/highlights.lua

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function highlights.setup()
1717
set_hl('BlinkCmpLabelDetail', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
1818
set_hl('BlinkCmpLabelDescription', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
1919
set_hl('BlinkCmpKind', { link = use_nvim_cmp and 'CmpItemKind' or 'Special' })
20+
set_hl('BlinkCmpSource', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
2021
for _, kind in ipairs(require('blink.cmp.types').CompletionItemKind) do
2122
set_hl('BlinkCmpKind' .. kind, { link = use_nvim_cmp and 'CmpItemKind' .. kind or 'BlinkCmpKind' })
2223
end

0 commit comments

Comments
 (0)