Skip to content

Commit

Permalink
Dim solver comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Sep 15, 2024
1 parent e96ad1b commit 593e2ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub trait Style {
fn green(&self) -> String;
fn red(&self) -> String;
fn dimmed(&self) -> String;
fn comment(&self) -> String;
fn tooltip(&self, text: &str) -> String;
fn code(&self) -> String;
}
Expand Down Expand Up @@ -36,6 +37,14 @@ impl Style for &str {
<Self as Colorize>::dimmed(self).to_string()
}
}
fn comment(&self) -> String {
if cfg!(target_arch = "wasm32") {
format!("<span style=\"color: dimgray\">{self}</span>")
} else {
use colored::Colorize;
<Self as Colorize>::dimmed(self).to_string()
}
}
fn tooltip(&self, text: &str) -> String {
if cfg!(target_arch = "wasm32") {
format!("<span title=\"{text}\">{self}</span>")
Expand All @@ -62,6 +71,9 @@ impl Style for String {
fn dimmed(&self) -> String {
self.as_str().dimmed()
}
fn comment(&self) -> String {
self.as_str().comment()
}
fn tooltip(&self, text: &str) -> String {
self.as_str().tooltip(text)
}
Expand Down
13 changes: 6 additions & 7 deletions src/solver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::collections::VecDeque;
use std::fmt;
use std::fmt::Write;

use itertools::Itertools;
use printer::Style;

use crate::*;

Expand Down Expand Up @@ -97,7 +99,6 @@ pub fn trace_solver<'a>(
options: RuleOptions,
style: PredicateStyle,
) -> String {
use std::fmt::Write;
let arenas = &Arenas::default();
let ctx = TypingCtx { arenas, options };
let mut solver = TypingSolver::new(request);
Expand All @@ -106,7 +107,8 @@ pub fn trace_solver<'a>(
loop {
match solver.step(ctx) {
Ok(rule) => {
let _ = write!(&mut trace, "// Applying rule `{}`\n", rule.display(options));
let line = format!("// Applying rule `{}`", rule.display(options));
let _ = write!(&mut trace, "{}\n", line.comment());
let _ = write!(&mut trace, "{}\n", solver.display_state(style));
}
Err(e) => {
Expand All @@ -116,11 +118,8 @@ pub fn trace_solver<'a>(
let _ = write!(&mut trace, "{}\n", solver.display_final_state(ctx, style));
}
CantStep::NoApplicableRule(pred, err) => {
let _ = write!(
&mut trace,
"// Type error for `{}`: {err:?}\n",
pred.display(style)
);
let line = format!("// Type error for `{}`: {err:?}", pred.display(style));
let _ = write!(&mut trace, "{}\n", line.red());
}
}
break;
Expand Down

0 comments on commit 593e2ad

Please sign in to comment.