Skip to content

Commit 9e7e440

Browse files
committed
fix(ui): avoid extraneous empty lines for compacted headers
1 parent 8edc19a commit 9e7e440

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

lua/opencode/ui/formatter.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,12 @@ function M.format_message_header(message, previous_message)
280280
M._format_callout(output, 'ERROR', error_message)
281281
end
282282

283-
output:add_line('')
283+
local hidden_same_mode_assistant_header = role == 'assistant' and header_style == 'hidden' and same_mode_as_previous
284+
285+
if not hidden_same_mode_assistant_header then
286+
output:add_line('')
287+
end
288+
284289
return output
285290
end
286291

tests/unit/formatter_spec.lua

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,64 @@ describe('formatter', function()
437437
parts = {},
438438
})
439439

440-
assert.are.same({ '' }, output.lines)
440+
assert.are.same({}, output.lines)
441441
assert.is_nil(output.extmarks[0])
442442
end)
443443

444+
it('does not add a spacing-only block for hidden same-mode assistant messages', function()
445+
config.setup({
446+
ui = {
447+
output = {
448+
compact_assistant_headers = 'hidden',
449+
},
450+
},
451+
})
452+
453+
local previous_message = {
454+
info = {
455+
id = 'msg_prev',
456+
role = 'assistant',
457+
sessionID = 'ses_1',
458+
mode = 'build',
459+
},
460+
parts = {},
461+
}
462+
463+
local current_message = {
464+
info = {
465+
id = 'msg_current',
466+
role = 'assistant',
467+
sessionID = 'ses_1',
468+
mode = 'build',
469+
},
470+
parts = {},
471+
}
472+
473+
local previous_part = formatter.format_part({
474+
id = 'prt_prev',
475+
type = 'text',
476+
text = 'First reply',
477+
messageID = 'msg_prev',
478+
sessionID = 'ses_1',
479+
}, previous_message, true)
480+
481+
local header = formatter.format_message_header(current_message, previous_message)
482+
local current_part = formatter.format_part({
483+
id = 'prt_current',
484+
type = 'text',
485+
text = 'Second reply',
486+
messageID = 'msg_current',
487+
sessionID = 'ses_1',
488+
}, current_message, true)
489+
490+
local combined_lines = {}
491+
vim.list_extend(combined_lines, previous_part.lines)
492+
vim.list_extend(combined_lines, header.lines)
493+
vim.list_extend(combined_lines, current_part.lines)
494+
495+
assert.are.same({ 'First reply', '', 'Second reply', '' }, combined_lines)
496+
end)
497+
444498
it('keeps full assistant headers when the mode changes', function()
445499
config.setup({
446500
ui = {

0 commit comments

Comments
 (0)