Revert to passing around SpanContents

This commit is contained in:
Lucas Holten 2024-01-11 10:11:42 +01:00
parent 997a3ea782
commit 0bf3daebc2
1 changed files with 12 additions and 13 deletions

View File

@ -377,11 +377,13 @@ impl GraphicalReportHandler {
diagnostic: &(dyn Diagnostic), diagnostic: &(dyn Diagnostic),
opt_source: Option<&dyn SourceCode>, opt_source: Option<&dyn SourceCode>,
) -> fmt::Result { ) -> fmt::Result {
let Some(source) = opt_source else { let source = match opt_source {
return Ok(()); Some(source) => source,
None => return Ok(()),
}; };
let Some(labels) = diagnostic.labels() else { let labels = match diagnostic.labels() {
return Ok(()); Some(labels) => labels,
None => return Ok(()),
}; };
let mut labels = labels.collect::<Vec<_>>(); let mut labels = labels.collect::<Vec<_>>();
@ -394,12 +396,12 @@ impl GraphicalReportHandler {
.map_err(|_| fmt::Error)?; .map_err(|_| fmt::Error)?;
if contexts.is_empty() { if contexts.is_empty() {
contexts.push((right, (right_conts.line(), right_conts.line_count()))); contexts.push((right, right_conts));
continue; continue;
} }
let (left, (left_line, left_line_count)) = contexts.last().unwrap().clone(); let (left, left_conts) = contexts.last().unwrap();
if left_line + left_line_count >= right_conts.line() { if left_conts.line() + left_conts.line_count() >= right_conts.line() {
// The snippets will overlap, so we create one Big Chunky Boi // The snippets will overlap, so we create one Big Chunky Boi
let left_end = left.offset() + left.len(); let left_end = left.offset() + left.len();
let right_end = right.offset() + right.len(); let right_end = right.offset() + right.len();
@ -419,16 +421,13 @@ impl GraphicalReportHandler {
source.read_span(new_span.inner(), self.context_lines, self.context_lines) source.read_span(new_span.inner(), self.context_lines, self.context_lines)
{ {
contexts.pop(); contexts.pop();
contexts.push(( // We'll throw the contents away later
// We'll throw this away later contexts.push((new_span, new_conts));
new_span,
(new_conts.line(), new_conts.line_count()),
));
continue; continue;
} }
} }
contexts.push((right, (right_conts.line(), right_conts.line_count()))); contexts.push((right, right_conts));
} }
for (ctx, _) in contexts { for (ctx, _) in contexts {
self.render_context(f, source, &ctx, &labels[..])?; self.render_context(f, source, &ctx, &labels[..])?;