From e9f1b5825a9d37ca0c173a7b2830ba36a27ca9e0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 24 Jul 2025 13:34:08 +0200 Subject: [PATCH 01/10] Lint for iterations over hash types (#6652) --- Cargo.toml | 1 + crates/typst-cli/src/watch.rs | 1 + crates/typst-cli/src/world.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 500d116a6..259a8a9f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,6 +159,7 @@ strip = true [workspace.lints.clippy] blocks_in_conditions = "allow" comparison_chain = "allow" +iter_over_hash_type = "warn" manual_range_contains = "allow" mutable_key_type = "allow" uninlined_format_args = "warn" diff --git a/crates/typst-cli/src/watch.rs b/crates/typst-cli/src/watch.rs index 765f86808..151c0ca1d 100644 --- a/crates/typst-cli/src/watch.rs +++ b/crates/typst-cli/src/watch.rs @@ -139,6 +139,7 @@ impl Watcher { fn update(&mut self, iter: impl IntoIterator) -> StrResult<()> { // Mark all files as not "seen" so that we may unwatch them if they // aren't in the dependency list. + #[allow(clippy::iter_over_hash_type, reason = "order does not matter")] for seen in self.watched.values_mut() { *seen = false; } diff --git a/crates/typst-cli/src/world.rs b/crates/typst-cli/src/world.rs index 42083ef20..34ebda64b 100644 --- a/crates/typst-cli/src/world.rs +++ b/crates/typst-cli/src/world.rs @@ -173,6 +173,7 @@ impl SystemWorld { /// Reset the compilation state in preparation of a new compilation. pub fn reset(&mut self) { + #[allow(clippy::iter_over_hash_type, reason = "order does not matter")] for slot in self.slots.get_mut().values_mut() { slot.reset(); } From 3adbedc3a8a8b6d7682cb3e86b4fb974260af754 Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Mon, 28 Jul 2025 11:03:37 +0200 Subject: [PATCH 02/10] Create constructor methods for manifest types (#6625) --- crates/typst-syntax/src/package.rs | 69 +++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/crates/typst-syntax/src/package.rs b/crates/typst-syntax/src/package.rs index fe3577a3b..9fde75e33 100644 --- a/crates/typst-syntax/src/package.rs +++ b/crates/typst-syntax/src/package.rs @@ -143,6 +143,16 @@ pub struct PackageInfo { } impl PackageManifest { + /// Create a new package manifest with the given package info. + pub fn new(package: PackageInfo) -> Self { + PackageManifest { + package, + template: None, + tool: ToolInfo::default(), + unknown_fields: UnknownFields::new(), + } + } + /// Ensure that this manifest is indeed for the specified package. pub fn validate(&self, spec: &PackageSpec) -> Result<(), EcoString> { if self.package.name != spec.name { @@ -173,6 +183,44 @@ impl PackageManifest { } } +impl TemplateInfo { + /// Create a new template info with only required fields. + pub fn new(path: impl Into, entrypoint: impl Into) -> Self { + TemplateInfo { + path: path.into(), + entrypoint: entrypoint.into(), + thumbnail: None, + unknown_fields: UnknownFields::new(), + } + } +} + +impl PackageInfo { + /// Create a new package info with only required fields. + pub fn new( + name: impl Into, + version: PackageVersion, + entrypoint: impl Into, + ) -> Self { + PackageInfo { + name: name.into(), + version, + entrypoint: entrypoint.into(), + authors: vec![], + categories: vec![], + compiler: None, + description: None, + disciplines: vec![], + exclude: vec![], + homepage: None, + keywords: vec![], + license: None, + repository: None, + unknown_fields: BTreeMap::new(), + } + } +} + /// Identifies a package. #[derive(Clone, Eq, PartialEq, Hash)] pub struct PackageSpec { @@ -535,22 +583,11 @@ mod tests { "# ), Ok(PackageManifest { - package: PackageInfo { - name: "package".into(), - version: PackageVersion { major: 0, minor: 1, patch: 0 }, - entrypoint: "src/lib.typ".into(), - authors: vec![], - license: None, - description: None, - homepage: None, - repository: None, - keywords: vec![], - categories: vec![], - disciplines: vec![], - compiler: None, - exclude: vec![], - unknown_fields: BTreeMap::new(), - }, + package: PackageInfo::new( + "package", + PackageVersion { major: 0, minor: 1, patch: 0 }, + "src/lib.typ" + ), template: None, tool: ToolInfo { sections: BTreeMap::new() }, unknown_fields: BTreeMap::new(), From a42501c6138e41349e09cf32808ebb82ae03d63f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 28 Jul 2025 11:03:57 +0200 Subject: [PATCH 03/10] Remove unnecessary `comemo` dependency in `typst-syntax` (#6668) --- Cargo.lock | 1 - crates/typst-syntax/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e5fb87ee..bcf430a43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3267,7 +3267,6 @@ dependencies = [ name = "typst-syntax" version = "0.13.1" dependencies = [ - "comemo", "ecow", "serde", "toml", diff --git a/crates/typst-syntax/Cargo.toml b/crates/typst-syntax/Cargo.toml index c20f6a087..263595bd4 100644 --- a/crates/typst-syntax/Cargo.toml +++ b/crates/typst-syntax/Cargo.toml @@ -15,7 +15,6 @@ readme = { workspace = true } [dependencies] typst-timing = { workspace = true } typst-utils = { workspace = true } -comemo = { workspace = true } ecow = { workspace = true } serde = { workspace = true } toml = { workspace = true } From a676c78a0598fd725a09f588f57f3bdbdce75f57 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 28 Jul 2025 11:04:10 +0200 Subject: [PATCH 04/10] Remove duplicate center alignment style for equations (#6667) --- crates/typst-library/src/math/equation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/typst-library/src/math/equation.rs b/crates/typst-library/src/math/equation.rs index 45831f52c..c624c8ad0 100644 --- a/crates/typst-library/src/math/equation.rs +++ b/crates/typst-library/src/math/equation.rs @@ -168,7 +168,6 @@ impl ShowSet for Packed { fn show_set(&self, styles: StyleChain) -> Styles { let mut out = Styles::new(); if self.block.get(styles) { - out.set(AlignElem::alignment, Alignment::CENTER); out.set(AlignElem::alignment, Alignment::CENTER); out.set(BlockElem::breakable, false); out.set(ParLine::numbering, None); From a4d4dfb1b656c5d0890f7c4079a851b182a74c35 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Mon, 28 Jul 2025 11:06:18 +0200 Subject: [PATCH 05/10] Fix incorrect `vline.x` docs (#6657) --- crates/typst-library/src/layout/grid/mod.rs | 2 +- crates/typst-library/src/model/table.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/typst-library/src/layout/grid/mod.rs b/crates/typst-library/src/layout/grid/mod.rs index de540a578..d33e887a3 100644 --- a/crates/typst-library/src/layout/grid/mod.rs +++ b/crates/typst-library/src/layout/grid/mod.rs @@ -548,7 +548,7 @@ pub struct GridHLine { /// the grid's `row-gutter` option. #[elem(name = "vline", title = "Grid Vertical Line")] pub struct GridVLine { - /// The column before which the horizontal line is placed (zero-indexed). + /// The column before which the vertical line is placed (zero-indexed). /// If the `position` field is set to `{end}`, the line is placed after the /// column with the given index instead (see that field's docs for /// details). diff --git a/crates/typst-library/src/model/table.rs b/crates/typst-library/src/model/table.rs index 412ca4229..c815fc159 100644 --- a/crates/typst-library/src/model/table.rs +++ b/crates/typst-library/src/model/table.rs @@ -528,7 +528,7 @@ pub struct TableHLine { /// part of all your tables' designs. #[elem(name = "vline", title = "Table Vertical Line")] pub struct TableVLine { - /// The column before which the horizontal line is placed (zero-indexed). + /// The column before which the vertical line is placed (zero-indexed). /// Functions identically to the `x` field in [`grid.vline`]($grid.vline). pub x: Smart, From d446cde4fa2f10c753092761c1ec7e2083512720 Mon Sep 17 00:00:00 2001 From: "Y.D.X." <73375426+YDX-2147483647@users.noreply.github.com> Date: Mon, 28 Jul 2025 17:39:13 +0800 Subject: [PATCH 06/10] Miscellaneous minor docs improvements (#6651) Co-authored-by: Laurenz --- .../src/introspection/counter.rs | 4 +- crates/typst-library/src/layout/page.rs | 9 +++++ crates/typst-library/src/model/figure.rs | 37 ++++++++++++++++++- crates/typst-library/src/text/mod.rs | 6 +++ docs/reference/library/symbols.md | 3 ++ 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/crates/typst-library/src/introspection/counter.rs b/crates/typst-library/src/introspection/counter.rs index f6083303d..c7d26040c 100644 --- a/crates/typst-library/src/introspection/counter.rs +++ b/crates/typst-library/src/introspection/counter.rs @@ -412,9 +412,11 @@ impl Counter { /// - If it is a string, creates a custom counter that is only affected /// by manual updates, /// - If it is the [`page`] function, counts through pages, - /// - If it is a [selector], counts through elements that matches with the + /// - If it is a [selector], counts through elements that match the /// selector. For example, /// - provide an element function: counts elements of that type, + /// - provide a [`where`]($function.where) selector: + /// counts a type of element with specific fields, /// - provide a [`{