Skip to content

Commit

Permalink
feat: add minimal render style (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
lopi-py authored Oct 11, 2024
1 parent d334b65 commit b4bbad1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ MiniDeps.add({
-- Controls how the completion items are rendered on the popup window
-- 'simple' will render the item's kind icon the left alongside the label
-- 'reversed' will render the label on the left and the kind icon + name on the right
-- 'minimal' will render the label on the left and the kind name on the right
-- 'function(blink.cmp.CompletionRenderContext): blink.cmp.Component[]' for custom rendering
draw = 'simple',
-- Controls the cycling behavior when reaching the beginning or end of the completion list.
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
--- @field preselect? boolean
--- @field winhighlight? string
--- @field scrolloff? number
--- @field draw? 'simple' | 'reversed' | function(blink.cmp.CompletionRenderContext): blink.cmp.Component[]
--- @field draw? 'simple' | 'reversed' | 'minimal' | function(blink.cmp.CompletionRenderContext): blink.cmp.Component[]
--- @field cycle? blink.cmp.AutocompleteConfig.CycleConfig

--- @class blink.cmp.AutocompleteConfig.CycleConfig
Expand Down
20 changes: 20 additions & 0 deletions lua/blink/cmp/windows/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ function autocomplete.get_draw_fn()
return autocomplete.render_item_simple
elseif autocmp_config.draw == 'reversed' then
return autocomplete.render_item_reversed
elseif autocmp_config.draw == 'minimal' then
return autocomplete.render_item_minimal
end
error('Invalid autocomplete window draw config')
end
Expand All @@ -260,6 +262,7 @@ function autocomplete.render_item_simple(ctx)
{ ctx.kind_icon, ctx.icon_gap, hl_group = 'BlinkCmpKind' .. ctx.kind },
{
ctx.item.label,
ctx.kind == 'Snippet' and '~' or nil,
fill = true,
hl_group = ctx.deprecated and 'BlinkCmpLabelDeprecated' or 'BlinkCmpLabel',
max_width = 50,
Expand All @@ -275,6 +278,7 @@ function autocomplete.render_item_reversed(ctx)
' ',
{
ctx.item.label,
ctx.kind == 'Snippet' and '~' or nil,
fill = true,
hl_group = ctx.deprecated and 'BlinkCmpLabelDeprecated' or 'BlinkCmpLabel',
max_width = 50,
Expand All @@ -285,6 +289,22 @@ function autocomplete.render_item_reversed(ctx)
}
end

function autocomplete.render_item_minimal(ctx)
return {
' ',
{
ctx.item.label,
ctx.kind == 'Snippet' and '~' or nil,
fill = true,
hl_group = ctx.deprecated and 'BlinkCmpLabelDeprecated' or 'BlinkCmpLabel',
max_width = 50,
},
' ',
{ ctx.kind, hl_group = 'BlinkCmpKind' .. ctx.kind },
' ',
}
end

---@return blink.cmp.CompletionItem?
function autocomplete.get_selected_item()
if not autocomplete.win:is_open() then return end
Expand Down

0 comments on commit b4bbad1

Please sign in to comment.