From 943631bbf3e7596bfd0aa4cbaabddb8829351bf1 Mon Sep 17 00:00:00 2001 From: Christopher Tam Date: Sun, 12 Jan 2020 12:57:14 -0800 Subject: [PATCH] Fix single char overflow display issue Fixes the error described in #16. Previously, when a single character of an annotation overflows to a new line, the DisplayList would incorrectly consider that character on the same line. This change fixes this and adds a new fixture test for this case. --- src/display_list/from_snippet.rs | 2 +- .../fixtures/no-color/multiline_annotation3.txt | 9 +++++++++ .../fixtures/no-color/multiline_annotation3.yaml | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/no-color/multiline_annotation3.txt create mode 100644 tests/fixtures/no-color/multiline_annotation3.yaml diff --git a/src/display_list/from_snippet.rs b/src/display_list/from_snippet.rs index a30bf40..2ba3b70 100644 --- a/src/display_list/from_snippet.rs +++ b/src/display_list/from_snippet.rs @@ -214,7 +214,7 @@ fn format_body(slice: &snippet::Slice, has_footer: bool) -> Vec { }; match annotation.range { (start, _) if start > line_end => true, - (start, end) if start >= line_start && end <= line_end + 1 => { + (start, end) if start >= line_start && end <= line_end => { let range = (start - line_start, end - line_start); body.insert( body_idx + 1, diff --git a/tests/fixtures/no-color/multiline_annotation3.txt b/tests/fixtures/no-color/multiline_annotation3.txt new file mode 100644 index 0000000..12e174c --- /dev/null +++ b/tests/fixtures/no-color/multiline_annotation3.txt @@ -0,0 +1,9 @@ +error[E####]: spacing error found + --> foo.txt:26:12 + | +26 | This is an exampl + | ____________^ +27 | | e of an edge case of an annotation overflowing + | |_^ this should not be on separate lines +28 | to exactly one character on next line. + | \ No newline at end of file diff --git a/tests/fixtures/no-color/multiline_annotation3.yaml b/tests/fixtures/no-color/multiline_annotation3.yaml new file mode 100644 index 0000000..65b50bf --- /dev/null +++ b/tests/fixtures/no-color/multiline_annotation3.yaml @@ -0,0 +1,16 @@ +slices: + - source: |- + This is an exampl + e of an edge case of an annotation overflowing + to exactly one character on next line. + line_start: 26 + origin: foo.txt + fold: false + annotations: + - label: this should not be on separate lines + annotation_type: Error + range: [11, 19] +title: + label: spacing error found + id: E#### + annotation_type: Error