Skip to content

Commit 8ba2069

Browse files
ofseedSaghen
andauthored
fix: join newlines in label_description (#333)
* fix: join newlines in `label_description` * feat: newline char for label/label_detail/label_description --------- Co-authored-by: Liam Dyer <[email protected]>
1 parent abf781a commit 8ba2069

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
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)