aboutsummaryrefslogtreecommitdiff
path: root/src/error.cpp
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com>2024-06-13 16:42:04 +0200
committerThomas Voss <mail@thomasvoss.com>2024-06-13 17:24:56 +0200
commit9f7ac1469fc364330ada811032d295ba36f6e078 (patch)
tree3e47a911be5bbe005ce2c3e9752c2d0cffa1af72 /src/error.cpp
parent657c51636080e9b3c9c2215d05b08f3cccf68e70 (diff)
Generate ranges of the correct length
Diffstat (limited to 'src/error.cpp')
-rw-r--r--src/error.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/error.cpp b/src/error.cpp
index 5a4cb6a0c..1e24325c5 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -336,15 +336,27 @@ gb_internal isize show_error_on_line(TokenPos const &pos, TokenPos end) {
error_out("^");
if (end.file_id == pos.file_id) {
+ i32 rune;
+
if (end.line > pos.line) {
- for (i32 i = offset; i < line_len; i++) {
- error_out("~");
+ for (i32 rune, rune_width, off = offset; off < line_len; off += rune_width) {
+ rune_width = cast(i32)utf8proc_iterate((u8 const *)line_text + off, line_len - off, &rune);
+ int w = utf8proc_charwidth(rune);
+ if (w > 0) {
+ error_out("%.*s", w, "~~~~");
+ }
}
} else if (end.line == pos.line && end.column > pos.column) {
- for (i32 i = 1; i < error_length-1+squiggle_extra; i++) {
+ isize columns = squiggle_extra;
+ for (i32 rune, rune_width, off = offset; off < offset + error_length - 1; off += rune_width) {
+ rune_width = cast(i32)utf8proc_iterate((u8 const *)line_text + off, line_len - off, &rune);
+ columns += utf8proc_charwidth(rune);
+ }
+
+ for (isize i = 1; i < columns; i++) {
error_out("~");
}
- if (error_length > 1 && squiggle_extra == 0) {
+ if (columns > 0 && squiggle_extra == 0) {
error_out("^");
}
}