diag: update bluelib api usage

This commit is contained in:
2025-11-06 10:38:58 +00:00
parent 6d172e1dc0
commit 9622e30e0f
4 changed files with 25 additions and 25 deletions

View File

@@ -12,4 +12,4 @@ endif ()
target_include_directories(ivy-diag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/) target_include_directories(ivy-diag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_compile_definitions(ivy-diag PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC}) target_compile_definitions(ivy-diag PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
target_link_libraries(ivy-diag ivy-common Bluelib::Core Bluelib::Object Bluelib::Term) target_link_libraries(ivy-diag ivy-common Bluelib::Core Bluelib::Ds Bluelib::Term)

View File

@@ -52,11 +52,12 @@ void ivy_diag_ctx_write(
struct ivy_diag_ctx *ctx, enum ivy_diag_format format, struct ivy_diag_ctx *ctx, enum ivy_diag_format format,
struct ivy_diag_stream *stream) struct ivy_diag_stream *stream)
{ {
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&ctx->ctx_diags);
b_queue_foreach (&it, &ctx->ctx_diags) { while (entry) {
struct ivy_diag *diag struct ivy_diag *diag
= b_unbox(struct ivy_diag, it.entry, diag_entry); = b_unbox(struct ivy_diag, entry, diag_entry);
diag_write(ctx, diag, format, stream); diag_write(ctx, diag, format, stream);
entry = b_queue_next(entry);
} }
} }

View File

@@ -3,7 +3,7 @@
#include "ctx.h" #include "ctx.h"
#include <assert.h> #include <assert.h>
#include <blue/object/string.h> #include <blue/ds/string.h>
#include <ivy/diag.h> #include <ivy/diag.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@@ -25,7 +25,7 @@ struct snippet_print_ctx {
size_t ctx_line_buf_ptr; size_t ctx_line_buf_ptr;
bool ctx_has_underline; bool ctx_has_underline;
b_stringstream ctx_underline; b_stringstream *ctx_underline;
struct diag_c_snippet *ctx_snippet; struct diag_c_snippet *ctx_snippet;
@@ -67,23 +67,23 @@ struct snippet_print_ctx {
#define STREAM_COLOUR_ERROR_B(stream, str) \ #define STREAM_COLOUR_ERROR_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stringstream_add(str, __STREAM_COLOUR_ERROR); \ b_stream_write_string(str, __STREAM_COLOUR_ERROR, NULL); \
} }
#define STREAM_COLOUR_WARN_B(stream, str) \ #define STREAM_COLOUR_WARN_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stringstream_add(str, __STREAM_COLOUR_WARN); \ b_stream_write_string(str, __STREAM_COLOUR_WARN, NULL); \
} }
#define STREAM_COLOUR_HINT_B(stream, str) \ #define STREAM_COLOUR_HINT_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stringstream_add(str, __STREAM_COLOUR_HINT); \ b_stream_write_string(str, __STREAM_COLOUR_HINT, NULL); \
} }
#define STREAM_COLOUR_ACCENT_B(stream, str) \ #define STREAM_COLOUR_ACCENT_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stringstream_add(str, __STREAM_COLOUR_ACCENT); \ b_stream_write_string(str, __STREAM_COLOUR_ACCENT, NULL); \
} }
#define STREAM_COLOUR_RESET_B(stream, str) \ #define STREAM_COLOUR_RESET_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stringstream_add(str, __STREAM_COLOUR_RESET); \ b_stream_write_string(str, __STREAM_COLOUR_RESET, NULL); \
} }
static void print_header( static void print_header(
@@ -233,7 +233,6 @@ static bool amendment_contains_cell(
static struct ivy_diag_highlight *find_highlight( static struct ivy_diag_highlight *find_highlight(
struct diag_c_snippet *snippet, size_t row, size_t col) struct diag_c_snippet *snippet, size_t row, size_t col)
{ {
b_queue_iterator it;
for (size_t i = 0; i < snippet->s_nr_highlights; i++) { for (size_t i = 0; i < snippet->s_nr_highlights; i++) {
struct ivy_diag_highlight *hl = &snippet->s_highlights[i]; struct ivy_diag_highlight *hl = &snippet->s_highlights[i];
@@ -248,7 +247,6 @@ static struct ivy_diag_highlight *find_highlight(
static struct ivy_diag_amendment *find_amendment( static struct ivy_diag_amendment *find_amendment(
struct diag_c_snippet *snippet, size_t row, size_t col) struct diag_c_snippet *snippet, size_t row, size_t col)
{ {
b_queue_iterator it;
for (size_t i = 0; i < snippet->s_nr_amendments; i++) { for (size_t i = 0; i < snippet->s_nr_amendments; i++) {
struct ivy_diag_amendment *a = &snippet->s_amendments[i]; struct ivy_diag_amendment *a = &snippet->s_amendments[i];
@@ -296,15 +294,15 @@ static void update_highlighting(struct snippet_print_ctx *ctx)
switch (ctx->ctx_hl->h_type) { switch (ctx->ctx_hl->h_type) {
case IVY_DIAG_HIGHLIGHT_ERROR: case IVY_DIAG_HIGHLIGHT_ERROR:
STREAM_COLOUR_ERROR(ctx->ctx_stream); STREAM_COLOUR_ERROR(ctx->ctx_stream);
STREAM_COLOUR_ERROR_B(ctx->ctx_stream, &ctx->ctx_underline); STREAM_COLOUR_ERROR_B(ctx->ctx_stream, ctx->ctx_underline);
break; break;
case IVY_DIAG_HIGHLIGHT_WARNING: case IVY_DIAG_HIGHLIGHT_WARNING:
STREAM_COLOUR_WARN(ctx->ctx_stream); STREAM_COLOUR_WARN(ctx->ctx_stream);
STREAM_COLOUR_WARN_B(ctx->ctx_stream, &ctx->ctx_underline); STREAM_COLOUR_WARN_B(ctx->ctx_stream, ctx->ctx_underline);
break; break;
case IVY_DIAG_HIGHLIGHT_HINT: case IVY_DIAG_HIGHLIGHT_HINT:
STREAM_COLOUR_HINT(ctx->ctx_stream); STREAM_COLOUR_HINT(ctx->ctx_stream);
STREAM_COLOUR_HINT_B(ctx->ctx_stream, &ctx->ctx_underline); STREAM_COLOUR_HINT_B(ctx->ctx_stream, ctx->ctx_underline);
break; break;
default: default:
break; break;
@@ -318,9 +316,8 @@ static enum ivy_status read_row(struct snippet_print_ctx *ctx, size_t row)
ctx->ctx_line_buf_ptr = 0; ctx->ctx_line_buf_ptr = 0;
ctx->ctx_has_underline = false; ctx->ctx_has_underline = false;
b_stringstream_begin( ctx->ctx_underline = b_stringstream_create_with_buffer(
&ctx->ctx_underline, ctx->ctx_underline_buf, ctx->ctx_underline_buf, sizeof ctx->ctx_underline_buf);
sizeof ctx->ctx_underline_buf);
size_t nr_read; size_t nr_read;
return ivy_line_source_get_row( return ivy_line_source_get_row(
@@ -383,7 +380,7 @@ static int get_char(struct snippet_print_ctx *ctx)
static void update_underline(struct snippet_print_ctx *ctx) static void update_underline(struct snippet_print_ctx *ctx)
{ {
if (!ctx->ctx_hl) { if (!ctx->ctx_hl) {
b_stringstream_add(&ctx->ctx_underline, " "); b_stream_write_char(ctx->ctx_underline, ' ');
return; return;
} }
@@ -391,10 +388,10 @@ static void update_underline(struct snippet_print_ctx *ctx)
case IVY_DIAG_HIGHLIGHT_ERROR: case IVY_DIAG_HIGHLIGHT_ERROR:
case IVY_DIAG_HIGHLIGHT_WARNING: case IVY_DIAG_HIGHLIGHT_WARNING:
case IVY_DIAG_HIGHLIGHT_HINT: case IVY_DIAG_HIGHLIGHT_HINT:
b_stringstream_add(&ctx->ctx_underline, "^"); b_stream_write_char(ctx->ctx_underline, '^');
break; break;
default: default:
b_stringstream_add(&ctx->ctx_underline, " "); b_stream_write_char(ctx->ctx_underline, ' ');
break; break;
} }
} }
@@ -484,13 +481,15 @@ static enum ivy_status write(
print_header(ctx, diag, stream); print_header(ctx, diag, stream);
print_location(ctx, diag, stream); print_location(ctx, diag, stream);
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&diag->diag_components);
b_queue_foreach (&it, &diag->diag_components) { while (entry) {
struct diag_component *c struct diag_component *c
= b_unbox(struct diag_component, it.entry, c_entry); = b_unbox(struct diag_component, entry, c_entry);
diag_stream_putc(stream, '\n'); diag_stream_putc(stream, '\n');
print_component(ctx, diag, c, stream); print_component(ctx, diag, c, stream);
entry = b_queue_next(entry);
} }
return IVY_OK; return IVY_OK;