diff options
| author | tingerrr <me@tinger.dev> | 2023-10-19 12:04:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-19 12:04:05 +0200 |
| commit | 76d4c39ce4730c8d8f00e7e73c020c9309e03756 (patch) | |
| tree | bbb1614994c0cdfd1cb643be68cacef2a8c5bd42 | |
| parent | e800b08f1a2c82a8da07eedff4533ce7eac9d922 (diff) | |
Only print unique diagnostics (#2385)
| -rw-r--r-- | crates/typst/src/lib.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/crates/typst/src/lib.rs b/crates/typst/src/lib.rs index 24a6311e..7303eca8 100644 --- a/crates/typst/src/lib.rs +++ b/crates/typst/src/lib.rs @@ -52,6 +52,7 @@ pub mod model; #[doc(inline)] pub use typst_syntax as syntax; +use std::collections::HashSet; use std::ops::Range; use comemo::{Prehashed, Track, TrackedMut}; @@ -79,16 +80,27 @@ pub fn compile(world: &dyn World, tracer: &mut Tracer) -> SourceResult<Document> let world = world.track(); let mut tracer = tracer.track_mut(); - // Evaluate the source file into a module. + // Try to evaluate the source file into a module. let module = eval::eval( world, route.track(), TrackedMut::reborrow_mut(&mut tracer), &world.main(), - )?; - - // Typeset it. - model::typeset(world, tracer, &module.content()) + ); + + // Try to typeset it. + let res = module.and_then(|module| model::typeset(world, tracer, &module.content())); + + // Deduplicate errors. + res.map_err(|err| { + let mut unique = HashSet::new(); + err.into_iter() + .filter(|diagnostic| { + let hash = util::hash128(&(&diagnostic.span, &diagnostic.message)); + unique.insert(hash) + }) + .collect() + }) } /// The environment in which typesetting occurs. |
