Add some more spans

This commit is contained in:
Laurenz 2024-12-02 13:15:28 +01:00
parent f8f2ba6a5f
commit 008b59839f
10 changed files with 41 additions and 18 deletions

View File

@ -391,7 +391,9 @@ fn wrap_args_in_math(
} }
Ok(Value::Content( Ok(Value::Content(
callee.display().spanned(callee_span) callee.display().spanned(callee_span)
+ LrElem::new(TextElem::packed('(') + body + TextElem::packed(')')).pack(), + LrElem::new(TextElem::packed('(') + body + TextElem::packed(')'))
.pack()
.spanned(args.span),
)) ))
} }

View File

@ -359,7 +359,7 @@ impl Eval for ast::Contextual<'_> {
}; };
let func = Func::from(closure).spanned(body.span()); let func = Func::from(closure).spanned(body.span());
Ok(ContextElem::new(func).pack()) Ok(ContextElem::new(func).pack().spanned(body.span()))
} }
} }

View File

@ -148,7 +148,8 @@ pub fn eval_string(
EvalMode::Math => Value::Content( EvalMode::Math => Value::Content(
EquationElem::new(root.cast::<ast::Math>().unwrap().eval(&mut vm)?) EquationElem::new(root.cast::<ast::Math>().unwrap().eval(&mut vm)?)
.with_block(false) .with_block(false)
.pack(), .pack()
.spanned(span),
), ),
}; };

View File

@ -187,7 +187,7 @@ impl Args {
self.items.retain(|item| { self.items.retain(|item| {
if item.name.is_some() { if item.name.is_some() {
return true; return true;
}; }
let span = item.value.span; let span = item.value.span;
let spanned = Spanned::new(std::mem::take(&mut item.value.v), span); let spanned = Spanned::new(std::mem::take(&mut item.value.v), span);
match T::from_value(spanned).at(span) { match T::from_value(spanned).at(span) {

View File

@ -481,17 +481,20 @@ impl Content {
impl Content { impl Content {
/// Strongly emphasize this content. /// Strongly emphasize this content.
pub fn strong(self) -> Self { pub fn strong(self) -> Self {
StrongElem::new(self).pack() let span = self.span();
StrongElem::new(self).pack().spanned(span)
} }
/// Emphasize this content. /// Emphasize this content.
pub fn emph(self) -> Self { pub fn emph(self) -> Self {
EmphElem::new(self).pack() let span = self.span();
EmphElem::new(self).pack().spanned(span)
} }
/// Underline this content. /// Underline this content.
pub fn underlined(self) -> Self { pub fn underlined(self) -> Self {
UnderlineElem::new(self).pack() let span = self.span();
UnderlineElem::new(self).pack().spanned(span)
} }
/// Link the content somewhere. /// Link the content somewhere.
@ -506,17 +509,24 @@ impl Content {
/// Pad this content at the sides. /// Pad this content at the sides.
pub fn padded(self, padding: Sides<Rel<Length>>) -> Self { pub fn padded(self, padding: Sides<Rel<Length>>) -> Self {
let span = self.span();
PadElem::new(self) PadElem::new(self)
.with_left(padding.left) .with_left(padding.left)
.with_top(padding.top) .with_top(padding.top)
.with_right(padding.right) .with_right(padding.right)
.with_bottom(padding.bottom) .with_bottom(padding.bottom)
.pack() .pack()
.spanned(span)
} }
/// Transform this content's contents without affecting layout. /// Transform this content's contents without affecting layout.
pub fn moved(self, delta: Axes<Rel<Length>>) -> Self { pub fn moved(self, delta: Axes<Rel<Length>>) -> 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)
} }
} }

View File

@ -443,7 +443,7 @@ pub trait NativeFunc {
Func::from(Self::data()) 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; fn data() -> &'static NativeFuncData;
} }
@ -462,6 +462,7 @@ pub struct NativeFuncData {
pub keywords: &'static [&'static str], pub keywords: &'static [&'static str],
/// Whether this function makes use of context. /// Whether this function makes use of context.
pub contextual: bool, pub contextual: bool,
/// Definitions in the scope of the function.
pub scope: LazyLock<Scope>, pub scope: LazyLock<Scope>,
/// A list of parameter information for each parameter. /// A list of parameter information for each parameter.
pub params: LazyLock<Vec<ParamInfo>>, pub params: LazyLock<Vec<ParamInfo>>,

View File

@ -199,6 +199,7 @@ pub trait NativeType {
pub struct NativeTypeData { pub struct NativeTypeData {
/// The type's normal name (e.g. `str`), as exposed to Typst. /// The type's normal name (e.g. `str`), as exposed to Typst.
pub name: &'static str, pub name: &'static str,
/// The type's long name (e.g. `string`), for error messages.
pub long_name: &'static str, pub long_name: &'static str,
/// The function's title case name (e.g. `String`). /// The function's title case name (e.g. `String`).
pub title: &'static str, pub title: &'static str,
@ -208,6 +209,7 @@ pub struct NativeTypeData {
pub keywords: &'static [&'static str], pub keywords: &'static [&'static str],
/// The constructor for this type. /// The constructor for this type.
pub constructor: LazyLock<Option<&'static NativeFuncData>>, pub constructor: LazyLock<Option<&'static NativeFuncData>>,
/// Definitions in the scope of the type.
pub scope: LazyLock<Scope>, pub scope: LazyLock<Scope>,
} }

View File

@ -248,7 +248,7 @@ impl Show for Packed<OutlineElem> {
)?; )?;
// Add the overridable outline entry, followed by a line break. // 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()); seq.push(LinebreakElem::shared().clone());
ancestors.push(elem); ancestors.push(elem);
@ -332,15 +332,18 @@ impl OutlineIndent {
} }
if !ancestors.is_empty() { if !ancestors.is_empty() {
seq.push(HideElem::new(hidden).pack()); seq.push(HideElem::new(hidden).pack().spanned(span));
seq.push(SpaceElem::shared().clone()); seq.push(SpaceElem::shared().clone().spanned(span));
} }
} }
// Length => indent with some fixed spacing per level // Length => indent with some fixed spacing per level
Some(Smart::Custom(OutlineIndent::Rel(length))) => { Some(Smart::Custom(OutlineIndent::Rel(length))) => {
seq.push( 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<OutlineEntry> {
); );
seq.push(SpaceElem::shared().clone()); seq.push(SpaceElem::shared().clone());
} else { } else {
seq.push(HElem::new(Fr::one().into()).pack()); seq.push(HElem::new(Fr::one().into()).pack().spanned(self.span()));
} }
// Add the page number. // Add the page number.

View File

@ -127,7 +127,7 @@ impl Show for Packed<TermsElem> {
let pad = hanging_indent + indent; let pad = hanging_indent + indent;
let unpad = (!hanging_indent.is_zero()) 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![]; let mut children = vec![];
for child in self.children().iter() { for child in self.children().iter() {
@ -149,12 +149,16 @@ impl Show for Packed<TermsElem> {
let mut realized = StackElem::new(children) let mut realized = StackElem::new(children)
.with_spacing(Some(gutter.into())) .with_spacing(Some(gutter.into()))
.pack() .pack()
.spanned(self.span())
.padded(padding); .padded(padding);
if self.tight(styles) { if self.tight(styles) {
let leading = ParElem::leading_in(styles); let leading = ParElem::leading_in(styles);
let spacing = let spacing = VElem::new(leading.into())
VElem::new(leading.into()).with_weak(true).with_attach(true).pack(); .with_weak(true)
.with_attach(true)
.pack()
.spanned(self.span());
realized = spacing + realized; realized = spacing + realized;
} }

View File

@ -273,7 +273,7 @@ fn create_output_body(input: &CastInput) -> TokenStream {
if input.dynamic { if input.dynamic {
quote! { #foundations::CastInfo::Type(#foundations::Type::of::<Self>()) } quote! { #foundations::CastInfo::Type(#foundations::Type::of::<Self>()) }
} else { } else {
quote! { Self::input() } quote! { <Self as #foundations::Reflect>::input() }
} }
} }