Skip to content

Commit

Permalink
Avoid double-extending past the end when showing source (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 26, 2022
1 parent d9355c9 commit 1912121
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/message.rs
Expand Up @@ -57,7 +57,14 @@ impl Source {
pub fn from_check(check: &Check, locator: &SourceCodeLocator) -> Self {
let source = locator.slice_source_code_range(&Range {
location: Location::new(check.location.row(), 0),
end_location: Location::new(check.end_location.row() + 1, 0),
// Checks can already extend one-past-the-end per Ropey's semantics. If they do, though,
// then they'll end at the start of a line. We need to avoid extending by yet another
// line past-the-end.
end_location: if check.end_location.column() == 0 {
check.end_location
} else {
Location::new(check.end_location.row() + 1, 0)
},
});
let num_chars_in_range = locator
.slice_source_code_range(&Range {
Expand Down

0 comments on commit 1912121

Please sign in to comment.