1
1
--- @class blink.cmp.CompletionRenderContext
2
2
--- @field item blink.cmp.CompletionItem
3
+ --- @field label string
3
4
--- @field kind string
4
5
--- @field kind_icon string
5
6
--- @field icon_gap string
@@ -250,11 +251,15 @@ function autocomplete.draw()
250
251
for _ , item in ipairs (autocomplete .items ) do
251
252
local kind = require (' blink.cmp.types' ).CompletionItemKind [item .kind ] or ' Unknown'
252
253
local kind_icon = config .kind_icons [kind ] or config .kind_icons .Field
254
+ -- Some LSPs can return labels with newlines.
255
+ -- Escape them to avoid errors in nvim_buf_set_lines when rendering the autocomplete menu.
256
+ local label = item .label :gsub (' \n ' , ' \\ n' )
253
257
254
258
table.insert (
255
259
components_list ,
256
260
draw_fn ({
257
261
item = item ,
262
+ label = label ,
258
263
kind = kind ,
259
264
kind_icon = kind_icon ,
260
265
icon_gap = icon_gap ,
@@ -295,7 +300,7 @@ function autocomplete.render_item_simple(ctx)
295
300
' ' ,
296
301
{ ctx .kind_icon , ctx .icon_gap , hl_group = ' BlinkCmpKind' .. ctx .kind },
297
302
{
298
- ctx .item . label ,
303
+ ctx .label ,
299
304
ctx .kind == ' Snippet' and ' ~' or nil ,
300
305
fill = true ,
301
306
hl_group = ctx .deprecated and ' BlinkCmpLabelDeprecated' or ' BlinkCmpLabel' ,
@@ -311,7 +316,7 @@ function autocomplete.render_item_reversed(ctx)
311
316
return {
312
317
' ' ,
313
318
{
314
- ctx .item . label ,
319
+ ctx .label ,
315
320
ctx .kind == ' Snippet' and ' ~' or nil ,
316
321
fill = true ,
317
322
hl_group = ctx .deprecated and ' BlinkCmpLabelDeprecated' or ' BlinkCmpLabel' ,
@@ -329,7 +334,7 @@ function autocomplete.render_item_minimal(ctx)
329
334
return {
330
335
' ' ,
331
336
{
332
- ctx .item . label ,
337
+ ctx .label ,
333
338
ctx .kind == ' Snippet' and ' ~' or nil ,
334
339
fill = true ,
335
340
hl_group = ctx .deprecated and ' BlinkCmpLabelDeprecated' or ' BlinkCmpLabel' ,
0 commit comments