diff --git a/src/renderer/display_list.rs b/src/renderer/display_list.rs index e7784db9..f283e522 100644 --- a/src/renderer/display_list.rs +++ b/src/renderer/display_list.rs @@ -934,14 +934,15 @@ fn format_body( ) -> Vec> { let source_len = slice.source.chars().count(); if let Some(bigger) = slice.annotations.iter().find_map(|x| { - if source_len < x.range.1 { + // Allow highlighting one past the last character in the source. + if source_len + 1 < x.range.1 { Some(x.range) } else { None } }) { panic!( - "SourceAnnotation range `{:?}` is bigger than source length `{}`", + "SourceAnnotation range `{:?}` is beyond the end of buffer `{}`", bigger, source_len ) } @@ -1479,7 +1480,7 @@ mod tests { footer: vec![], slices: vec![snippet::Slice { annotations: vec![snippet::SourceAnnotation { - range: (0, source.len() + 1), + range: (0, source.len() + 2), label, annotation_type: snippet::AnnotationType::Error, }], diff --git a/tests/fixtures/no-color/one_past.toml b/tests/fixtures/no-color/one_past.toml new file mode 100644 index 00000000..62d1d42c --- /dev/null +++ b/tests/fixtures/no-color/one_past.toml @@ -0,0 +1,12 @@ +[snippet.title] +label = "expected `.`, `=`" +annotation_type = "Error" + +[[snippet.slices]] +source = "asdf" +line_start = 1 +origin = "Cargo.toml" +[[snippet.slices.annotations]] +label = "" +annotation_type = "Error" +range = [4, 5] diff --git a/tests/fixtures/no-color/one_past.txt b/tests/fixtures/no-color/one_past.txt new file mode 100644 index 00000000..7f255b88 --- /dev/null +++ b/tests/fixtures/no-color/one_past.txt @@ -0,0 +1,6 @@ +error: expected `.`, `=` + --> Cargo.toml:1:5 + | +1 | asdf + | ^ + |