Skip to content

Commit

Permalink
Merge pull request #701 from epage/cleanup
Browse files Browse the repository at this point in the history
refactor(error): Clean up highlight code
  • Loading branch information
epage committed Mar 11, 2024
2 parents 01d2f4a + 31457b3 commit d41c62c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/toml_edit/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ impl Display for TomlError {
let col_num = column + 1;
let gutter = line_num.to_string().len();
let content = raw.split('\n').nth(line).expect("valid line number");
let highlight_len = span.end - span.start;
// Allow highlight to go one past the line
let highlight_len = highlight_len.min(content.len().saturating_sub(column));

writeln!(
f,
Expand Down Expand Up @@ -125,7 +128,7 @@ impl Display for TomlError {
// The span will be empty at eof, so we need to make sure we always print at least
// one `^`
write!(f, "^")?;
for _ in (span.start + 1)..(span.end.min(span.start + content.len() - column)) {
for _ in 1..highlight_len {
write!(f, "^")?;
}
writeln!(f)?;
Expand Down

0 comments on commit d41c62c

Please sign in to comment.