summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/geom/em.rs5
-rw-r--r--src/geom/length.rs6
-rw-r--r--src/ide/complete.rs4
-rw-r--r--src/model/eval.rs11
-rw-r--r--src/model/func.rs17
5 files changed, 22 insertions, 21 deletions
diff --git a/src/geom/em.rs b/src/geom/em.rs
index 93dc80e4..9f5aff39 100644
--- a/src/geom/em.rs
+++ b/src/geom/em.rs
@@ -42,6 +42,11 @@ impl Em {
(self.0).0
}
+ /// The absolute value of this em length.
+ pub fn abs(self) -> Self {
+ Self::new(self.get().abs())
+ }
+
/// Convert to an absolute length at the given font size.
pub fn at(self, font_size: Abs) -> Abs {
let resolved = font_size * self.get();
diff --git a/src/geom/length.rs b/src/geom/length.rs
index 230ea48b..ae615f14 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -18,6 +18,12 @@ impl Length {
Self { abs: Abs::zero(), em: Em::zero() }
}
+ /// Try to compute the absolute value of the length.
+ pub fn try_abs(self) -> Option<Self> {
+ (self.abs.is_zero() || self.em.is_zero())
+ .then(|| Self { abs: self.abs.abs(), em: self.em.abs() })
+ }
+
/// Try to divide two lengths.
pub fn try_div(self, other: Self) -> Option<f64> {
if self.abs.is_zero() && other.abs.is_zero() {
diff --git a/src/ide/complete.rs b/src/ide/complete.rs
index 53d4851f..27b81fb2 100644
--- a/src/ide/complete.rs
+++ b/src/ide/complete.rs
@@ -774,7 +774,7 @@ impl<'a> CompletionContext<'a> {
matches!(
value,
Value::Func(func) if func.info().map_or(false, |info| {
- info.tags.contains(&"math")
+ info.category == "math"
}),
)
});
@@ -805,7 +805,7 @@ impl<'a> CompletionContext<'a> {
!short_form || matches!(
value,
Value::Func(func) if func.info().map_or(true, |info| {
- !info.tags.contains(&"math")
+ info.category != "math"
}),
)
});
diff --git a/src/model/eval.rs b/src/model/eval.rs
index 91fe61bb..a9fa2e14 100644
--- a/src/model/eval.rs
+++ b/src/model/eval.rs
@@ -476,10 +476,7 @@ impl Eval for ast::Frac {
type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok((vm.items.math_frac)(
- self.num().eval(vm)?,
- self.denom().eval(vm)?,
- ))
+ Ok((vm.items.math_frac)(self.num().eval(vm)?, self.denom().eval(vm)?))
}
}
@@ -781,11 +778,7 @@ impl Eval for ast::FieldAccess {
.field(&field)
.ok_or_else(|| format!("unknown field {field:?}"))
.at(span)?,
- v => bail!(
- self.target().span(),
- "cannot access field on {}",
- v.type_name()
- ),
+ v => bail!(self.target().span(), "cannot access field on {}", v.type_name()),
})
}
}
diff --git a/src/model/func.rs b/src/model/func.rs
index fb8b3dd0..e47594a1 100644
--- a/src/model/func.rs
+++ b/src/model/func.rs
@@ -37,18 +37,16 @@ impl Func {
/// Create a new function from a native rust function.
pub fn from_fn(
- name: &'static str,
func: fn(&Vm, &mut Args) -> SourceResult<Value>,
info: FuncInfo,
) -> Self {
- Self(Arc::new(Repr::Native(Native { name, func, set: None, node: None, info })))
+ Self(Arc::new(Repr::Native(Native { func, set: None, node: None, info })))
}
/// Create a new function from a native rust node.
- pub fn from_node<T: Node>(name: &'static str, mut info: FuncInfo) -> Self {
+ pub fn from_node<T: Node>(mut info: FuncInfo) -> Self {
info.params.extend(T::properties());
Self(Arc::new(Repr::Native(Native {
- name,
func: |ctx, args| {
let styles = T::set(args, true)?;
let content = T::construct(ctx, args)?;
@@ -68,7 +66,7 @@ impl Func {
/// The name of the function.
pub fn name(&self) -> Option<&str> {
match self.0.as_ref() {
- Repr::Native(native) => Some(native.name),
+ Repr::Native(native) => Some(native.info.name),
Repr::Closure(closure) => closure.name.as_deref(),
Repr::With(func, _) => func.name(),
}
@@ -184,8 +182,6 @@ pub trait FuncType {
/// A function defined by a native rust function or node.
struct Native {
- /// The name of the function.
- name: &'static str,
/// The function pointer.
func: fn(&Vm, &mut Args) -> SourceResult<Value>,
/// The set rule.
@@ -198,7 +194,6 @@ struct Native {
impl Hash for Native {
fn hash<H: Hasher>(&self, state: &mut H) {
- self.name.hash(state);
(self.func as usize).hash(state);
self.set.map(|set| set as usize).hash(state);
self.node.hash(state);
@@ -210,8 +205,10 @@ impl Hash for Native {
pub struct FuncInfo {
/// The function's name.
pub name: &'static str,
- /// Tags that categorize the function.
- pub tags: &'static [&'static str],
+ /// The display name of the function.
+ pub display: &'static str,
+ /// Which category the function is part of.
+ pub category: &'static str,
/// Documentation for the function.
pub docs: &'static str,
/// The source code of an example, if any.