mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Improve error line squiggle logic
This commit is contained in:
+2
-2
@@ -4615,7 +4615,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
|
|||||||
entity = scope_lookup_current(import_scope, entity_name);
|
entity = scope_lookup_current(import_scope, entity_name);
|
||||||
bool allow_builtin = false;
|
bool allow_builtin = false;
|
||||||
if (!is_entity_declared_for_selector(entity, import_scope, &allow_builtin)) {
|
if (!is_entity_declared_for_selector(entity, import_scope, &allow_builtin)) {
|
||||||
error(op_expr, "'%.*s' is not declared by '%.*s'", LIT(entity_name), LIT(import_name));
|
error(node, "'%.*s' is not declared by '%.*s'", LIT(entity_name), LIT(import_name));
|
||||||
operand->mode = Addressing_Invalid;
|
operand->mode = Addressing_Invalid;
|
||||||
operand->expr = node;
|
operand->expr = node;
|
||||||
|
|
||||||
@@ -4635,7 +4635,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
|
|||||||
|
|
||||||
if (!is_entity_exported(entity, allow_builtin)) {
|
if (!is_entity_exported(entity, allow_builtin)) {
|
||||||
gbString sel_str = expr_to_string(selector);
|
gbString sel_str = expr_to_string(selector);
|
||||||
error(op_expr, "'%s' is not exported by '%.*s'", sel_str, LIT(import_name));
|
error(node, "'%s' is not exported by '%.*s'", sel_str, LIT(import_name));
|
||||||
gb_string_free(sel_str);
|
gb_string_free(sel_str);
|
||||||
// NOTE(bill): make the state valid still, even if it's "invalid"
|
// NOTE(bill): make the state valid still, even if it's "invalid"
|
||||||
// operand->mode = Addressing_Invalid;
|
// operand->mode = Addressing_Invalid;
|
||||||
|
|||||||
+18
-18
@@ -261,30 +261,31 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) {
|
|||||||
enum {
|
enum {
|
||||||
MAX_LINE_LENGTH = 80,
|
MAX_LINE_LENGTH = 80,
|
||||||
MAX_TAB_WIDTH = 8,
|
MAX_TAB_WIDTH = 8,
|
||||||
ELLIPSIS_PADDING = 8 // `... ...`
|
ELLIPSIS_PADDING = 8, // `... ...`
|
||||||
|
MAX_LINE_LENGTH_PADDED = MAX_LINE_LENGTH-MAX_TAB_WIDTH-ELLIPSIS_PADDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
error_out("\t");
|
error_out("\t");
|
||||||
|
|
||||||
terminal_set_colours(TerminalStyle_Bold, TerminalColour_White);
|
terminal_set_colours(TerminalStyle_Bold, TerminalColour_White);
|
||||||
|
|
||||||
|
|
||||||
|
i32 error_length = gb_max(end.offset - pos.offset, 1);
|
||||||
|
|
||||||
isize squiggle_extra = 0;
|
isize squiggle_extra = 0;
|
||||||
|
|
||||||
if (line.len+MAX_TAB_WIDTH+ELLIPSIS_PADDING > MAX_LINE_LENGTH) {
|
if (line.len > MAX_LINE_LENGTH_PADDED) {
|
||||||
i32 const half_width = MAX_LINE_LENGTH/2;
|
i32 left = MAX_TAB_WIDTH;
|
||||||
i32 left = cast(i32)(offset);
|
|
||||||
i32 right = cast(i32)(line.len - offset);
|
|
||||||
left = gb_min(left, half_width);
|
|
||||||
right = gb_min(right, half_width);
|
|
||||||
|
|
||||||
line.text += offset-left;
|
line.text += offset-left;
|
||||||
line.len -= offset+right-left;
|
line.len -= offset-left;
|
||||||
|
offset = left+MAX_TAB_WIDTH/2;
|
||||||
line = string_trim_whitespace(line);
|
if (line.len > MAX_LINE_LENGTH_PADDED) {
|
||||||
|
line.len = MAX_LINE_LENGTH_PADDED;
|
||||||
squiggle_extra = ELLIPSIS_PADDING/2 + 1;
|
if (error_length > line.len-left) {
|
||||||
offset = left + ELLIPSIS_PADDING/2;
|
error_length = cast(i32)line.len - left;
|
||||||
|
squiggle_extra = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
error_out("... %.*s ...", LIT(line));
|
error_out("... %.*s ...", LIT(line));
|
||||||
} else {
|
} else {
|
||||||
error_out("%.*s", LIT(line));
|
error_out("%.*s", LIT(line));
|
||||||
@@ -304,11 +305,10 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) {
|
|||||||
error_out("~");
|
error_out("~");
|
||||||
}
|
}
|
||||||
} else if (end.line == pos.line && end.column > pos.column) {
|
} else if (end.line == pos.line && end.column > pos.column) {
|
||||||
i32 length = gb_min(end.offset - pos.offset, cast(i32)(line.len-offset));
|
for (i32 i = 1; i < error_length-1+squiggle_extra; i++) {
|
||||||
for (i32 i = 1; i < length-1+squiggle_extra; i++) {
|
|
||||||
error_out("~");
|
error_out("~");
|
||||||
}
|
}
|
||||||
if (length > 1 && squiggle_extra == 0) {
|
if (error_length > 1 && squiggle_extra == 0) {
|
||||||
error_out("^");
|
error_out("^");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -20,8 +20,8 @@ gb_internal Token ast_token(Ast *node) {
|
|||||||
case Ast_ParenExpr: return node->ParenExpr.open;
|
case Ast_ParenExpr: return node->ParenExpr.open;
|
||||||
case Ast_CallExpr: return ast_token(node->CallExpr.proc);
|
case Ast_CallExpr: return ast_token(node->CallExpr.proc);
|
||||||
case Ast_SelectorExpr:
|
case Ast_SelectorExpr:
|
||||||
if (node->SelectorExpr.selector != nullptr) {
|
if (node->SelectorExpr.expr != nullptr) {
|
||||||
return ast_token(node->SelectorExpr.selector);
|
return ast_token(node->SelectorExpr.expr);
|
||||||
}
|
}
|
||||||
return node->SelectorExpr.token;
|
return node->SelectorExpr.token;
|
||||||
case Ast_SelectorCallExpr:
|
case Ast_SelectorCallExpr:
|
||||||
|
|||||||
Reference in New Issue
Block a user