Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lura-eyre): add base for eyre #19

Merged
merged 13 commits into from
Nov 14, 2023
45 changes: 42 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ members = [
"lura-ide",
"lura-eval",
"lura-tt",
"lura-eyre",
"lura-cli",
"lura-typer",
"lura-ariadne",
@@ -31,6 +32,7 @@ thiserror = "1.0.40"
salsa-2022 = { git = "https://github.com/aripiprazole/salsa.git" }

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

tree-sitter = "~0.20.10"
2 changes: 1 addition & 1 deletion lura-ariadne/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@ version.workspace = true
lura-diagnostic = { version = "0.0.1", path = "../lura-diagnostic" }
lura-syntax = { version = "0.0.1", path = "../lura-syntax" }
lura-vfs = { version = "0.0.1", path = "../lura-vfs" }
lura-eyre = { version = "0.0.1", path = "../lura-eyre" }

salsa-2022 = { workspace = true }

tree-sitter = { workspace = true }
type-sitter-lib = { workspace = true }

dashmap = { workspace = true }
eyre = { workspace = true }
itertools.workspace = true
fxhash.workspace = true

8 changes: 4 additions & 4 deletions lura-ariadne/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashMap;

use ariadne::Fmt;
use eyre::Context;
use fxhash::{FxBuildHasher, FxHashSet};
use lura_diagnostic::Report;
use lura_eyre::Context;

type Span = (String, std::ops::Range<usize>);

@@ -44,12 +44,12 @@ impl AriadneReport {
self
}

pub fn write(self, output: &mut dyn std::io::Write) -> eyre::Result<()> {
pub fn write(self, output: &mut dyn std::io::Write) -> lura_eyre::Result<()> {
write!(output, "{}", self.dump()?)?;
Ok(())
}

pub fn dump(self) -> eyre::Result<String> {
pub fn dump(self) -> lura_eyre::Result<String> {
let mut output = Vec::new();
let errors = self.group_errors_by_file();

@@ -111,7 +111,7 @@ impl AriadneReport {
}

/// Prints the report to stderr.
pub fn eprint(self) -> eyre::Result<()> {
pub fn eprint(self) -> lura_eyre::Result<()> {
println!("{}", self.dump()?);
Ok(())
}
2 changes: 1 addition & 1 deletion lura-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ lura-vfs = { version = "0.0.1", path = "../lura-vfs" }
lura-js = { version = "0.0.1", path = "../lura-js" }
lura-ariadne = { version = "0.0.1", path = "../lura-ariadne" }
lura-driver = { version = "0.0.1", path = "../lura-driver" }
lura-eyre = { version = "0.0.1", path = "../lura-eyre" }

salsa-2022.workspace = true

@@ -27,7 +28,6 @@ type-sitter-lib.workspace = true
tree-sitter-lura = { version = "0.1.20", path = "../tree-sitter-lura" }

dashmap.workspace = true
eyre.workspace = true
im.workspace = true
fxhash.workspace = true
itertools.workspace = true
14 changes: 7 additions & 7 deletions lura-cli/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{collections::HashMap, fmt::Display, path::PathBuf};

use eyre::Context;
use fxhash::FxBuildHasher;
use itertools::Itertools;
use lura_diagnostic::{Diagnostics, Report};
use lura_driver::RootDb;
use lura_eyre::Context;
use lura_hir::{
package::{HasManifest, Package, Version},
source::HirSource,
@@ -35,7 +35,7 @@ pub struct Manifest<'db> {
impl<'db> Manifest<'db> {
pub const FILE_NAME: &'static str = "lura.toml";

pub fn load_in_folder(db: &'db RootDb, folder: PathBuf) -> eyre::Result<Self> {
pub fn load_in_folder(db: &'db RootDb, folder: PathBuf) -> lura_eyre::Result<Self> {
let manifest_path = folder.join(Self::FILE_NAME);
let manifest_content = std::fs::read_to_string(manifest_path.clone())
.wrap_err_with(|| format!("Unable to find manifest file for folder {folder:?}"))?;
@@ -51,7 +51,7 @@ impl<'db> Manifest<'db> {
})
}

pub fn read_file(&mut self, folder: PathBuf, path: PathBuf) -> eyre::Result<Source> {
pub fn read_file(&mut self, folder: PathBuf, path: PathBuf) -> lura_eyre::Result<Source> {
let path = folder.join(path);
let contents = std::fs::read_to_string(&path)
.wrap_err_with(|| format!("Failed to read {}", path.display()))?;
@@ -83,7 +83,7 @@ impl<'db> Manifest<'db> {
Ok(cst)
}

pub fn as_package(&mut self) -> eyre::Result<Package> {
pub fn as_package(&mut self) -> lura_eyre::Result<Package> {
let version = parse_version(&self.config.version)?;
let source = self.root_folder.join(&self.config.source);

@@ -99,7 +99,7 @@ impl<'db> Manifest<'db> {
))
}

pub fn register_packages(&mut self) -> eyre::Result<()> {
pub fn register_packages(&mut self) -> lura_eyre::Result<()> {
for dependency in self.config.dependencies.values() {
let folder = self.root_folder.join(&dependency.path).canonicalize()?;
let mut manifest = Manifest::load_in_folder(self.db, folder)?;
@@ -115,7 +115,7 @@ impl<'db> Manifest<'db> {
Ok(())
}

pub fn resolve_all_files(&mut self) -> eyre::Result<SourceMap> {
pub fn resolve_all_files(&mut self) -> lura_eyre::Result<SourceMap> {
// Clear diagnostics for new revision
self.diagnostics = Default::default();

@@ -156,7 +156,7 @@ fn source_folder_default() -> String {
"src".to_string()
}

fn parse_version(version: &str) -> eyre::Result<Version> {
fn parse_version(version: &str) -> lura_eyre::Result<Version> {
let mut split = version.split('.');
let major = split.next().unwrap();
let minor = split.next().unwrap();
4 changes: 2 additions & 2 deletions lura-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::*;
use eyre::eyre;
use itertools::Itertools;
use lura_driver::RootDb;
use lura_eyre::eyre;

use crate::build::Manifest;

@@ -27,7 +27,7 @@ pub enum Command {

pub mod build;

fn main() -> eyre::Result<()> {
fn main() -> lura_eyre::Result<()> {
let cli = Cli::parse();
let db = RootDb::default();

2 changes: 1 addition & 1 deletion lura-driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@ lura-typer = { version = "0.0.1", path = "../lura-typer" }
lura-ariadne = { version = "0.0.1", path = "../lura-ariadne" }
lura-eval = { version = "0.0.1", path = "../lura-eval" }
lura-tt = { version = "0.0.1", path = "../lura-tt" }
lura-eyre = { version = "0.0.1", path = "../lura-eyre" }

salsa-2022 = { workspace = true }

dashmap.workspace = true
eyre.workspace = true
itertools.workspace = true
fxhash.workspace = true

10 changes: 7 additions & 3 deletions lura-driver/src/suite.rs
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ pub fn run_test_suite(
file: &str,
source_code: &str,
expect: &str,
f: impl FnOnce(RootDb, SourceCode, Expect) -> eyre::Result<()>,
f: impl FnOnce(RootDb, SourceCode, Expect) -> lura_eyre::Result<()>,
) {
let _ = env_logger::builder()
.is_test(true)
@@ -84,7 +84,7 @@ pub fn run_test_suite(
}

/// Groups the errors by file.
pub fn push_ariadne_errors(output: Expect, outputs: &[Vec<Report>]) -> eyre::Result<()> {
pub fn push_ariadne_errors(output: Expect, outputs: &[Vec<Report>]) -> lura_eyre::Result<()> {
let mut ariadne = AriadneReport::default();
for output in outputs {
ariadne = ariadne.expand(output.clone());
@@ -94,7 +94,11 @@ pub fn push_ariadne_errors(output: Expect, outputs: &[Vec<Report>]) -> eyre::Res
}

/// Prints a debug report of the given `type_table`.
pub fn debug_type_table(expect: Expect, db: &RootDb, type_table: TypeTable) -> eyre::Result<()> {
pub fn debug_type_table(
expect: Expect,
db: &RootDb,
type_table: TypeTable,
) -> lura_eyre::Result<()> {
let mut output = Vec::new();
let expressions = type_table.expressions(db);

21 changes: 21 additions & 0 deletions lura-eyre/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "lura-eyre"
edition.workspace = true
authors.workspace = true
documentation.workspace = true
version.workspace = true

[dependencies]
lura-diagnostic = { version = "0.0.1", path = "../lura-diagnostic" }
lura-hir = { version = "0.0.1", path = "../lura-hir" }
lura-syntax = { version = "0.0.1", path = "../lura-syntax" }
lura-vfs = { version = "0.0.1", path = "../lura-vfs" }

salsa-2022.workspace = true

thiserror.workspace = true

eyre.workspace = true
miette.workspace = true

im.workspace = true
Loading