Show warnings from eval (#6100)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
+merlan #flirora 2025-04-07 14:42:29 -04:00 committed by GitHub
parent bd2e76e11d
commit 14a0565d95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 5 deletions

View File

@ -2,6 +2,7 @@ use comemo::Track;
use ecow::{eco_format, EcoString}; use ecow::{eco_format, EcoString};
use serde::Serialize; use serde::Serialize;
use typst::diag::{bail, HintedStrResult, StrResult, Warned}; use typst::diag::{bail, HintedStrResult, StrResult, Warned};
use typst::engine::Sink;
use typst::foundations::{Content, IntoValue, LocatableSelector, Scope}; use typst::foundations::{Content, IntoValue, LocatableSelector, Scope};
use typst::layout::PagedDocument; use typst::layout::PagedDocument;
use typst::syntax::Span; use typst::syntax::Span;
@ -58,6 +59,8 @@ fn retrieve(
let selector = eval_string( let selector = eval_string(
&typst::ROUTINES, &typst::ROUTINES,
world.track(), world.track(),
// TODO: propagate warnings
Sink::new().track_mut(),
&command.selector, &command.selector,
Span::detached(), Span::detached(),
EvalMode::Code, EvalMode::Code,

View File

@ -101,6 +101,7 @@ pub fn eval(
pub fn eval_string( pub fn eval_string(
routines: &Routines, routines: &Routines,
world: Tracked<dyn World + '_>, world: Tracked<dyn World + '_>,
sink: TrackedMut<Sink>,
string: &str, string: &str,
span: Span, span: Span,
mode: EvalMode, mode: EvalMode,
@ -121,7 +122,6 @@ pub fn eval_string(
} }
// Prepare the engine. // Prepare the engine.
let mut sink = Sink::new();
let introspector = Introspector::default(); let introspector = Introspector::default();
let traced = Traced::default(); let traced = Traced::default();
let engine = Engine { let engine = Engine {
@ -129,7 +129,7 @@ pub fn eval_string(
world, world,
introspector: introspector.track(), introspector: introspector.track(),
traced: traced.track(), traced: traced.track(),
sink: sink.track_mut(), sink,
route: Route::default(), route: Route::default(),
}; };

View File

@ -77,6 +77,7 @@ pub use {
indexmap::IndexMap, indexmap::IndexMap,
}; };
use comemo::TrackedMut;
use ecow::EcoString; use ecow::EcoString;
use typst_syntax::Spanned; use typst_syntax::Spanned;
@ -297,5 +298,14 @@ pub fn eval(
for (key, value) in dict { for (key, value) in dict {
scope.bind(key.into(), Binding::new(value, span)); scope.bind(key.into(), Binding::new(value, span));
} }
(engine.routines.eval_string)(engine.routines, engine.world, &text, span, mode, scope)
(engine.routines.eval_string)(
engine.routines,
engine.world,
TrackedMut::reborrow_mut(&mut engine.sink),
&text,
span,
mode,
scope,
)
} }

View File

@ -6,7 +6,7 @@ use std::num::NonZeroUsize;
use std::path::Path; use std::path::Path;
use std::sync::{Arc, LazyLock}; use std::sync::{Arc, LazyLock};
use comemo::Tracked; use comemo::{Track, Tracked};
use ecow::{eco_format, EcoString, EcoVec}; use ecow::{eco_format, EcoString, EcoVec};
use hayagriva::archive::ArchivedStyle; use hayagriva::archive::ArchivedStyle;
use hayagriva::io::BibLaTeXError; use hayagriva::io::BibLaTeXError;
@ -20,7 +20,7 @@ use typst_syntax::{Span, Spanned};
use typst_utils::{Get, ManuallyHash, NonZeroExt, PicoStr}; use typst_utils::{Get, ManuallyHash, NonZeroExt, PicoStr};
use crate::diag::{bail, error, At, FileError, HintedStrResult, SourceResult, StrResult}; use crate::diag::{bail, error, At, FileError, HintedStrResult, SourceResult, StrResult};
use crate::engine::Engine; use crate::engine::{Engine, Sink};
use crate::foundations::{ use crate::foundations::{
elem, Bytes, CastInfo, Content, Derived, FromValue, IntoValue, Label, NativeElement, elem, Bytes, CastInfo, Content, Derived, FromValue, IntoValue, Label, NativeElement,
OneOrMultiple, Packed, Reflect, Scope, Show, ShowSet, Smart, StyleChain, Styles, OneOrMultiple, Packed, Reflect, Scope, Show, ShowSet, Smart, StyleChain, Styles,
@ -999,6 +999,8 @@ impl ElemRenderer<'_> {
(self.routines.eval_string)( (self.routines.eval_string)(
self.routines, self.routines,
self.world, self.world,
// TODO: propagate warnings
Sink::new().track_mut(),
math, math,
self.span, self.span,
EvalMode::Math, EvalMode::Math,

View File

@ -55,6 +55,7 @@ routines! {
fn eval_string( fn eval_string(
routines: &Routines, routines: &Routines,
world: Tracked<dyn World + '_>, world: Tracked<dyn World + '_>,
sink: TrackedMut<Sink>,
string: &str, string: &str,
span: Span, span: Span,
mode: EvalMode, mode: EvalMode,

View File

@ -52,3 +52,9 @@ _Tiger!_
#eval(mode: "math", "f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)") #eval(mode: "math", "f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)")
$f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)$ $f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)$
--- issue-6067-eval-warnings ---
// Test that eval shows warnings from the executed code.
// Warning: 7-11 no text within stars
// Hint: 7-11 using multiple consecutive stars (e.g. **) has no additional effect
#eval("**", mode: "markup")