diff --git a/crates/typst-eval/src/call.rs b/crates/typst-eval/src/call.rs index f48734cbc..513d1dd2c 100644 --- a/crates/typst-eval/src/call.rs +++ b/crates/typst-eval/src/call.rs @@ -391,7 +391,9 @@ fn wrap_args_in_math( } Ok(Value::Content( callee.display().spanned(callee_span) - + LrElem::new(TextElem::packed('(') + body + TextElem::packed(')')).pack(), + + LrElem::new(TextElem::packed('(') + body + TextElem::packed(')')) + .pack() + .spanned(args.span), )) } diff --git a/crates/typst-eval/src/code.rs b/crates/typst-eval/src/code.rs index ba5256c1f..34373fd4a 100644 --- a/crates/typst-eval/src/code.rs +++ b/crates/typst-eval/src/code.rs @@ -359,7 +359,7 @@ impl Eval for ast::Contextual<'_> { }; let func = Func::from(closure).spanned(body.span()); - Ok(ContextElem::new(func).pack()) + Ok(ContextElem::new(func).pack().spanned(body.span())) } } diff --git a/crates/typst-eval/src/lib.rs b/crates/typst-eval/src/lib.rs index 69c20e8cc..5eae7c1df 100644 --- a/crates/typst-eval/src/lib.rs +++ b/crates/typst-eval/src/lib.rs @@ -148,7 +148,8 @@ pub fn eval_string( EvalMode::Math => Value::Content( EquationElem::new(root.cast::().unwrap().eval(&mut vm)?) .with_block(false) - .pack(), + .pack() + .spanned(span), ), }; diff --git a/crates/typst-library/src/foundations/args.rs b/crates/typst-library/src/foundations/args.rs index ee282a874..a60e6d7f2 100644 --- a/crates/typst-library/src/foundations/args.rs +++ b/crates/typst-library/src/foundations/args.rs @@ -187,7 +187,7 @@ impl Args { self.items.retain(|item| { if item.name.is_some() { return true; - }; + } let span = item.value.span; let spanned = Spanned::new(std::mem::take(&mut item.value.v), span); match T::from_value(spanned).at(span) { diff --git a/crates/typst-library/src/foundations/content.rs b/crates/typst-library/src/foundations/content.rs index 69103e080..bfafbc486 100644 --- a/crates/typst-library/src/foundations/content.rs +++ b/crates/typst-library/src/foundations/content.rs @@ -481,17 +481,20 @@ impl Content { impl Content { /// Strongly emphasize this content. pub fn strong(self) -> Self { - StrongElem::new(self).pack() + let span = self.span(); + StrongElem::new(self).pack().spanned(span) } /// Emphasize this content. pub fn emph(self) -> Self { - EmphElem::new(self).pack() + let span = self.span(); + EmphElem::new(self).pack().spanned(span) } /// Underline this content. pub fn underlined(self) -> Self { - UnderlineElem::new(self).pack() + let span = self.span(); + UnderlineElem::new(self).pack().spanned(span) } /// Link the content somewhere. @@ -506,17 +509,24 @@ impl Content { /// Pad this content at the sides. pub fn padded(self, padding: Sides>) -> Self { + let span = self.span(); PadElem::new(self) .with_left(padding.left) .with_top(padding.top) .with_right(padding.right) .with_bottom(padding.bottom) .pack() + .spanned(span) } /// Transform this content's contents without affecting layout. pub fn moved(self, delta: Axes>) -> Self { - MoveElem::new(self).with_dx(delta.x).with_dy(delta.y).pack() + let span = self.span(); + MoveElem::new(self) + .with_dx(delta.x) + .with_dy(delta.y) + .pack() + .spanned(span) } } diff --git a/crates/typst-library/src/foundations/func.rs b/crates/typst-library/src/foundations/func.rs index e34f48a17..40c826df9 100644 --- a/crates/typst-library/src/foundations/func.rs +++ b/crates/typst-library/src/foundations/func.rs @@ -443,7 +443,7 @@ pub trait NativeFunc { Func::from(Self::data()) } - /// Get the function data for the native Rust type. + /// Get the function data for the native Rust function. fn data() -> &'static NativeFuncData; } @@ -462,6 +462,7 @@ pub struct NativeFuncData { pub keywords: &'static [&'static str], /// Whether this function makes use of context. pub contextual: bool, + /// Definitions in the scope of the function. pub scope: LazyLock, /// A list of parameter information for each parameter. pub params: LazyLock>, diff --git a/crates/typst-library/src/foundations/ty.rs b/crates/typst-library/src/foundations/ty.rs index 680c4f6a1..8b20e2c62 100644 --- a/crates/typst-library/src/foundations/ty.rs +++ b/crates/typst-library/src/foundations/ty.rs @@ -199,6 +199,7 @@ pub trait NativeType { pub struct NativeTypeData { /// The type's normal name (e.g. `str`), as exposed to Typst. pub name: &'static str, + /// The type's long name (e.g. `string`), for error messages. pub long_name: &'static str, /// The function's title case name (e.g. `String`). pub title: &'static str, @@ -208,6 +209,7 @@ pub struct NativeTypeData { pub keywords: &'static [&'static str], /// The constructor for this type. pub constructor: LazyLock>, + /// Definitions in the scope of the type. pub scope: LazyLock, } diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs index 85257c2c7..0be1a9d0a 100644 --- a/crates/typst-library/src/model/outline.rs +++ b/crates/typst-library/src/model/outline.rs @@ -248,7 +248,7 @@ impl Show for Packed { )?; // Add the overridable outline entry, followed by a line break. - seq.push(entry.pack()); + seq.push(entry.pack().spanned(self.span())); seq.push(LinebreakElem::shared().clone()); ancestors.push(elem); @@ -332,15 +332,18 @@ impl OutlineIndent { } if !ancestors.is_empty() { - seq.push(HideElem::new(hidden).pack()); - seq.push(SpaceElem::shared().clone()); + seq.push(HideElem::new(hidden).pack().spanned(span)); + seq.push(SpaceElem::shared().clone().spanned(span)); } } // Length => indent with some fixed spacing per level Some(Smart::Custom(OutlineIndent::Rel(length))) => { seq.push( - HElem::new(Spacing::Rel(*length)).pack().repeat(ancestors.len()), + HElem::new(Spacing::Rel(*length)) + .pack() + .spanned(span) + .repeat(ancestors.len()), ); } @@ -535,7 +538,7 @@ impl Show for Packed { ); seq.push(SpaceElem::shared().clone()); } else { - seq.push(HElem::new(Fr::one().into()).pack()); + seq.push(HElem::new(Fr::one().into()).pack().spanned(self.span())); } // Add the page number. diff --git a/crates/typst-library/src/model/terms.rs b/crates/typst-library/src/model/terms.rs index 036a03e27..bbcb63fc2 100644 --- a/crates/typst-library/src/model/terms.rs +++ b/crates/typst-library/src/model/terms.rs @@ -127,7 +127,7 @@ impl Show for Packed { let pad = hanging_indent + indent; let unpad = (!hanging_indent.is_zero()) - .then(|| HElem::new((-hanging_indent).into()).pack()); + .then(|| HElem::new((-hanging_indent).into()).pack().spanned(self.span())); let mut children = vec![]; for child in self.children().iter() { @@ -149,12 +149,16 @@ impl Show for Packed { let mut realized = StackElem::new(children) .with_spacing(Some(gutter.into())) .pack() + .spanned(self.span()) .padded(padding); if self.tight(styles) { let leading = ParElem::leading_in(styles); - let spacing = - VElem::new(leading.into()).with_weak(true).with_attach(true).pack(); + let spacing = VElem::new(leading.into()) + .with_weak(true) + .with_attach(true) + .pack() + .spanned(self.span()); realized = spacing + realized; } diff --git a/crates/typst-macros/src/cast.rs b/crates/typst-macros/src/cast.rs index 9254cdb90..b90b78886 100644 --- a/crates/typst-macros/src/cast.rs +++ b/crates/typst-macros/src/cast.rs @@ -273,7 +273,7 @@ fn create_output_body(input: &CastInput) -> TokenStream { if input.dynamic { quote! { #foundations::CastInfo::Type(#foundations::Type::of::()) } } else { - quote! { Self::input() } + quote! { ::input() } } }