From 612967d381f05e2e5a27e39a7a66942c7ec396f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 22 Sep 2021 14:01:22 -0700 Subject: [PATCH] fix(deps): remove dep on itertools --- Cargo.toml | 1 - src/handlers/graphical.rs | 22 +++++++++++++--------- src/handlers/narratable.rs | 23 +++++++++++++---------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2cb6ac43..05cd18bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ exclude = ["images/", "tests/", "miette-derive/"] thiserror = "1.0.26" miette-derive = { path = "miette-derive", version = "=3.0.0-beta.0"} once_cell = "1.8.0" -itertools = "0.10.1" owo-colors = { version = "2.0.0", optional = true } atty = { version = "0.2.14", optional = true } diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index ae12a4d0..06bf26d3 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -1,6 +1,5 @@ use std::fmt::{self, Write}; -use itertools::Itertools; use owo_colors::{OwoColorize, Style}; use crate::chain::Chain; @@ -251,8 +250,12 @@ impl GraphicalReportHandler { }) .collect::>>, MietteError>>() .map_err(|_| fmt::Error)?; - let contexts = labels.iter().cloned().zip(contents.iter()).coalesce( - |(left, left_conts), (right, right_conts)| { + let mut contexts = Vec::new(); + for (right, right_conts) in labels.iter().cloned().zip(contents.iter()) { + if contexts.is_empty() { + contexts.push((right, right_conts)); + } else { + let (left, left_conts) = contexts.last().unwrap().clone(); let left_end = left.offset() + left.len(); let right_end = right.offset() + right.len(); if left_conts.line() + left_conts.line_count() >= right_conts.line() { @@ -276,18 +279,19 @@ impl GraphicalReportHandler { ) .is_ok() { - Ok(( + contexts.pop(); + contexts.push(( new_span, // We'll throw this away later left_conts, - )) + )); } else { - Err(((left, left_conts), (right, right_conts))) + contexts.push((right, right_conts)); } } else { - Err(((left, left_conts), (right, right_conts))) + contexts.push((right, right_conts)); } - }, - ); + } + } for (ctx, _) in contexts { self.render_context(f, source, &ctx, &labels[..])?; } diff --git a/src/handlers/narratable.rs b/src/handlers/narratable.rs index ba400788..c38ee224 100644 --- a/src/handlers/narratable.rs +++ b/src/handlers/narratable.rs @@ -1,7 +1,5 @@ use std::fmt; -use itertools::Itertools; - use crate::chain::Chain; use crate::protocol::{Diagnostic, Severity}; use crate::{LabeledSpan, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents}; @@ -114,8 +112,12 @@ impl NarratableReportHandler { }) .collect::>>, MietteError>>() .map_err(|_| fmt::Error)?; - let contexts = labels.iter().cloned().zip(contents.iter()).coalesce( - |(left, left_conts), (right, right_conts)| { + let mut contexts = Vec::new(); + for (right, right_conts) in labels.iter().cloned().zip(contents.iter()) { + if contexts.is_empty() { + contexts.push((right, right_conts)); + } else { + let (left, left_conts) = contexts.last().unwrap().clone(); let left_end = left.offset() + left.len(); let right_end = right.offset() + right.len(); if left_conts.line() + left_conts.line_count() >= right_conts.line() { @@ -139,18 +141,19 @@ impl NarratableReportHandler { ) .is_ok() { - Ok(( + contexts.pop(); + contexts.push(( new_span, // We'll throw this away later left_conts, - )) + )); } else { - Err(((left, left_conts), (right, right_conts))) + contexts.push((right, right_conts)); } } else { - Err(((left, left_conts), (right, right_conts))) + contexts.push((right, right_conts)); } - }, - ); + } + } for (ctx, _) in contexts { self.render_context(f, source, &ctx, &labels[..])?; }