Skip to content

Commit

Permalink
fix: join newlines in label_description (#333)
Browse files Browse the repository at this point in the history
* fix: join newlines in `label_description`

* feat: newline char for label/label_detail/label_description

---------

Co-authored-by: Liam Dyer <liamcdyer@gmail.com>
  • Loading branch information
ofseed and Saghen authored Nov 15, 2024
1 parent abf781a commit 8ba2069
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lua/blink/cmp/windows/render/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ function context.new(draw, item, matched_indices)
local config = require('blink.cmp.config')
local kind = require('blink.cmp.types').CompletionItemKind[item.kind] or 'Unknown'
local kind_icon = config.kind_icons[kind] or config.kind_icons.Field

-- Some LSPs can return labels with newlines.
-- Escape them to avoid errors in nvim_buf_set_lines when rendering the autocomplete menu.
local label = item.label:gsub('\n', '\\n') .. (kind == 'Snippet' and '~' or '')
local icon_spacing = config.nerd_font_variant == 'mono' and '' or ' '
local newline_char = '' .. icon_spacing
local label = item.label:gsub('\n', newline_char) .. (kind == 'Snippet' and '~' or '')
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)
if config.nerd_font_variant == 'normal' then label = label:gsub('', '') end

return {
self = draw,
item = item,
label = label,
label_detail = item.labelDetails and item.labelDetails.detail or '',
label_description = item.labelDetails and item.labelDetails.description or '',
label_detail = label_detail,
label_description = label_description,
label_matched_indices = matched_indices,
kind = kind,
kind_icon = kind_icon,
Expand Down

0 comments on commit 8ba2069

Please sign in to comment.