Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(render): support source_id and source_name in menu render #400

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ MiniDeps.add({
text = function(ctx) return ctx.label_description end,
highlight = 'BlinkCmpLabelDescription',
},

source_name = {
width = { max = 30 },
text = function(ctx) return ctx.source_name end,
highlight = 'BlinkCmpSource',
},
},
},
},
Expand Down Expand Up @@ -655,9 +661,10 @@ MiniDeps.add({
| `BlinkCmpLabel` | Pmenu | Label of the completion item |
| `BlinkCmpLabelDeprecated` | Comment | Deprecated label of the completion item |
| `BlinkCmpLabelMatch` | Pmenu | (Currently unused) Label of the completion item when it matches the query |
| `BlinkCmpGhostText` | Comment | Preview item with ghost text |
| `BlinkCmpKind` | Special | Kind icon/text of the completion item |
| `BlinkCmpKind<kind>` | Special | Kind icon/text of the completion item |
| `BlinkCmpSourceName` | NonText | Source name of the completion item |
| `BlinkCmpGhostText` | Comment | Preview item with ghost text |
| `BlinkCmpDoc` | NormalFloat | The documentation window |
| `BlinkCmpDocBorder` | NormalFloat | The documentation window border |
| `BlinkCmpDocCursorLine` | Visual | The documentation window cursor line |
Expand Down Expand Up @@ -796,6 +803,13 @@ completion.menu.draw = {
text = function(ctx) return ctx.label_description end,
highlight = 'BlinkCmpLabelDescription',
},

source_name = {
width = { max = 30 },
-- source_name or source_id are supported
text = function(ctx) return ctx.source_name end,
highlight = 'BlinkCmpSource',
},
},
}
```
Expand Down
6 changes: 6 additions & 0 deletions lua/blink/cmp/completion/windows/render/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
--- @field kind_icon string
--- @field icon_gap string
--- @field deprecated boolean
--- @field source_id string
--- @field source_name string

local context = {}

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

local label_detail = (item.labelDetails and item.labelDetails.detail or ''):gsub('\n', newline_char)
local label_description = (item.labelDetails and item.labelDetails.description or ''):gsub('\n', newline_char)
local source_id = item.source_id
local source_name = item.source_name

return {
self = draw,
Expand All @@ -58,6 +62,8 @@ function context.new(draw, item, matched_indices)
kind_icon = kind_icon,
icon_gap = config.nerd_font_variant == 'mono' and '' or ' ',
deprecated = item.deprecated or (item.tags and vim.tbl_contains(item.tags, 1)) or false,
source_id = source_id,
source_name = source_name,
}
end

Expand Down
7 changes: 7 additions & 0 deletions lua/blink/cmp/config/completion/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ local window = {
text = function(ctx) return ctx.label_description end,
highlight = 'BlinkCmpLabelDescription',
},

source_name = {
width = { max = 30 },
-- source_name or source_id are supported
text = function(ctx) return ctx.source_name end,
highlight = 'BlinkCmpSource',
},
},
},
},
Expand Down
1 change: 1 addition & 0 deletions lua/blink/cmp/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function highlights.setup()
set_hl('BlinkCmpLabelDetail', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
set_hl('BlinkCmpLabelDescription', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
set_hl('BlinkCmpKind', { link = use_nvim_cmp and 'CmpItemKind' or 'Special' })
set_hl('BlinkCmpSource', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
for _, kind in ipairs(require('blink.cmp.types').CompletionItemKind) do
set_hl('BlinkCmpKind' .. kind, { link = use_nvim_cmp and 'CmpItemKind' .. kind or 'BlinkCmpKind' })
end
Expand Down