From 491ce7c0ce1f04c9b6fc09c250f188c1ec77df53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 21 Sep 2021 17:50:42 -0700 Subject: [PATCH] fix(graphical): fix coalescing adjacent things when they cross boundaries --- src/handlers/graphical.rs | 37 ++++++++++++++++++++++--------------- src/source_impls.rs | 1 - 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index b6cd42e5..3edc35f3 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -242,21 +242,28 @@ impl GraphicalReportHandler { let right_end = right.offset() + right.len(); if left_conts.line() + left_conts.line_count() >= right_conts.line() { // The snippets will overlap, so we create one Big Chunky Boi - Ok(( - LabeledSpan::new( - left.label().map(String::from), - left.offset(), - if right_end >= left_end { - // Right end goes past left end - right_end - left.offset() - } else { - // right is contained inside left - left.len() - }, - ), - // We'll throw this away later - left_conts, - )) + let new_span = LabeledSpan::new( + left.label().map(String::from), + left.offset(), + if right_end >= left_end { + // Right end goes past left end + right_end - left.offset() + } else { + // right is contained inside left + left.len() + }, + ); + if source + .read_span(new_span.inner(), self.context_lines, self.context_lines) + .is_ok() + { + Ok(( + new_span, // We'll throw this away later + left_conts, + )) + } else { + Err(((left, left_conts), (right, right_conts))) + } } else { Err(((left, left_conts), (right, right_conts))) } diff --git a/src/source_impls.rs b/src/source_impls.rs index 77c41144..bedabc76 100644 --- a/src/source_impls.rs +++ b/src/source_impls.rs @@ -92,7 +92,6 @@ fn context_info<'a>( line_count, )) } else { - // eprintln!("Out of bounds :("); Err(MietteError::OutOfBounds) } }