Skip to content

Commit 63dd87d

Browse files
committed
fix(chunk): respect multilines.enabled for overflow
1 parent f653dce commit 63dd87d

File tree

2 files changed

+111
-6
lines changed

2 files changed

+111
-6
lines changed

lua/tiny-inline-diagnostic/chunk.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
435435

436436
local other_extmarks_offset = extmarks.handle_other_extmarks(buf, diag_line, line_length)
437437

438-
if
439-
(opts.options.overflow.mode ~= "none" and not opts.options.multilines)
440-
or cursor_line == diag_line
441-
then
438+
local multilines_enabled = type(opts.options.multilines) == "table" and opts.options.multilines.enabled
439+
or opts.options.multilines
440+
441+
if (opts.options.overflow.mode ~= "none" and not multilines_enabled) or cursor_line == diag_line then
442442
local line_display_width = lines[1] and vim.fn.strdisplaywidth(lines[1]) or 0
443443
local visual_line_width = line_display_width + other_extmarks_offset
444444

@@ -458,7 +458,7 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
458458
diag_message = opts.options.format(diag)
459459
end
460460

461-
if not opts.options.multilines or cursor_line == diag_line then
461+
if not multilines_enabled or cursor_line == diag_line then
462462
chunks = M.handle_overflow_modes(
463463
opts,
464464
diag_message,

tests/test_chunk.lua

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,112 @@ T["get_chunks"]["sets need_to_be_under for long lines"] = function()
328328
}
329329

330330
local result = chunk.get_chunks(opts, diags, 1, 0, 0, buf)
331-
MiniTest.expect.equality(type(result.need_to_be_under), "boolean")
331+
MiniTest.expect.equality(result.need_to_be_under, true)
332+
end)
333+
end
334+
335+
T["get_chunks"]["does not set need_to_be_under for short lines"] = function()
336+
local short_line = "short"
337+
H.with_win_buf({ short_line }, nil, 80, function(buf, win)
338+
local opts = H.make_opts({
339+
options = {
340+
overflow = { mode = "wrap" },
341+
multilines = { enabled = false },
342+
softwrap = 10,
343+
break_line = { enabled = false },
344+
show_source = { enabled = false },
345+
},
346+
})
347+
local diags = {
348+
{ message = "test error", severity = vim.diagnostic.severity.ERROR, lnum = 0 },
349+
}
350+
351+
local result = chunk.get_chunks(opts, diags, 1, 0, 0, buf)
352+
MiniTest.expect.equality(result.need_to_be_under, false)
353+
end)
354+
end
355+
356+
T["get_chunks"]["uses display width not byte length"] = function()
357+
local line_with_multibyte = string.rep("こんにちは世界", 10)
358+
H.with_win_buf({ line_with_multibyte }, nil, 80, function(buf, win)
359+
local opts = H.make_opts({
360+
options = {
361+
overflow = { mode = "wrap" },
362+
multilines = { enabled = false },
363+
softwrap = 5,
364+
break_line = { enabled = false },
365+
show_source = { enabled = false },
366+
},
367+
})
368+
local diags = {
369+
{ message = "test", severity = vim.diagnostic.severity.ERROR, lnum = 0 },
370+
}
371+
372+
local result = chunk.get_chunks(opts, diags, 1, 0, 0, buf)
373+
MiniTest.expect.equality(result.need_to_be_under, true)
374+
end)
375+
end
376+
377+
T["get_chunks"]["uses virtcol when cursor on diagnostic line"] = function()
378+
local line = string.rep("x", 50)
379+
H.with_win_buf({ line }, { 1, 0 }, 80, function(buf, win)
380+
local opts = H.make_opts({
381+
options = {
382+
overflow = { mode = "wrap" },
383+
multilines = { enabled = false },
384+
softwrap = 10,
385+
break_line = { enabled = false },
386+
show_source = { enabled = false },
387+
},
388+
})
389+
local diags = {
390+
{ message = "test error", severity = vim.diagnostic.severity.ERROR, lnum = 0 },
391+
}
392+
393+
local result = chunk.get_chunks(opts, diags, 1, 0, 0, buf)
394+
MiniTest.expect.equality(result.need_to_be_under, false)
395+
end)
396+
end
397+
398+
T["get_chunks"]["accounts for window width in wrapping decision"] = function()
399+
local line = string.rep("x", 60)
400+
H.with_win_buf({ line }, nil, 80, function(buf, win)
401+
local opts = H.make_opts({
402+
options = {
403+
overflow = { mode = "wrap" },
404+
multilines = { enabled = false },
405+
softwrap = 10,
406+
break_line = { enabled = false },
407+
show_source = { enabled = false },
408+
},
409+
})
410+
local diags = {
411+
{ message = "test", severity = vim.diagnostic.severity.ERROR, lnum = 0 },
412+
}
413+
414+
local result = chunk.get_chunks(opts, diags, 1, 0, 0, buf)
415+
MiniTest.expect.equality(result.need_to_be_under, false)
416+
end)
417+
end
418+
419+
T["get_chunks"]["wraps when line exceeds window width minus softwrap"] = function()
420+
local line = string.rep("x", 80)
421+
H.with_win_buf({ line }, nil, 80, function(buf, win)
422+
local opts = H.make_opts({
423+
options = {
424+
overflow = { mode = "wrap" },
425+
multilines = { enabled = false },
426+
softwrap = 5,
427+
break_line = { enabled = false },
428+
show_source = { enabled = false },
429+
},
430+
})
431+
local diags = {
432+
{ message = "test", severity = vim.diagnostic.severity.ERROR, lnum = 0 },
433+
}
434+
435+
local result = chunk.get_chunks(opts, diags, 1, 0, 0, buf)
436+
MiniTest.expect.equality(result.need_to_be_under, true)
332437
end)
333438
end
334439

0 commit comments

Comments
 (0)