mirror of
https://github.com/typst/typst
synced 2025-08-15 23:48:32 +08:00
Show warnings from eval
This commit is contained in:
parent
1f1c133878
commit
6e8ce9ebd5
@ -105,7 +105,7 @@ pub fn eval_string(
|
||||
span: Span,
|
||||
mode: EvalMode,
|
||||
scope: Scope,
|
||||
) -> SourceResult<Value> {
|
||||
) -> SourceResult<(Value, Sink)> {
|
||||
let mut root = match mode {
|
||||
EvalMode::Code => parse_code(string),
|
||||
EvalMode::Markup => parse(string),
|
||||
@ -158,7 +158,7 @@ pub fn eval_string(
|
||||
bail!(flow.forbidden());
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
Ok((output, sink))
|
||||
}
|
||||
|
||||
/// Evaluate an expression.
|
||||
|
@ -297,5 +297,18 @@ pub fn eval(
|
||||
for (key, value) in dict {
|
||||
scope.bind(key.into(), Binding::new(value, span));
|
||||
}
|
||||
(engine.routines.eval_string)(engine.routines, engine.world, &text, span, mode, scope)
|
||||
let (result, sink) = (engine.routines.eval_string)(
|
||||
engine.routines,
|
||||
engine.world,
|
||||
&text,
|
||||
span,
|
||||
mode,
|
||||
scope,
|
||||
)?;
|
||||
|
||||
for warning in sink.warnings() {
|
||||
engine.sink.warn(warning);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
@ -1004,7 +1004,8 @@ impl ElemRenderer<'_> {
|
||||
EvalMode::Math,
|
||||
Scope::new(),
|
||||
)
|
||||
.map(Value::display)
|
||||
// TODO: propagate warnings
|
||||
.map(|(result, _sink)| Value::display(result))
|
||||
.unwrap_or_else(|_| TextElem::packed(math).spanned(self.span))
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ routines! {
|
||||
span: Span,
|
||||
mode: EvalMode,
|
||||
scope: Scope,
|
||||
) -> SourceResult<Value>
|
||||
) -> SourceResult<(Value, Sink)>
|
||||
|
||||
/// Call the closure in the context with the arguments.
|
||||
fn eval_closure(
|
||||
|
@ -52,3 +52,9 @@ _Tiger!_
|
||||
#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)$
|
||||
|
||||
--- 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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user