fix bug and change char in underline for error display

This commit is contained in:
Mark 2023-10-27 19:47:55 +02:00
parent b914b11af6
commit cfa5a5e43e

View File

@ -181,20 +181,22 @@ impl CheckError {
let highlight_end = pos.end.pos() - start; let highlight_end = pos.end.pos() - start;
if highlight_start < line_end && highlight_end > line_start if highlight_start < line_end && highlight_end > line_start
{ {
// where the highlight starts in this line
let hl_start = let hl_start =
highlight_start.saturating_sub(line_start); highlight_start.saturating_sub(line_start);
// highlight would be further left than cursor, so we need a new line
if hl_start < right { if hl_start < right {
right = 0; right = 0;
writeln!(f)?; writeln!(f)?;
} }
// length of the highlight
let hl_len = highlight_end let hl_len = highlight_end
.saturating_sub(line_start) .saturating_sub(line_start)
.saturating_sub(hl_start); .saturating_sub(hl_start);
let hl_space = hl_start - right; let hl_space = hl_start - right;
let print_indent = right == 0; let print_indent = right == 0;
let hl_len = hl_len.min(line.len() - right);
right += hl_space + hl_len; right += hl_space + hl_len;
let hl_len =
hl_len.min(highlight_end - highlight_start);
if print_indent && right != 0 { if print_indent && right != 0 {
write!(f, "{} ", indent!())?; write!(f, "{} ", indent!())?;
} }
@ -202,7 +204,7 @@ impl CheckError {
f, f,
"{}{}", "{}{}",
" ".repeat(hl_space), " ".repeat(hl_space),
"^".repeat(hl_len).color(*color) "~".repeat(hl_len).color(*color)
)?; )?;
} }
} }