summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-12-02 13:15:28 +0100
committerLaurenz <laurmaedje@gmail.com>2024-12-04 10:12:07 +0100
commit008b59839f276bc5563fea2ac3350da63a0355d8 (patch)
treee5e5a227e984df67ffa73d2561567e800952de7d /crates
parentf8f2ba6a5f8c8ca7dbb85cf17b73332a0c301c60 (diff)
Add some more spans
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-eval/src/call.rs4
-rw-r--r--crates/typst-eval/src/code.rs2
-rw-r--r--crates/typst-eval/src/lib.rs3
-rw-r--r--crates/typst-library/src/foundations/args.rs2
-rw-r--r--crates/typst-library/src/foundations/content.rs18
-rw-r--r--crates/typst-library/src/foundations/func.rs3
-rw-r--r--crates/typst-library/src/foundations/ty.rs2
-rw-r--r--crates/typst-library/src/model/outline.rs13
-rw-r--r--crates/typst-library/src/model/terms.rs10
-rw-r--r--crates/typst-macros/src/cast.rs2
10 files changed, 41 insertions, 18 deletions
diff --git a/crates/typst-eval/src/call.rs b/crates/typst-eval/src/call.rs
index f48734cb..513d1dd2 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 ba5256c1..34373fd4 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 69c20e8c..5eae7c1d 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::<ast::Math>().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 ee282a87..a60e6d7f 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 69103e08..bfafbc48 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<Rel<Length>>) -> 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<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)
}
}
diff --git a/crates/typst-library/src/foundations/func.rs b/crates/typst-library/src/foundations/func.rs
index e34f48a1..40c826df 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<Scope>,
/// A list of parameter information for each parameter.
pub params: LazyLock<Vec<ParamInfo>>,
diff --git a/crates/typst-library/src/foundations/ty.rs b/crates/typst-library/src/foundations/ty.rs
index 680c4f6a..8b20e2c6 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<Option<&'static NativeFuncData>>,
+ /// Definitions in the scope of the type.
pub scope: LazyLock<Scope>,
}
diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs
index 85257c2c..0be1a9d0 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<OutlineElem> {
)?;
// 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<OutlineEntry> {
);
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 036a03e2..bbcb63fc 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<TermsElem> {
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<TermsElem> {
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 9254cdb9..b90b7888 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::<Self>()) }
} else {
- quote! { Self::input() }
+ quote! { <Self as #foundations::Reflect>::input() }
}
}