Skip to content

Commit

Permalink
feat(sol-driver): use miette instead of ariadne
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed May 28, 2024
1 parent c7066cd commit 67d34c3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 239 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ members = [
"sol-eyre",
"sol-cli",
"sol-typer",
"sol-ariadne",
"sol-docs-backend",
"tree-sitter-sol",
]
Expand All @@ -32,6 +31,7 @@ salsa-2022 = { git = "https://github.com/aripiprazole/salsa.git" }

eyre = "0.6.8"
miette = "5.10.0"
bupropion = "0.0.18"
paste = "1.0.14"

tree-sitter = "~0.20.10"
Expand Down Expand Up @@ -75,7 +75,6 @@ toml = "0.7.6"

clap = { version = "4.3.19", features = ["derive"] }

sol-ariadne = { version = "0.0.1", path = "./sol-ariadne" }
sol-cli = { version = "0.0.1", path = "./sol-cli" }
sol-diagnostic = { version = "0.0.1", path = "./sol-diagnostic" }
sol-docs-backend = { version = "0.0.1", path = "./sol-docs-backend" }
Expand Down
19 changes: 0 additions & 19 deletions sol-ariadne/Cargo.toml

This file was deleted.

134 changes: 0 additions & 134 deletions sol-ariadne/src/lib.rs

This file was deleted.

4 changes: 2 additions & 2 deletions sol-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ sol-hir-lowering.workspace = true
sol-syntax.workspace = true
sol-vfs.workspace = true
sol-typer.workspace = true
sol-ariadne.workspace = true
sol-thir.workspace = true
sol-thir-lowering.workspace = true
sol-eyre.workspace = true
salsa-2022.workspace = true
dashmap.workspace = true
itertools.workspace = true
fxhash.workspace = true
ariadne.workspace = true
miette.workspace = true
bupropion.workspace = true
similar.workspace = true
strip-ansi-escapes.workspace = true
env_logger.workspace = true
Expand Down
90 changes: 8 additions & 82 deletions sol-driver/src/suite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, io::Write};
use std::{collections::HashMap, io::Write, sync::Arc};

use ariadne::{Color, Fmt};
use itertools::Itertools;
Expand Down Expand Up @@ -122,13 +122,11 @@ pub fn run_test_suite(
}

/// Groups the errors by file.
pub fn push_ariadne_errors(output: Expect, outputs: &[Vec<Report>]) -> sol_eyre::Result<()> {
let mut ariadne = AriadneReport::default();
for output in outputs {
ariadne = ariadne.expand(output.clone());
}
ariadne.write(output)?;
Ok(())
pub fn push_ariadne_errors(
output: Expect,
outputs: &[Vec<Arc<miette::Report>>],
) -> sol_eyre::Result<()> {
todo!();
}

/// Prints a debug report of the given `type_table`.
Expand All @@ -137,81 +135,9 @@ pub fn debug_type_table(
db: &RootDb,
type_table: TypeTable,
) -> sol_eyre::Result<()> {
let mut output = Vec::new();
let expressions = type_table.expressions(db);

let mut parameters = HashMap::new();
for (parameter, type_rep) in type_table.parameters(db) {
let location = parameter.location(db);
let file_name = location.file_name().to_string();

parameters
.entry(file_name)
.or_insert_with(Vec::new)
.push((parameter, type_rep));
for (name, (term, type_rep)) in type_table {
writeln!(expect, "{name} : {type_rep} = {term}")?;
}

let file_type_tables = expressions.iter().group_by(|(expression, _)| {
let location = expression.location(db);
let file_name = location.file_name().to_string();
let contents = location.source().to_string();
(file_name, contents)
});

for ((file, contents), type_table) in file_type_tables.into_iter() {
// Get all the parameters contained in the current file,
// to be able to print them in the report.
let parameters = parameters.get(&file).cloned().unwrap_or_default();

type Span = (String, std::ops::Range<usize>);
ariadne::Report::<Span>::build(ariadne::ReportKind::Advice, file.clone(), 0)
.with_message("type table information")
.with_note("These are generated types, they are not part of the source code.")
.with_config(
ariadne::Config::default()
.with_cross_gap(true)
.with_char_set(ariadne::CharSet::Unicode)
.with_label_attach(ariadne::LabelAttach::Start),
)
.with_labels(parameters.into_iter().map(|(parameter, type_rep)| {
let location = parameter.location(db);
let range = location.start().0..location.end().0;

// TODO: use a better representation for types
let type_rep = type_rep.to_string();

// Build pattern string
let pattern = parameter.binding(db);
let pattern = pattern.formatter();
let pattern = format!("{:?}", pattern.debug_all(db));

ariadne::Label::new((file.clone(), range))
.with_color(Color::Yellow)
.with_message(format!(
"parameter {} has type {}",
pattern.fg(Color::Yellow),
type_rep.fg(Color::Red)
))
}))
.with_labels(type_table.into_iter().map(|(expr, type_rep)| {
let location = expr.location(db);
let range = location.start().0..location.end().0;

// TODO: use a better representation for types
let type_rep = type_rep.to_string();

ariadne::Label::new((file.clone(), range))
.with_color(Color::Green)
.with_message(format!("has type {}", type_rep.fg(Color::Green)))
}))
.finish()
.write(
(file.clone(), ariadne::Source::from(&contents)),
&mut output,
)
.unwrap();

write!(expect, "{}", String::from_utf8_lossy(&output))?;
}
Ok(())
}

0 comments on commit 67d34c3

Please sign in to comment.