Skip to content

Commit 0622b81

Browse files
committed
feat: newline char for label/label_detail/label_description
1 parent 96191fd commit 0622b81

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ MiniDeps.add({
473473

474474
label_description = {
475475
width = { max = 30 },
476-
text = function(ctx) return (ctx.label_description:gsub('\n%s*', ' ')) end,
476+
text = function(ctx) return ctx.label_description end,
477477
highlight = 'BlinkCmpLabelDescription',
478478
},
479479
},

lua/blink/cmp/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ local config = {
459459

460460
label_description = {
461461
width = { max = 30 },
462-
text = function(ctx) return (ctx.label_description:gsub('\n%s*', ' ')) end,
462+
text = function(ctx) return ctx.label_description end,
463463
highlight = 'BlinkCmpLabelDescription',
464464
},
465465
},

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,22 @@ function context.new(draw, item, matched_indices)
3535
local config = require('blink.cmp.config')
3636
local kind = require('blink.cmp.types').CompletionItemKind[item.kind] or 'Unknown'
3737
local kind_icon = config.kind_icons[kind] or config.kind_icons.Field
38+
3839
-- Some LSPs can return labels with newlines.
3940
-- Escape them to avoid errors in nvim_buf_set_lines when rendering the autocomplete menu.
40-
local label = item.label:gsub('\n', '\\n') .. (kind == 'Snippet' and '~' or '')
41+
local icon_spacing = config.nerd_font_variant == 'mono' and '' or ' '
42+
local newline_char = '' .. icon_spacing
43+
local label = item.label:gsub('\n', newline_char) .. (kind == 'Snippet' and '~' or '')
44+
local label_detail = (item.labelDetails and item.labelDetails.detail or ''):gsub('\n', newline_char)
45+
local label_description = (item.labelDetails and item.labelDetails.description or ''):gsub('\n', newline_char)
4146
if config.nerd_font_variant == 'normal' then label = label:gsub('', '') end
4247

4348
return {
4449
self = draw,
4550
item = item,
4651
label = label,
47-
label_detail = item.labelDetails and item.labelDetails.detail or '',
48-
label_description = item.labelDetails and item.labelDetails.description or '',
52+
label_detail = label_detail,
53+
label_description = label_description,
4954
label_matched_indices = matched_indices,
5055
kind = kind,
5156
kind_icon = kind_icon,

0 commit comments

Comments
 (0)