Skip to content

Commit

Permalink
fix(deps): remove dep on itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Sep 22, 2021
1 parent fbf6664 commit 612967d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
22 changes: 13 additions & 9 deletions src/handlers/graphical.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::{self, Write};

use itertools::Itertools;
use owo_colors::{OwoColorize, Style};

use crate::chain::Chain;
Expand Down Expand Up @@ -251,8 +250,12 @@ impl GraphicalReportHandler {
})
.collect::<Result<Vec<Box<dyn SpanContents<'_>>>, 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() {
Expand All @@ -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[..])?;
}
Expand Down
23 changes: 13 additions & 10 deletions src/handlers/narratable.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -114,8 +112,12 @@ impl NarratableReportHandler {
})
.collect::<Result<Vec<Box<dyn SpanContents<'_>>>, 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() {
Expand All @@ -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[..])?;
}
Expand Down

0 comments on commit 612967d

Please sign in to comment.