tool: diag: output formatting fixes

This commit is contained in:
2026-03-16 12:09:11 +00:00
parent 778835032d
commit a29779aa83

View File

@@ -19,8 +19,9 @@ struct snippet_print_ctx {
struct mie_line_source *ctx_line_source;
size_t ctx_row, ctx_col;
size_t ctx_indent_offset;
bool ctx_has_underline;
bool ctx_has_underline, ctx_in_content;
b_stringstream *ctx_underline;
const b_string *ctx_linebuf;
const b_iterator *ctx_linebuf_ptr;
@@ -224,18 +225,22 @@ static void update_amendment(struct snippet_print_ctx *ctx)
{
if (ctx->ctx_amendment
&& amendment_contains_cell(
ctx->ctx_amendment, ctx->ctx_row, ctx->ctx_col)) {
ctx->ctx_amendment, ctx->ctx_row,
ctx->ctx_col + ctx->ctx_indent_offset)) {
return;
}
ctx->ctx_amendment
= find_amendment(ctx->ctx_snippet, ctx->ctx_row, ctx->ctx_col);
ctx->ctx_amendment = find_amendment(
ctx->ctx_snippet, ctx->ctx_row,
ctx->ctx_col + ctx->ctx_indent_offset);
}
static void update_highlighting(struct snippet_print_ctx *ctx)
{
if (ctx->ctx_hl
&& highlight_contains_cell(ctx->ctx_hl, ctx->ctx_row, ctx->ctx_col)) {
&& highlight_contains_cell(
ctx->ctx_hl, ctx->ctx_row,
ctx->ctx_col + ctx->ctx_indent_offset)) {
return;
}
@@ -243,8 +248,9 @@ static void update_highlighting(struct snippet_print_ctx *ctx)
STREAM_COLOUR_RESET(ctx->ctx_stream);
const struct mie_diag_highlight *new_hl
= find_highlight(ctx->ctx_snippet, ctx->ctx_row, ctx->ctx_col);
const struct mie_diag_highlight *new_hl = find_highlight(
ctx->ctx_snippet, ctx->ctx_row,
ctx->ctx_col + ctx->ctx_indent_offset);
if (!new_hl) {
return;
@@ -299,7 +305,8 @@ static int get_char_amendment(struct snippet_print_ctx *ctx)
switch (a->a_type) {
case MIE_DIAG_AMENDMENT_ADD:
i = ctx->ctx_col - a->a_add.a_loc.c_row;
i = ctx->ctx_col - ctx->ctx_indent_offset - a->a_add.a_loc.c_row
- 1;
return a->a_add.a_str[i];
case MIE_DIAG_AMENDMENT_REMOVE:
b_iterator_move_next(ctx->ctx_linebuf_ptr);
@@ -334,13 +341,24 @@ static int get_char(struct snippet_print_ctx *ctx)
return get_char_amendment(ctx);
}
b_wchar c = b_iterator_get_cvalue(ctx->ctx_linebuf_ptr).v_int;
if (c == B_WCHAR_INVALID) {
return GET_CHAR_STOP;
};
b_wchar c = B_WCHAR_INVALID;
b_iterator_move_next(ctx->ctx_linebuf_ptr);
return c;
while (1) {
c = b_iterator_get_cvalue(ctx->ctx_linebuf_ptr).v_int;
if (c == B_WCHAR_INVALID) {
return GET_CHAR_STOP;
}
b_iterator_move_next(ctx->ctx_linebuf_ptr);
if (isspace(c) && !ctx->ctx_in_content) {
ctx->ctx_indent_offset++;
continue;
}
ctx->ctx_in_content = true;
return c;
}
}
static void update_underline(struct snippet_print_ctx *ctx)
@@ -414,6 +432,10 @@ static void print_snippet(
update_highlighting(&printer);
if (c == '[') {
b_tty_putc(stream, 0, c);
}
b_tty_putc(stream, 0, c);
update_underline(&printer);