Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
Fix panic computing indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 30, 2021
1 parent e6dabf1 commit 635eef7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn parse_snippet(span: &DiagnosticSpan) -> Option<Snippet> {
.chars()
.take_while(|&c| char::is_whitespace(c))
.count();
std::cmp::min(indent, line.highlight_start)
std::cmp::min(indent, line.highlight_start - 1)
})
.min()?;

Expand Down
60 changes: 60 additions & 0 deletions tests/edge-cases/indented_whitespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"message": "non-ASCII whitespace symbol '\\u{a0}' is not skipped",
"code": null,
"level": "warning",
"spans":
[
{
"file_name": "lib.rs",
"byte_start": 26,
"byte_end": 28,
"line_start": 2,
"line_end": 2,
"column_start": 1,
"column_end": 2,
"is_primary": false,
"text":
[
{
"text": " indented\";",
"highlight_start": 1,
"highlight_end": 2
}
],
"label": "non-ASCII whitespace symbol '\\u{a0}' is not skipped",
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
},
{
"file_name": "lib.rs",
"byte_start": 24,
"byte_end": 28,
"line_start": 1,
"line_end": 2,
"column_start": 25,
"column_end": 2,
"is_primary": true,
"text":
[
{
"text": "pub static FOO: &str = \"\\",
"highlight_start": 25,
"highlight_end": 26
},
{
"text": " indented\";",
"highlight_start": 1,
"highlight_end": 2
}
],
"label": null,
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
}
],
"children":
[],
"rendered": "warning: non-ASCII whitespace symbol '\\u{a0}' is not skipped\n --> lib.rs:1:25\n |\n1 | pub static FOO: &str = \"\\\n | _________________________^\n2 | |  indented\";\n | | ^ non-ASCII whitespace symbol '\\u{a0}' is not skipped\n | |_|\n | \n\n"
}
1 change: 1 addition & 0 deletions tests/edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ expect_empty_json_test! {out_of_bounds_test, "out_of_bounds.recorded.json"}
expect_empty_json_test! {utf8_identifiers_test, "utf8_idents.recorded.json"}
expect_empty_json_test! {empty, "empty.json"}
expect_empty_json_test! {no_main, "no_main.json"}
expect_empty_json_test! {indented_whitespace, "indented_whitespace.json"}

0 comments on commit 635eef7

Please sign in to comment.