Skip to content

Commit d41c62c

Browse files
authored
Merge pull request #701 from epage/cleanup
refactor(error): Clean up highlight code
2 parents 01d2f4a + 31457b3 commit d41c62c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

crates/toml_edit/src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ impl Display for TomlError {
9898
let col_num = column + 1;
9999
let gutter = line_num.to_string().len();
100100
let content = raw.split('\n').nth(line).expect("valid line number");
101+
let highlight_len = span.end - span.start;
102+
// Allow highlight to go one past the line
103+
let highlight_len = highlight_len.min(content.len().saturating_sub(column));
101104

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy