Skip to content

Commit af66255

Browse files
committed
update formatting
1 parent a801cd5 commit af66255

File tree

1 file changed

+23
-24
lines changed
  • crates/compilers/src/resolver

1 file changed

+23
-24
lines changed

crates/compilers/src/resolver/mod.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use std::{
6464
io,
6565
path::{Path, PathBuf},
6666
};
67+
use yansi::{Color, Paint};
6768

6869
pub mod parse;
6970
mod tree;
@@ -547,21 +548,25 @@ impl<L: Language, D: ParsedSource<Language = L>> Graph<D> {
547548
fn format_imports_list<W: std::fmt::Write>(
548549
&self,
549550
idx: usize,
550-
imports: impl IntoIterator<Item = usize>,
551+
incompatible: HashSet<usize>,
551552
f: &mut W,
552553
) -> std::result::Result<(), std::fmt::Error> {
553-
let node = self.node(idx);
554-
write!(f, "{} ", utils::source_name(&node.path, &self.root).display())?;
555-
if let Some(req) = node.data.version_req() {
556-
write!(f, "{req}")?;
557-
}
558-
write!(f, " imports:")?;
559-
for dep in imports {
560-
let dep = self.node(dep);
561-
write!(f, "\n {} ", utils::source_name(&dep.path, &self.root).display())?;
562-
if let Some(req) = dep.data.version_req() {
563-
write!(f, "{req}")?;
554+
let format_node = |idx, f: &mut W| {
555+
let node = self.node(idx);
556+
let color = if incompatible.contains(&idx) { Color::Red } else { Color::White };
557+
558+
let mut line = utils::source_name(&node.path, &self.root).display().to_string();
559+
if let Some(req) = node.data.version_req() {
560+
line.push_str(&format!(" {req}"));
564561
}
562+
563+
write!(f, "{} ", line.paint(color))
564+
};
565+
format_node(idx, f)?;
566+
write!(f, " imports:")?;
567+
for dep in self.node_ids(idx).skip(1) {
568+
write!(f, "\n ")?;
569+
format_node(dep, f)?;
565570
}
566571

567572
Ok(())
@@ -617,23 +622,17 @@ impl<L: Language, D: ParsedSource<Language = L>> Graph<D> {
617622
// iterate over all the nodes once again and find the one incompatible
618623
for node in &nodes {
619624
if self.node(*node).check_available_version(&all_versions, offline).is_err() {
620-
let mut msg = String::new();
621-
622-
// avoid formatting root node as import
623-
let imports = if *node == idx {
624-
vec![failed_node_idx]
625-
} else {
626-
vec![*node, failed_node_idx]
627-
};
625+
let mut msg = "Found incompatible versions:\n".white().to_string();
628626

629-
self.format_imports_list(idx, imports, &mut msg).unwrap();
630-
return Err(format!("Found incompatible versions:\n{msg}"));
627+
self.format_imports_list(idx, [*node, failed_node_idx].into(), &mut msg)
628+
.unwrap();
629+
return Err(msg);
631630
}
632631
}
633632
}
634633

635-
let mut msg = String::new();
636-
self.format_imports_list(idx, nodes[1..].to_vec(), &mut msg).unwrap();
634+
let mut msg = "Found incompatible versions:\n".white().to_string();
635+
self.format_imports_list(idx, nodes.into_iter().collect(), &mut msg).unwrap();
637636
Err(format!("Found incompatible versions:\n{msg}"))
638637
}
639638

0 commit comments

Comments
 (0)