Reformat with 2024 edition

This commit is contained in:
Laurenz 2025-07-21 15:13:34 +02:00
parent e81a5a6ef2
commit b036fd97ab
260 changed files with 1245 additions and 1289 deletions

View File

@ -1,10 +1,10 @@
use std::env;
use std::fs::{create_dir_all, File};
use std::fs::{File, create_dir_all};
use std::path::Path;
use std::process::Command;
use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, Shell};
use clap_complete::{Shell, generate_to};
use clap_mangen::Man;
#[path = "src/args.rs"]

View File

@ -10,13 +10,13 @@ use ecow::eco_format;
use parking_lot::RwLock;
use pathdiff::diff_paths;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use typst::WorldExt;
use typst::diag::{
bail, At, Severity, SourceDiagnostic, SourceResult, StrResult, Warned,
At, Severity, SourceDiagnostic, SourceResult, StrResult, Warned, bail,
};
use typst::foundations::{Datetime, Smart};
use typst::layout::{Frame, Page, PageRanges, PagedDocument};
use typst::syntax::{FileId, Lines, Span};
use typst::WorldExt;
use typst_html::HtmlDocument;
use typst_pdf::{PdfOptions, PdfStandards, Timestamp};
@ -513,7 +513,9 @@ fn write_make_deps(
})
.collect::<Result<Vec<_>, _>>()
else {
bail!("failed to create make dependencies file because output path was not valid unicode")
bail!(
"failed to create make dependencies file because output path was not valid unicode"
)
};
if output_paths.is_empty() {
bail!("failed to create make dependencies file because output was stdout")

View File

@ -8,8 +8,8 @@ use codespan_reporting::term::termcolor::WriteColor;
use typst::utils::format_duration;
use typst_kit::download::{DownloadState, Downloader, Progress};
use crate::terminal::{self, TermOut};
use crate::ARGS;
use crate::terminal::{self, TermOut};
/// Prints download progress by writing `downloading {0}` followed by repeatedly
/// updating the last terminal line.

View File

@ -4,7 +4,7 @@ use std::path::Path;
use codespan_reporting::term::termcolor::{Color, ColorSpec, WriteColor};
use ecow::eco_format;
use fs_extra::dir::CopyOptions;
use typst::diag::{bail, FileError, StrResult};
use typst::diag::{FileError, StrResult, bail};
use typst::syntax::package::{
PackageManifest, PackageSpec, TemplateInfo, VersionlessPackageSpec,
};

View File

@ -21,8 +21,8 @@ use std::io::{self, Write};
use std::process::ExitCode;
use std::sync::LazyLock;
use clap::error::ErrorKind;
use clap::Parser;
use clap::error::ErrorKind;
use codespan_reporting::term;
use codespan_reporting::term::termcolor::WriteColor;
use typst::diag::HintedStrResult;
@ -102,7 +102,7 @@ fn print_error(msg: &str) -> io::Result<()> {
#[cfg(not(feature = "self-update"))]
mod update {
use typst::diag::{bail, StrResult};
use typst::diag::{StrResult, bail};
use crate::args::UpdateCommand;

View File

@ -1,12 +1,12 @@
use comemo::Track;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use serde::Serialize;
use typst::diag::{bail, HintedStrResult, StrResult, Warned};
use typst::World;
use typst::diag::{HintedStrResult, StrResult, Warned, bail};
use typst::engine::Sink;
use typst::foundations::{Content, IntoValue, LocatableSelector, Scope};
use typst::layout::PagedDocument;
use typst::syntax::{Span, SyntaxMode};
use typst::World;
use typst_eval::eval_string;
use crate::args::{QueryCommand, SerializationFormat};

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use ecow::eco_format;
use parking_lot::{Condvar, Mutex, MutexGuard};
use tiny_http::{Header, Request, Response, StatusCode};
use typst::diag::{bail, StrResult};
use typst::diag::{StrResult, bail};
use crate::args::{Input, ServerArgs};

View File

@ -2,9 +2,9 @@ use std::fs::File;
use std::io::BufWriter;
use std::path::{Path, PathBuf};
use typst::diag::{bail, StrResult};
use typst::syntax::Span;
use typst::World;
use typst::diag::{StrResult, bail};
use typst::syntax::Span;
use crate::args::{CliArguments, Command};
use crate::world::SystemWorld;

View File

@ -6,7 +6,7 @@ use ecow::eco_format;
use semver::Version;
use serde::Deserialize;
use tempfile::NamedTempFile;
use typst::diag::{bail, StrResult};
use typst::diag::{StrResult, bail};
use typst_kit::download::Downloader;
use xz2::bufread::XzDecoder;
use zip::ZipArchive;

View File

@ -10,12 +10,12 @@ use codespan_reporting::term::{self, termcolor};
use ecow::eco_format;
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher as _};
use same_file::is_same_file;
use typst::diag::{bail, warning, StrResult};
use typst::diag::{StrResult, bail, warning};
use typst::syntax::Span;
use typst::utils::format_duration;
use crate::args::{Input, Output, WatchCommand};
use crate::compile::{compile_once, print_diagnostics, CompileConfig};
use crate::compile::{CompileConfig, compile_once, print_diagnostics};
use crate::timings::Timer;
use crate::world::{SystemWorld, WorldCreationError};
use crate::{print_error, terminal};

View File

@ -5,7 +5,7 @@ use std::sync::{LazyLock, OnceLock};
use std::{fmt, fs, io, mem};
use chrono::{DateTime, Datelike, FixedOffset, Local, Utc};
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use parking_lot::Mutex;
use typst::diag::{FileError, FileResult};
use typst::foundations::{Bytes, Datetime, Dict, IntoValue};
@ -362,7 +362,8 @@ impl<T: Clone> SlotCell<T> {
) -> FileResult<T> {
// If we accessed the file already in this compilation, retrieve it.
if mem::replace(&mut self.accessed, true)
&& let Some(data) = &self.data {
&& let Some(data) = &self.data
{
return data.clone();
}
@ -372,7 +373,8 @@ impl<T: Clone> SlotCell<T> {
// If the file contents didn't change, yield the old processed data.
if mem::replace(&mut self.fingerprint, fingerprint) == fingerprint
&& let Some(data) = &self.data {
&& let Some(data) = &self.data
{
return data.clone();
}

View File

@ -1,9 +1,9 @@
use ecow::eco_format;
use typst_library::diag::{bail, At, Hint, SourceResult, Trace, Tracepoint};
use typst_library::diag::{At, Hint, SourceResult, Trace, Tracepoint, bail};
use typst_library::foundations::{Dict, Value};
use typst_syntax::ast::{self, AstNode};
use crate::{call_method_access, is_accessor_method, Eval, Vm};
use crate::{Eval, Vm, call_method_access, is_accessor_method};
/// Access an expression mutably.
pub(crate) trait Access {
@ -30,7 +30,8 @@ impl Access for ast::Ident<'_> {
fn access<'a>(self, vm: &'a mut Vm) -> SourceResult<&'a mut Value> {
let span = self.span();
if vm.inspected == Some(span)
&& let Ok(binding) = vm.scopes.get(&self) {
&& let Ok(binding) = vm.scopes.get(&self)
{
vm.trace(binding.read().clone());
}
vm.scopes

View File

@ -1,7 +1,7 @@
use std::collections::HashSet;
use ecow::eco_format;
use typst_library::diag::{bail, error, At, SourceDiagnostic, SourceResult};
use typst_library::diag::{At, SourceDiagnostic, SourceResult, bail, error};
use typst_library::foundations::{Array, Dict, Value};
use typst_syntax::ast::{self, AstNode};

View File

@ -1,8 +1,9 @@
use comemo::{Tracked, TrackedMut};
use ecow::{eco_format, EcoString, EcoVec};
use ecow::{EcoString, EcoVec, eco_format};
use typst_library::World;
use typst_library::diag::{
bail, error, At, HintedStrResult, HintedString, SourceDiagnostic, SourceResult,
Trace, Tracepoint,
At, HintedStrResult, HintedString, SourceDiagnostic, SourceResult, Trace, Tracepoint,
bail, error,
};
use typst_library::engine::{Engine, Sink, Traced};
use typst_library::foundations::{
@ -12,12 +13,11 @@ use typst_library::foundations::{
use typst_library::introspection::Introspector;
use typst_library::math::LrElem;
use typst_library::routines::Routines;
use typst_library::World;
use typst_syntax::ast::{self, AstNode, Ident};
use typst_syntax::{Span, Spanned, SyntaxNode};
use typst_utils::LazyHash;
use crate::{call_method_mut, is_mutating_method, Access, Eval, FlowEvent, Route, Vm};
use crate::{Access, Eval, FlowEvent, Route, Vm, call_method_mut, is_mutating_method};
impl Eval for ast::FuncCall<'_> {
type Output = Value;

View File

@ -1,9 +1,9 @@
use ecow::{eco_vec, EcoVec};
use typst_library::diag::{bail, error, warning, At, SourceResult};
use ecow::{EcoVec, eco_vec};
use typst_library::diag::{At, SourceResult, bail, error, warning};
use typst_library::engine::Engine;
use typst_library::foundations::{
ops, Array, Capturer, Closure, Content, ContextElem, Dict, Func, NativeElement,
Selector, Str, Value,
Array, Capturer, Closure, Content, ContextElem, Dict, Func, NativeElement, Selector,
Str, Value, ops,
};
use typst_library::introspection::{Counter, State};
use typst_syntax::ast::{self, AstNode};
@ -324,14 +324,13 @@ impl Eval for ast::FieldAccess<'_> {
};
// Check whether this is a get rule field access.
if let Value::Func(func) = &value &&
let Some(element) = func.element() &&
let Some(id) = element.field_id(&field) &&
let styles = vm.context.styles().at(field.span()) &&
let Ok(value) = element.field_from_styles(
id,
styles.as_ref().map(|&s| s).unwrap_or_default(),
) {
if let Value::Func(func) = &value
&& let Some(element) = func.element()
&& let Some(id) = element.field_id(&field)
&& let styles = vm.context.styles().at(field.span())
&& let Ok(value) = element
.field_from_styles(id, styles.as_ref().map(|&s| s).unwrap_or_default())
{
// Only validate the context once we know that this is indeed
// a field from the style chain.
let _ = styles?;

View File

@ -1,10 +1,10 @@
use typst_library::diag::{bail, error, At, SourceDiagnostic, SourceResult};
use typst_library::foundations::{ops, IntoValue, Value};
use typst_library::diag::{At, SourceDiagnostic, SourceResult, bail, error};
use typst_library::foundations::{IntoValue, Value, ops};
use typst_syntax::ast::{self, AstNode};
use typst_syntax::{Span, SyntaxKind, SyntaxNode};
use unicode_segmentation::UnicodeSegmentation;
use crate::{destructure, Eval, Vm};
use crate::{Eval, Vm, destructure};
/// The maximum number of loop iterations.
const MAX_ITERATIONS: usize = 10_000;

View File

@ -1,16 +1,16 @@
use comemo::TrackedMut;
use ecow::{eco_format, eco_vec, EcoString};
use ecow::{EcoString, eco_format, eco_vec};
use typst_library::World;
use typst_library::diag::{
bail, error, warning, At, FileError, SourceResult, Trace, Tracepoint,
At, FileError, SourceResult, Trace, Tracepoint, bail, error, warning,
};
use typst_library::engine::Engine;
use typst_library::foundations::{Binding, Content, Module, Value};
use typst_library::World;
use typst_syntax::ast::{self, AstNode, BareImportError};
use typst_syntax::package::{PackageManifest, PackageSpec};
use typst_syntax::{FileId, Span, VirtualPath};
use crate::{eval, Eval, Vm};
use crate::{Eval, Vm, eval};
impl Eval for ast::ModuleImport<'_> {
type Output = Value;
@ -47,7 +47,8 @@ impl Eval for ast::ModuleImport<'_> {
let new_name = self.new_name();
if let Some(new_name) = new_name {
if let ast::Expr::Ident(ident) = self.source()
&& ident.as_str() == new_name.as_str() {
&& ident.as_str() == new_name.as_str()
{
// Warn on `import x as x`
vm.engine.sink.warn(warning!(
new_name.span(),

View File

@ -14,7 +14,7 @@ mod methods;
mod rules;
mod vm;
pub use self::call::{eval_closure, CapturesVisitor};
pub use self::call::{CapturesVisitor, eval_closure};
pub use self::flow::FlowEvent;
pub use self::import::import;
pub use self::vm::Vm;
@ -24,14 +24,14 @@ use self::binding::*;
use self::methods::*;
use comemo::{Track, Tracked, TrackedMut};
use typst_library::diag::{bail, SourceResult};
use typst_library::World;
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Context, Module, NativeElement, Scope, Scopes, Value};
use typst_library::introspection::Introspector;
use typst_library::math::EquationElem;
use typst_library::routines::Routines;
use typst_library::World;
use typst_syntax::{ast, parse, parse_code, parse_math, Source, Span, SyntaxMode};
use typst_syntax::{Source, Span, SyntaxMode, ast, parse, parse_code, parse_math};
/// Evaluate a source file and return the resulting module.
#[comemo::memoize]

View File

@ -1,4 +1,4 @@
use typst_library::diag::{warning, At, SourceResult};
use typst_library::diag::{At, SourceResult, warning};
use typst_library::foundations::{
Content, Label, NativeElement, Repr, Smart, Symbol, Unlabellable, Value,
};

View File

@ -1,8 +1,8 @@
use typst_library::diag::{At, HintedStrResult, SourceResult};
use typst_library::foundations::{ops, IntoValue, Value};
use typst_library::foundations::{IntoValue, Value, ops};
use typst_syntax::ast::{self, AstNode};
use crate::{access_dict, Access, Eval, Vm};
use crate::{Access, Eval, Vm, access_dict};
impl Eval for ast::Unary<'_> {
type Output = Value;
@ -77,7 +77,8 @@ fn apply_assignment(
// An assignment to a dictionary field is different from a normal access
// since it can create the field instead of just modifying it.
if binary.op() == ast::BinOp::Assign
&& let ast::Expr::FieldAccess(access) = lhs {
&& let ast::Expr::FieldAccess(access) = lhs
{
let dict = access_dict(vm, access)?;
dict.insert(access.field().get().clone().into(), rhs);
return Ok(Value::None);

View File

@ -1,4 +1,4 @@
use typst_library::diag::{warning, At, SourceResult};
use typst_library::diag::{At, SourceResult, warning};
use typst_library::foundations::{
Element, Func, Recipe, Selector, ShowableSelector, Styles, Transformation,
};
@ -13,7 +13,8 @@ impl Eval for ast::SetRule<'_> {
fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> {
if let Some(condition) = self.condition()
&& !condition.eval(vm)?.cast::<bool>().at(condition.span())? {
&& !condition.eval(vm)?.cast::<bool>().at(condition.span())?
{
return Ok(Styles::new());
}
@ -57,10 +58,10 @@ impl Eval for ast::ShowRule<'_> {
/// Migration hint for `show par: set block(spacing: ..)`.
fn check_show_par_set_block(vm: &mut Vm, recipe: &Recipe) {
if let Some(Selector::Elem(elem, _)) = recipe.selector() &&
*elem == Element::of::<ParElem>() &&
let Transformation::Style(styles) = recipe.transform() &&
(styles.has(BlockElem::above) || styles.has(BlockElem::below))
if let Some(Selector::Elem(elem, _)) = recipe.selector()
&& *elem == Element::of::<ParElem>()
&& let Transformation::Style(styles) = recipe.transform()
&& (styles.has(BlockElem::above) || styles.has(BlockElem::below))
{
vm.engine.sink.warn(warning!(
recipe.span(),

View File

@ -1,10 +1,10 @@
use comemo::Tracked;
use typst_library::World;
use typst_library::diag::warning;
use typst_library::engine::Engine;
use typst_library::foundations::{Binding, Context, IntoValue, Scopes, Value};
use typst_library::World;
use typst_syntax::ast::{self, AstNode};
use typst_syntax::Span;
use typst_syntax::ast::{self, AstNode};
use crate::FlowEvent;

View File

@ -1,4 +1,4 @@
use typst_library::diag::{warning, SourceResult};
use typst_library::diag::{SourceResult, warning};
use typst_library::engine::Engine;
use typst_library::foundations::{Content, StyleChain, Target, TargetElem};
use typst_library::introspection::{SplitLocator, TagElem};
@ -8,7 +8,7 @@ use typst_library::routines::Pair;
use typst_library::text::{LinebreakElem, SmartQuoteElem, SpaceElem, TextElem};
use crate::fragment::html_fragment;
use crate::{attr, tag, FrameElem, HtmlElem, HtmlElement, HtmlFrame, HtmlNode};
use crate::{FrameElem, HtmlElem, HtmlElement, HtmlFrame, HtmlNode, attr, tag};
/// Converts realized content into HTML nodes.
pub fn convert_to_nodes<'a>(

View File

@ -2,7 +2,8 @@ use std::collections::HashSet;
use std::num::NonZeroUsize;
use comemo::{Tracked, TrackedMut};
use typst_library::diag::{bail, SourceResult};
use typst_library::World;
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Content, StyleChain};
use typst_library::introspection::{
@ -11,11 +12,10 @@ use typst_library::introspection::{
use typst_library::layout::{Point, Position, Transform};
use typst_library::model::DocumentInfo;
use typst_library::routines::{Arenas, RealizationKind, Routines};
use typst_library::World;
use typst_syntax::Span;
use typst_utils::NonZeroExt;
use crate::{attr, tag, HtmlDocument, HtmlElement, HtmlNode};
use crate::{HtmlDocument, HtmlElement, HtmlNode, attr, tag};
/// Produce an HTML document from content.
///

View File

@ -1,8 +1,8 @@
use std::fmt::{self, Debug, Display, Formatter};
use ecow::{EcoString, EcoVec};
use typst_library::diag::{bail, HintedStrResult, StrResult};
use typst_library::foundations::{cast, Dict, Repr, Str, StyleChain};
use typst_library::diag::{HintedStrResult, StrResult, bail};
use typst_library::foundations::{Dict, Repr, Str, StyleChain, cast};
use typst_library::introspection::{Introspector, Tag};
use typst_library::layout::{Abs, Frame, Point};
use typst_library::model::DocumentInfo;

View File

@ -1,12 +1,12 @@
use std::fmt::Write;
use typst_library::diag::{bail, At, SourceResult, StrResult};
use typst_library::diag::{At, SourceResult, StrResult, bail};
use typst_library::foundations::Repr;
use typst_library::introspection::Introspector;
use typst_syntax::Span;
use crate::{
attr, charsets, tag, HtmlDocument, HtmlElement, HtmlFrame, HtmlNode, HtmlTag,
HtmlDocument, HtmlElement, HtmlFrame, HtmlNode, HtmlTag, attr, charsets, tag,
};
/// Encodes an HTML document into a string.
@ -262,11 +262,7 @@ impl RawMode {
{
// Template literals can be multi-line, so indent may change
// the semantics of the JavaScript.
if text.contains('`') {
Self::Wrap
} else {
Self::Indent
}
if text.contains('`') { Self::Wrap } else { Self::Indent }
}
tag::style => Self::Indent,
_ => Self::Keep,

View File

@ -4,8 +4,8 @@ use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Content, StyleChain};
use typst_library::introspection::{Introspector, Locator, LocatorLink};
use typst_library::routines::{Arenas, FragmentKind, RealizationKind, Routines};
use typst_library::World;
use typst_library::routines::{Arenas, FragmentKind, RealizationKind, Routines};
use crate::HtmlNode;

View File

@ -19,8 +19,8 @@ pub use self::encode::html;
pub use self::rules::register;
use ecow::EcoString;
use typst_library::foundations::{Content, Module, Scope};
use typst_library::Category;
use typst_library::foundations::{Content, Module, Scope};
use typst_macros::elem;
/// Creates the module with all HTML definitions.
@ -86,11 +86,7 @@ impl HtmlElem {
attr: HtmlAttr,
value: Option<impl Into<EcoString>>,
) -> Self {
if let Some(value) = value {
self.with_attr(attr, value)
} else {
self
}
if let Some(value) = value { self.with_attr(attr, value) } else { self }
}
/// Adds CSS styles to an element.

View File

@ -1,14 +1,14 @@
use std::collections::{HashMap, HashSet, VecDeque};
use comemo::Track;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use typst_library::foundations::{Label, NativeElement};
use typst_library::introspection::{Introspector, Location, Tag};
use typst_library::layout::{Frame, FrameItem, Point};
use typst_library::model::{Destination, LinkElem};
use typst_utils::PicoStr;
use crate::{attr, tag, HtmlElement, HtmlNode};
use crate::{HtmlElement, HtmlNode, attr, tag};
/// Searches for links within a frame.
///

View File

@ -1,12 +1,12 @@
use std::num::NonZeroUsize;
use ecow::{eco_format, EcoVec};
use typst_library::diag::{warning, At};
use ecow::{EcoVec, eco_format};
use typst_library::diag::{At, warning};
use typst_library::foundations::{
Content, NativeElement, NativeRuleMap, ShowFn, Smart, StyleChain, Target,
};
use typst_library::introspection::{Counter, Locator};
use typst_library::layout::resolve::{table_to_cellgrid, Cell, CellGrid, Entry};
use typst_library::layout::resolve::{Cell, CellGrid, Entry, table_to_cellgrid};
use typst_library::layout::{OuterVAlignment, Sizing};
use typst_library::model::{
Attribution, CiteElem, CiteGroup, Destination, EmphElem, EnumElem, FigureCaption,
@ -19,7 +19,7 @@ use typst_library::text::{
};
use typst_library::visualize::ImageElem;
use crate::{attr, css, tag, FrameElem, HtmlAttrs, HtmlElem, HtmlTag};
use crate::{FrameElem, HtmlAttrs, HtmlElem, HtmlTag, attr, css, tag};
/// Registers show rules for the [HTML target](Target::Html).
pub fn register(rules: &mut NativeRuleMap) {
@ -240,9 +240,9 @@ const QUOTE_RULE: ShowFn<QuoteElem> = |elem, _, styles| {
let mut blockquote = HtmlElem::new(tag::blockquote).with_body(Some(realized));
if let Some(Attribution::Content(attribution)) = attribution
&& let Some(link) = attribution.to_packed::<LinkElem>()
&& let LinkTarget::Dest(Destination::Url(url)) = &link.dest {
blockquote =
blockquote.with_attr(attr::cite, url.clone().into_inner());
&& let LinkTarget::Dest(Destination::Url(url)) = &link.dest
{
blockquote = blockquote.with_attr(attr::cite, url.clone().into_inner());
}
realized = blockquote.pack().spanned(span);

View File

@ -9,9 +9,9 @@ use std::sync::LazyLock;
use bumpalo::Bump;
use comemo::Tracked;
use ecow::{eco_format, eco_vec, EcoString};
use ecow::{EcoString, eco_format, eco_vec};
use typst_assets::html as data;
use typst_library::diag::{bail, At, Hint, HintedStrResult, SourceResult};
use typst_library::diag::{At, Hint, HintedStrResult, SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{
Args, Array, AutoValue, CastInfo, Content, Context, Datetime, Dict, Duration,
@ -22,7 +22,7 @@ use typst_library::layout::{Axes, Axis, Dir, Length};
use typst_library::visualize::Color;
use typst_macros::cast;
use crate::{css, tag, HtmlAttr, HtmlAttrs, HtmlElem, HtmlTag};
use crate::{HtmlAttr, HtmlAttrs, HtmlElem, HtmlTag, css, tag};
/// Hook up all typed HTML definitions.
pub(super) fn define(html: &mut Scope) {

View File

@ -1,11 +1,11 @@
use std::collections::HashSet;
use comemo::Track;
use ecow::{eco_vec, EcoString, EcoVec};
use ecow::{EcoString, EcoVec, eco_vec};
use typst::foundations::{Label, Styles, Value};
use typst::layout::PagedDocument;
use typst::model::{BibliographyElem, FigureElem};
use typst::syntax::{ast, LinkedNode, SyntaxKind};
use typst::syntax::{LinkedNode, SyntaxKind, ast};
use crate::IdeWorld;
@ -28,12 +28,15 @@ pub fn analyze_expr(
ast::Expr::Str(v) => Value::Str(v.get().into()),
_ => {
if node.kind() == SyntaxKind::Contextual
&& let Some(child) = node.children().next_back() {
&& let Some(child) = node.children().next_back()
{
return analyze_expr(world, &child);
}
if let Some(parent) = node.parent()
&& parent.kind() == SyntaxKind::FieldAccess && node.index() > 0 {
&& parent.kind() == SyntaxKind::FieldAccess
&& node.index() > 0
{
return analyze_expr(world, parent);
}

View File

@ -2,17 +2,17 @@ use std::cmp::Reverse;
use std::collections::{BTreeMap, HashSet};
use std::ffi::OsStr;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use serde::{Deserialize, Serialize};
use typst::foundations::{
fields_on, repr, AutoValue, CastInfo, Func, Label, NoneValue, ParamInfo, Repr,
StyleChain, Styles, Type, Value,
AutoValue, CastInfo, Func, Label, NoneValue, ParamInfo, Repr, StyleChain, Styles,
Type, Value, fields_on, repr,
};
use typst::layout::{Alignment, Dir, PagedDocument};
use typst::syntax::ast::AstNode;
use typst::syntax::{
ast, is_id_continue, is_id_start, is_ident, FileId, LinkedNode, Side, Source,
SyntaxKind,
FileId, LinkedNode, Side, Source, SyntaxKind, ast, is_id_continue, is_id_start,
is_ident,
};
use typst::text::{FontFlags, RawElem};
use typst::visualize::Color;
@ -21,7 +21,7 @@ use unscanny::Scanner;
use crate::utils::{
check_value_recursively, globals, plain_docs_sentence, summarize_font_family,
};
use crate::{analyze_expr, analyze_import, analyze_labels, named_items, IdeWorld};
use crate::{IdeWorld, analyze_expr, analyze_import, analyze_labels, named_items};
/// Autocomplete a cursor position in a source file.
///
@ -375,8 +375,8 @@ fn complete_field_accesses(ctx: &mut CompletionContext) -> bool {
&& let Some(prev) = ctx.leaf.prev_sibling()
&& (!in_markup || prev.range().end == ctx.leaf.range().start)
&& prev.is::<ast::Expr>()
&& (prev.parent_kind() != Some(SyntaxKind::Markup) ||
prev.prev_sibling_kind() == Some(SyntaxKind::Hash))
&& (prev.parent_kind() != Some(SyntaxKind::Markup)
|| prev.prev_sibling_kind() == Some(SyntaxKind::Hash))
&& let Some((value, styles)) = analyze_expr(ctx.world, &prev).into_iter().next()
{
ctx.from = ctx.cursor;
@ -390,7 +390,8 @@ fn complete_field_accesses(ctx: &mut CompletionContext) -> bool {
&& prev.kind() == SyntaxKind::Dot
&& let Some(prev_prev) = prev.prev_sibling()
&& prev_prev.is::<ast::Expr>()
&& let Some((value, styles)) = analyze_expr(ctx.world, &prev_prev).into_iter().next()
&& let Some((value, styles)) =
analyze_expr(ctx.world, &prev_prev).into_iter().next()
{
ctx.from = ctx.leaf.offset();
field_access_completions(ctx, &value, &styles);
@ -498,7 +499,8 @@ fn complete_open_labels(ctx: &mut CompletionContext) -> bool {
fn complete_imports(ctx: &mut CompletionContext) -> bool {
// In an import path for a file or package:
// "#import "|",
if let Some(SyntaxKind::ModuleImport | SyntaxKind::ModuleInclude) = ctx.leaf.parent_kind()
if let Some(SyntaxKind::ModuleImport | SyntaxKind::ModuleInclude) =
ctx.leaf.parent_kind()
&& let Some(ast::Expr::Str(str)) = ctx.leaf.cast()
{
let value = str.get();
@ -662,8 +664,7 @@ fn show_rule_recipe_completions(ctx: &mut CompletionContext) {
/// Complete call and set rule parameters.
fn complete_params(ctx: &mut CompletionContext) -> bool {
// Ensure that we are in a function call or set rule's argument list.
let (callee, set, args, args_linked) =
if let Some(parent) = ctx.leaf.parent()
let (callee, set, args, args_linked) = if let Some(parent) = ctx.leaf.parent()
&& let Some(parent) = match parent.kind() {
SyntaxKind::Named => parent.parent(),
_ => Some(parent),
@ -676,8 +677,7 @@ fn complete_params(ctx: &mut CompletionContext) -> bool {
ast::Expr::FuncCall(call) => Some(call.callee()),
ast::Expr::SetRule(set) => Some(set.target()),
_ => None,
}
{
} {
(callee, set, args, parent)
} else {
return false;
@ -1355,8 +1355,10 @@ impl<'a> CompletionContext<'a> {
}
} else if at {
apply = Some(eco_format!("at(\"{label}\")"));
} else if label.starts_with('"') && self.after.starts_with('"')
&& let Some(trimmed) = label.strip_suffix('"') {
} else if label.starts_with('"')
&& self.after.starts_with('"')
&& let Some(trimmed) = label.strip_suffix('"')
{
apply = Some(trimmed.into());
}
@ -1543,7 +1545,7 @@ mod tests {
use typst::layout::PagedDocument;
use super::{autocomplete, Completion, CompletionKind};
use super::{Completion, CompletionKind, autocomplete};
use crate::tests::{FilePos, TestWorld, WorldLike};
/// Quote a string.

View File

@ -1,12 +1,12 @@
use typst::foundations::{Label, Selector, Value};
use typst::layout::PagedDocument;
use typst::syntax::{ast, LinkedNode, Side, Source, Span};
use typst::syntax::{LinkedNode, Side, Source, Span, ast};
use typst::utils::PicoStr;
use crate::utils::globals;
use crate::{
analyze_expr, analyze_import, deref_target, named_items, DerefTarget, IdeWorld,
NamedItem,
DerefTarget, IdeWorld, NamedItem, analyze_expr, analyze_import, deref_target,
named_items,
};
/// A definition of some item.
@ -90,11 +90,11 @@ mod tests {
use std::borrow::Borrow;
use std::ops::Range;
use typst::WorldExt;
use typst::foundations::{IntoValue, NativeElement};
use typst::syntax::Side;
use typst::WorldExt;
use super::{definition, Definition};
use super::{Definition, definition};
use crate::tests::{FilePos, TestWorld, WorldLike};
type Response = (TestWorld, Option<Definition>);

View File

@ -1,10 +1,10 @@
use std::num::NonZeroUsize;
use typst::WorldExt;
use typst::layout::{Frame, FrameItem, PagedDocument, Point, Position, Size};
use typst::model::{Destination, Url};
use typst::syntax::{FileId, LinkedNode, Side, Source, Span, SyntaxKind};
use typst::visualize::{Curve, CurveItem, FillRule, Geometry};
use typst::WorldExt;
use crate::IdeWorld;
@ -37,7 +37,8 @@ pub fn jump_from_click(
// Try to find a link first.
for (pos, item) in frame.items() {
if let FrameItem::Link(dest, size) = item
&& is_in_rect(*pos, *size, click) {
&& is_in_rect(*pos, *size, click)
{
return Some(match dest {
Destination::Url(url) => Jump::Url(url.clone()),
Destination::Position(pos) => Jump::Position(*pos),
@ -54,7 +55,8 @@ pub fn jump_from_click(
FrameItem::Group(group) => {
let pos = click - pos;
if let Some(clip) = &group.clip
&& !clip.contains(FillRule::NonZero, pos) {
&& !clip.contains(FillRule::NonZero, pos)
{
continue;
}
// Realistic transforms should always be invertible.
@ -177,7 +179,8 @@ pub fn jump_from_cursor(
fn find_in_frame(frame: &Frame, span: Span) -> Option<Point> {
for &(mut pos, ref item) in frame.items() {
if let FrameItem::Group(group) = item
&& let Some(point) = find_in_frame(&group.frame, span) {
&& let Some(point) = find_in_frame(&group.frame, span)
{
return Some(pos + point.transform(group.transform));
}
@ -219,7 +222,7 @@ mod tests {
use typst::layout::{Abs, Point, Position};
use super::{jump_from_click, jump_from_cursor, Jump};
use super::{Jump, jump_from_click, jump_from_cursor};
use crate::tests::{FilePos, TestWorld, WorldLike};
fn point(x: f64, y: f64) -> Point {

View File

@ -9,16 +9,16 @@ mod tooltip;
mod utils;
pub use self::analyze::{analyze_expr, analyze_import, analyze_labels};
pub use self::complete::{autocomplete, Completion, CompletionKind};
pub use self::definition::{definition, Definition};
pub use self::jump::{jump_from_click, jump_from_cursor, Jump};
pub use self::matchers::{deref_target, named_items, DerefTarget, NamedItem};
pub use self::tooltip::{tooltip, Tooltip};
pub use self::complete::{Completion, CompletionKind, autocomplete};
pub use self::definition::{Definition, definition};
pub use self::jump::{Jump, jump_from_click, jump_from_cursor};
pub use self::matchers::{DerefTarget, NamedItem, deref_target, named_items};
pub use self::tooltip::{Tooltip, tooltip};
use ecow::EcoString;
use typst::syntax::package::PackageSpec;
use typst::syntax::FileId;
use typst::World;
use typst::syntax::FileId;
use typst::syntax::package::PackageSpec;
/// Extends the `World` for IDE functionality.
pub trait IdeWorld: World {

View File

@ -1,9 +1,9 @@
use ecow::EcoString;
use typst::foundations::{Module, Value};
use typst::syntax::ast::AstNode;
use typst::syntax::{ast, LinkedNode, Span, SyntaxKind};
use typst::syntax::{LinkedNode, Span, SyntaxKind, ast};
use crate::{analyze_import, IdeWorld};
use crate::{IdeWorld, analyze_import};
/// Find the named items starting from the given position.
pub fn named_items<T>(
@ -60,7 +60,8 @@ pub fn named_items<T>(
// Seeing the module itself.
if let Some((name, span)) = name_and_span
&& let Some(res) = recv(NamedItem::Module(&name, span, module)) {
&& let Some(res) = recv(NamedItem::Module(&name, span, module))
{
return Some(res);
}
@ -124,7 +125,8 @@ pub fn named_items<T>(
if let Some(parent) = node.parent() {
if let Some(v) = parent.cast::<ast::ForLoop>()
&& node.prev_sibling_kind() != Some(SyntaxKind::In) {
&& node.prev_sibling_kind() != Some(SyntaxKind::In)
{
let pattern = v.pattern();
for ident in pattern.bindings() {
if let Some(res) = recv(NamedItem::Var(ident)) {
@ -154,7 +156,8 @@ pub fn named_items<T>(
}
ast::Param::Spread(s) => {
if let Some(sink_ident) = s.sink_ident()
&& let Some(t) = recv(NamedItem::Var(sink_ident)) {
&& let Some(t) = recv(NamedItem::Var(sink_ident))
{
return Some(t);
}
}

View File

@ -9,7 +9,7 @@ use typst::layout::{Abs, Margin, PageElem};
use typst::syntax::package::{PackageSpec, PackageVersion};
use typst::syntax::{FileId, Source, VirtualPath};
use typst::text::{Font, FontBook, TextElem, TextSize};
use typst::utils::{singleton, LazyHash};
use typst::utils::{LazyHash, singleton};
use typst::{Feature, Library, LibraryExt, World};
use crate::IdeWorld;

View File

@ -1,16 +1,16 @@
use std::fmt::Write;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use typst::engine::Sink;
use typst::foundations::{repr, Binding, Capturer, CastInfo, Repr, Value};
use typst::foundations::{Binding, Capturer, CastInfo, Repr, Value, repr};
use typst::layout::{Length, PagedDocument};
use typst::syntax::ast::AstNode;
use typst::syntax::{ast, LinkedNode, Side, Source, SyntaxKind};
use typst::utils::{round_with_precision, Numeric};
use typst::syntax::{LinkedNode, Side, Source, SyntaxKind, ast};
use typst::utils::{Numeric, round_with_precision};
use typst_eval::CapturesVisitor;
use crate::utils::{plain_docs_sentence, summarize_font_family};
use crate::{analyze_expr, analyze_import, analyze_labels, IdeWorld};
use crate::{IdeWorld, analyze_expr, analyze_import, analyze_labels};
/// Describe the item under the cursor.
///
@ -66,7 +66,8 @@ fn expr_tooltip(world: &dyn IdeWorld, leaf: &LinkedNode) -> Option<Tooltip> {
}
if let &Value::Length(length) = value
&& let Some(tooltip) = length_tooltip(length) {
&& let Some(tooltip) = length_tooltip(length)
{
return Some(tooltip);
}
}
@ -92,7 +93,8 @@ fn expr_tooltip(world: &dyn IdeWorld, leaf: &LinkedNode) -> Option<Tooltip> {
}
if let Some((_, count)) = last
&& count > 1 {
&& count > 1
{
write!(pieces.last_mut().unwrap(), " (×{count})").unwrap();
}
@ -256,7 +258,6 @@ fn font_tooltip(world: &dyn IdeWorld, leaf: &LinkedNode) -> Option<Tooltip> {
.book()
.families()
.find(|&(family, _)| family.to_lowercase().as_str() == lower.as_str())
{
let detail = summarize_font_family(iter.collect());
return Some(Tooltip::Text(detail));
@ -271,7 +272,7 @@ mod tests {
use typst::syntax::Side;
use super::{tooltip, Tooltip};
use super::{Tooltip, tooltip};
use crate::tests::{FilePos, TestWorld, WorldLike};
type Response = Option<Tooltip>;

View File

@ -2,7 +2,7 @@ use std::fmt::Write;
use std::ops::ControlFlow;
use comemo::Track;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use typst::engine::{Engine, Route, Sink, Traced};
use typst::foundations::{Scope, Value};
use typst::introspection::Introspector;
@ -119,11 +119,7 @@ pub fn globals<'a>(world: &'a dyn IdeWorld, leaf: &LinkedNode) -> &'a Scope {
.is_none_or(|prev| !matches!(prev.kind(), SyntaxKind::Hash));
let library = world.library();
if in_math {
library.math.scope()
} else {
library.global.scope()
}
if in_math { library.math.scope() } else { library.global.scope() }
}
/// Checks whether the given value or any of its constituent parts satisfy the

View File

@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
use ecow::eco_format;
use once_cell::sync::OnceCell;
use serde::Deserialize;
use typst_library::diag::{bail, PackageError, PackageResult, StrResult};
use typst_library::diag::{PackageError, PackageResult, StrResult, bail};
use typst_syntax::package::{PackageSpec, PackageVersion, VersionlessPackageSpec};
use crate::download::{Downloader, Progress};
@ -189,7 +189,7 @@ impl PackageStorage {
}
}
Err(err) => {
return Err(PackageError::NetworkFailed(Some(eco_format!("{err}"))))
return Err(PackageError::NetworkFailed(Some(eco_format!("{err}"))));
}
};

View File

@ -408,7 +408,8 @@ fn distribute<'a>(
// last region (it will overflow, but there's nothing else
// we can do).
if !remaining.approx_empty()
&& let Some(last) = buf.last_mut() {
&& let Some(last) = buf.last_mut()
{
*last += remaining;
}

View File

@ -2,10 +2,11 @@ use std::cell::{LazyCell, RefCell};
use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;
use bumpalo::boxed::Box as BumpBox;
use bumpalo::Bump;
use bumpalo::boxed::Box as BumpBox;
use comemo::{Track, Tracked, TrackedMut};
use typst_library::diag::{bail, warning, SourceResult};
use typst_library::World;
use typst_library::diag::{SourceResult, bail, warning};
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Packed, Resolve, Smart, StyleChain};
use typst_library::introspection::{
@ -19,10 +20,9 @@ use typst_library::layout::{
use typst_library::model::ParElem;
use typst_library::routines::{Pair, Routines};
use typst_library::text::TextElem;
use typst_library::World;
use typst_utils::SliceExt;
use super::{layout_multi_block, layout_single_block, FlowMode};
use super::{FlowMode, layout_multi_block, layout_single_block};
use crate::inline::ParSituation;
use crate::modifiers::layout_and_modify;
@ -685,7 +685,8 @@ impl<T> CachedCell<T> {
let mut slot = self.0.borrow_mut();
if let Some((hash, output)) = &*slot
&& *hash == input_hash {
&& *hash == input_hash
{
return output.clone();
}

View File

@ -18,7 +18,7 @@ use typst_syntax::Span;
use typst_utils::{NonZeroExt, Numeric};
use super::{
distribute, Config, FlowMode, FlowResult, LineNumberConfig, PlacedChild, Stop, Work,
Config, FlowMode, FlowResult, LineNumberConfig, PlacedChild, Stop, Work, distribute,
};
/// Composes the contents of a single page/region. A region can have multiple
@ -319,11 +319,7 @@ impl<'a, 'b> Composer<'a, 'b, '_, '_> {
let used = base.y - remaining;
let half = need / 2.0;
let ratio = (used + half) / base.y;
if ratio <= 0.5 {
FixedAlignment::Start
} else {
FixedAlignment::End
}
if ratio <= 0.5 { FixedAlignment::Start } else { FixedAlignment::End }
});
// Select the insertion area where we'll put this float.

View File

@ -14,7 +14,8 @@ use std::rc::Rc;
use bumpalo::Bump;
use comemo::{Track, Tracked, TrackedMut};
use ecow::EcoVec;
use typst_library::diag::{bail, At, SourceDiagnostic, SourceResult};
use typst_library::World;
use typst_library::diag::{At, SourceDiagnostic, SourceResult, bail};
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Content, Packed, Resolve, StyleChain};
use typst_library::introspection::{
@ -27,14 +28,13 @@ use typst_library::layout::{
use typst_library::model::{FootnoteElem, FootnoteEntry, LineNumberingScope, ParLine};
use typst_library::routines::{Arenas, FragmentKind, Pair, RealizationKind, Routines};
use typst_library::text::TextElem;
use typst_library::World;
use typst_utils::{NonZeroExt, Numeric};
use self::block::{layout_multi_block, layout_single_block};
use self::collect::{
collect, Child, LineChild, MultiChild, MultiSpill, PlacedChild, SingleChild,
Child, LineChild, MultiChild, MultiSpill, PlacedChild, SingleChild, collect,
};
use self::compose::{compose, Composer};
use self::compose::{Composer, compose};
use self::distribute::distribute;
/// Lays out content into a single region, producing a single frame.

View File

@ -1,6 +1,6 @@
use std::fmt::Debug;
use typst_library::diag::{bail, SourceResult};
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{Resolve, StyleChain};
use typst_library::layout::grid::resolve::{
@ -16,8 +16,8 @@ use typst_syntax::Span;
use typst_utils::Numeric;
use super::{
generate_line_segments, hline_stroke_at_column, layout_cell, vline_stroke_at_row,
LineSegment, Rowspan, UnbreakableRowGroup,
LineSegment, Rowspan, UnbreakableRowGroup, generate_line_segments,
hline_stroke_at_column, layout_cell, vline_stroke_at_row,
};
/// Performs grid layout.
@ -275,7 +275,8 @@ impl<'a> GridLayouter<'a> {
self.measure_columns(engine)?;
if let Some(footer) = &self.grid.footer
&& footer.repeated {
&& footer.repeated
{
// Ensure rows in the first region will be aware of the
// possible presence of the footer.
self.prepare_footer(footer, engine, 0)?;
@ -287,7 +288,8 @@ impl<'a> GridLayouter<'a> {
let mut consecutive_header_count = 0;
while y < self.grid.rows.len() {
if let Some(next_header) = self.upcoming_headers.get(consecutive_header_count)
&& next_header.range.contains(&y) {
&& next_header.range.contains(&y)
{
self.place_new_headers(&mut consecutive_header_count, engine)?;
y = next_header.range.end;
@ -296,7 +298,9 @@ impl<'a> GridLayouter<'a> {
}
if let Some(footer) = &self.grid.footer
&& footer.repeated && y >= footer.start {
&& footer.repeated
&& y >= footer.start
{
if y == footer.start {
self.layout_footer(footer, engine, self.finished.len())?;
self.flush_orphans();
@ -1524,7 +1528,8 @@ impl<'a> GridLayouter<'a> {
// were placed, so remove those rows and try again in a new region,
// unless this is the last region.
if let Some(orphan_snapshot) = self.current.lrows_orphan_snapshot.take()
&& !last {
&& !last
{
self.current.lrows.truncate(orphan_snapshot);
self.current.repeated_header_rows =
self.current.repeated_header_rows.min(orphan_snapshot);
@ -1564,8 +1569,7 @@ impl<'a> GridLayouter<'a> {
&& self.current.could_progress_at_top;
let mut laid_out_footer_start = None;
if !footer_would_be_widow
&& let Some(footer) = &self.grid.footer {
if !footer_would_be_widow && let Some(footer) = &self.grid.footer {
// Don't layout the footer if it would be alone with the header
// in the page (hence the widow check), and don't layout it
// twice (check below).

View File

@ -1,8 +1,8 @@
use std::sync::Arc;
use typst_library::foundations::{AlternativeFold, Fold};
use typst_library::layout::grid::resolve::{CellGrid, Line, Repeatable};
use typst_library::layout::Abs;
use typst_library::layout::grid::resolve::{CellGrid, Line, Repeatable};
use typst_library::visualize::Stroke;
use super::RowPiece;
@ -292,7 +292,8 @@ pub fn vline_stroke_at_row(
// column), and/or one row below (if at a gutter row), in order to
// check if it would be merged with a cell before the vline.
if let Some(parent) = grid.effective_parent_cell_position(x, y)
&& parent.x < x {
&& parent.x < x
{
// There is a colspan cell going through this vline's position,
// so don't draw it here.
return None;
@ -416,7 +417,8 @@ pub fn hline_stroke_at_column(
// column), and/or one row below (if at a gutter row), in order to
// check if it would be merged with a cell before the hline.
if let Some(parent) = grid.effective_parent_cell_position(x, y)
&& parent.y < y {
&& parent.y < y
{
// Get the first 'y' spanned by the possible rowspan in this region.
// The 'parent.y' row and any other spanned rows above 'y' could be
// missing from this region, which could have lead the check above

View File

@ -9,13 +9,13 @@ use typst_library::diag::SourceResult;
use typst_library::engine::Engine;
use typst_library::foundations::{Packed, StyleChain};
use typst_library::introspection::Locator;
use typst_library::layout::grid::resolve::{grid_to_cellgrid, table_to_cellgrid, Cell};
use typst_library::layout::grid::resolve::{Cell, grid_to_cellgrid, table_to_cellgrid};
use typst_library::layout::{Fragment, GridElem, Regions};
use typst_library::model::TableElem;
use self::layouter::RowPiece;
use self::lines::{
generate_line_segments, hline_stroke_at_column, vline_stroke_at_row, LineSegment,
LineSegment, generate_line_segments, hline_stroke_at_column, vline_stroke_at_row,
};
use self::rowspans::{Rowspan, UnbreakableRowGroup};

View File

@ -241,7 +241,9 @@ impl<'a> GridLayouter<'a> {
}
if let Some(footer) = &self.grid.footer
&& footer.repeated && skipped_region {
&& footer.repeated
&& skipped_region
{
// Simulate the footer again; the region's 'full' might have
// changed.
self.regions.size.y += self.current.footer_height;

View File

@ -4,8 +4,8 @@ use typst_library::foundations::Resolve;
use typst_library::layout::grid::resolve::Repeatable;
use typst_library::layout::{Abs, Axes, Frame, Point, Region, Regions, Size, Sizing};
use super::layouter::{points, Row};
use super::{layout_cell, Cell, GridLayouter};
use super::layouter::{Row, points};
use super::{Cell, GridLayouter, layout_cell};
/// All information needed to layout a single rowspan.
pub struct Rowspan {
@ -239,7 +239,9 @@ impl GridLayouter<'_> {
// unbreakable cells (with or without a rowspan setting).
let mut amount_unbreakable_rows = None;
if let Some(footer) = &self.grid.footer
&& !footer.repeated && current_row >= footer.start {
&& !footer.repeated
&& current_row >= footer.start
{
// Non-repeated footer, so keep it unbreakable.
//
// TODO(subfooters): This will become unnecessary
@ -1268,7 +1270,8 @@ fn subtract_end_sizes(sizes: &mut Vec<Abs>, mut subtract: Abs) {
subtract -= sizes.pop().unwrap();
}
if subtract > Abs::zero()
&& let Some(last_size) = sizes.last_mut() {
&& let Some(last_size) = sizes.last_mut()
{
*last_size -= subtract;
}
}

View File

@ -6,14 +6,14 @@ use typst_library::layout::{
};
use typst_library::routines::Pair;
use typst_library::text::{
is_default_ignorable, LinebreakElem, SmartQuoteElem, SmartQuoter, SmartQuotes,
SpaceElem, TextElem,
LinebreakElem, SmartQuoteElem, SmartQuoter, SmartQuotes, SpaceElem, TextElem,
is_default_ignorable,
};
use typst_syntax::Span;
use typst_utils::Numeric;
use super::*;
use crate::modifiers::{layout_and_modify, FrameModifiers, FrameModify};
use crate::modifiers::{FrameModifiers, FrameModify, layout_and_modify};
// The characters by which spacing, inline content and pins are replaced in the
// full text.
@ -275,7 +275,8 @@ impl<'a> Collector<'a> {
// Merge adjacent text segments with the same styles.
if let Some(Segment::Text(last_len, last_styles)) = self.segments.last_mut()
&& *last_styles == styles {
&& *last_styles == styles
{
*last_len += segment_len;
return;
}

View File

@ -6,7 +6,7 @@ use typst_library::foundations::Resolve;
use typst_library::introspection::{SplitLocator, Tag};
use typst_library::layout::{Abs, Dir, Em, Fr, Frame, FrameItem, Point};
use typst_library::model::ParLineMarker;
use typst_library::text::{variant, Lang, TextElem};
use typst_library::text::{Lang, TextElem, variant};
use typst_utils::Numeric;
use super::*;
@ -156,13 +156,15 @@ pub fn line<'a>(
// Add a hyphen at the line start, if a previous dash should be repeated.
if pred.is_some_and(|pred| should_repeat_hyphen(pred, full))
&& let Some(shaped) = items.first_text_mut() {
&& let Some(shaped) = items.first_text_mut()
{
shaped.prepend_hyphen(engine, p.config.fallback);
}
// Add a hyphen at the line end, if we ended on a soft hyphen.
if dash == Some(Dash::Soft)
&& let Some(shaped) = items.last_text_mut() {
&& let Some(shaped) = items.last_text_mut()
{
shaped.push_hyphen(engine, p.config.fallback);
}
@ -217,7 +219,8 @@ fn collect_items<'a>(
// Add fallback text to expand the line height, if necessary.
if !items.iter().any(|item| matches!(item, Item::Text(_)))
&& let Some(fallback) = fallback {
&& let Some(fallback) = fallback
{
items.push(fallback, usize::MAX);
}

View File

@ -2,8 +2,8 @@ use std::ops::{Add, Sub};
use std::sync::LazyLock;
use az::SaturatingAs;
use icu_properties::maps::{CodePointMapData, CodePointMapDataBorrowed};
use icu_properties::LineBreak;
use icu_properties::maps::{CodePointMapData, CodePointMapDataBorrowed};
use icu_provider::AsDeserializingBufferProvider;
use icu_provider_adapters::fork::ForkByKeyProvider;
use icu_provider_blob::BlobDataProvider;
@ -11,7 +11,7 @@ use icu_segmenter::LineSegmenter;
use typst_library::engine::Engine;
use typst_library::layout::{Abs, Em};
use typst_library::model::Linebreaks;
use typst_library::text::{is_default_ignorable, Lang, TextElem};
use typst_library::text::{Lang, TextElem, is_default_ignorable};
use typst_syntax::link_prefix;
use unicode_segmentation::UnicodeSegmentation;
@ -137,7 +137,8 @@ fn linebreak_simple<'a>(
// into the stack and rebuild the line from the attempt's end. The
// resulting line cannot be broken up further.
if !width.fits(attempt.width)
&& let Some((last_attempt, last_end)) = last.take() {
&& let Some((last_attempt, last_end)) = last.take()
{
lines.push(last_attempt);
start = last_end;
attempt = line(engine, p, start..end, breakpoint, lines.last());
@ -893,11 +894,7 @@ impl CostMetrics {
/// we allow less because otherwise we get an invalid layout fairly often,
/// which makes our bound useless.
fn min_ratio(&self, approx: bool) -> f64 {
if approx {
self.min_approx_ratio
} else {
self.min_ratio
}
if approx { self.min_approx_ratio } else { self.min_ratio }
}
}

View File

@ -12,6 +12,7 @@ pub use self::box_::layout_box;
pub use self::shaping::create_shape_plan;
use comemo::{Track, Tracked, TrackedMut};
use typst_library::World;
use typst_library::diag::SourceResult;
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Packed, Smart, StyleChain};
@ -23,18 +24,17 @@ use typst_library::model::{
};
use typst_library::routines::{Arenas, Pair, RealizationKind, Routines};
use typst_library::text::{Costs, Lang, TextElem};
use typst_library::World;
use typst_utils::{Numeric, SliceExt};
use self::collect::{collect, Item, Segment, SpanMapper};
use self::collect::{Item, Segment, SpanMapper, collect};
use self::deco::decorate;
use self::finalize::finalize;
use self::line::{apply_shift, commit, line, Line};
use self::linebreak::{linebreak, Breakpoint};
use self::prepare::{prepare, Preparation};
use self::line::{Line, apply_shift, commit, line};
use self::linebreak::{Breakpoint, linebreak};
use self::prepare::{Preparation, prepare};
use self::shaping::{
cjk_punct_style, is_of_cj_script, shape_range, ShapedGlyph, ShapedText,
BEGIN_PUNCT_PAT, END_PUNCT_PAT,
BEGIN_PUNCT_PAT, END_PUNCT_PAT, ShapedGlyph, ShapedText, cjk_punct_style,
is_of_cj_script, shape_range,
};
/// Range of a substring of text.
@ -190,11 +190,7 @@ fn configuration(
Config {
justify,
linebreaks: base.linebreaks.unwrap_or_else(|| {
if justify {
Linebreaks::Optimized
} else {
Linebreaks::Simple
}
if justify { Linebreaks::Optimized } else { Linebreaks::Simple }
}),
first_line_indent: {
let FirstLineIndent { amount, all } = base.first_line_indent;

View File

@ -4,21 +4,21 @@ use std::sync::Arc;
use az::SaturatingAs;
use rustybuzz::{BufferFlags, Feature, ShapePlan, UnicodeBuffer};
use ttf_parser::gsub::SubstitutionSubtable;
use ttf_parser::Tag;
use ttf_parser::gsub::SubstitutionSubtable;
use typst_library::World;
use typst_library::engine::Engine;
use typst_library::foundations::{Smart, StyleChain};
use typst_library::layout::{Abs, Dir, Em, Frame, FrameItem, Point, Size};
use typst_library::text::{
families, features, is_default_ignorable, language, variant, Font, FontFamily,
FontVariant, Glyph, Lang, Region, ShiftSettings, TextEdgeBounds, TextElem, TextItem,
Font, FontFamily, FontVariant, Glyph, Lang, Region, ShiftSettings, TextEdgeBounds,
TextElem, TextItem, families, features, is_default_ignorable, language, variant,
};
use typst_library::World;
use typst_utils::SliceExt;
use unicode_bidi::{BidiInfo, Level as BidiLevel};
use unicode_script::{Script, UnicodeScript};
use super::{decorate, Item, Range, SpanMapper};
use super::{Item, Range, SpanMapper, decorate};
use crate::modifiers::FrameModifyText;
/// The result of shaping text.
@ -539,11 +539,7 @@ impl<'a> ShapedText<'a> {
// Find any glyph with the text index.
let found = self.glyphs.binary_search_by(|g: &ShapedGlyph| {
let ordering = g.range.start.cmp(&text_index);
if ltr {
ordering
} else {
ordering.reverse()
}
if ltr { ordering } else { ordering.reverse() }
});
let mut idx = match found {

View File

@ -24,11 +24,7 @@ pub fn layout_list(
let body_indent = elem.body_indent.get(styles);
let tight = elem.tight.get(styles);
let gutter = elem.spacing.get(styles).unwrap_or_else(|| {
if tight {
styles.get(ParElem::leading)
} else {
styles.get(ParElem::spacing)
}
if tight { styles.get(ParElem::leading) } else { styles.get(ParElem::spacing) }
});
let Depth(depth) = styles.get(ListElem::depth);
@ -88,22 +84,15 @@ pub fn layout_enum(
let body_indent = elem.body_indent.get(styles);
let tight = elem.tight.get(styles);
let gutter = elem.spacing.get(styles).unwrap_or_else(|| {
if tight {
styles.get(ParElem::leading)
} else {
styles.get(ParElem::spacing)
}
if tight { styles.get(ParElem::leading) } else { styles.get(ParElem::spacing) }
});
let mut cells = vec![];
let mut locator = locator.split();
let mut number = elem.start.get(styles).unwrap_or_else(|| {
if reversed {
elem.children.len() as u64
} else {
1
}
});
let mut number = elem
.start
.get(styles)
.unwrap_or_else(|| if reversed { elem.children.len() as u64 } else { 1 });
let mut parents = styles.get_cloned(EnumElem::parents);
let full = elem.full.get(styles);

View File

@ -4,8 +4,8 @@ use typst_library::layout::{Em, Frame, Point, Size};
use typst_library::math::AccentElem;
use super::{
style_cramped, style_dtls, style_flac, FrameFragment, GlyphFragment, MathContext,
MathFragment,
FrameFragment, GlyphFragment, MathContext, MathFragment, style_cramped, style_dtls,
style_flac,
};
/// How much the accent can be shorter than the base.

View File

@ -7,8 +7,8 @@ use typst_library::math::{
use typst_utils::OptionExt;
use super::{
stretch_fragment, style_for_subscript, style_for_superscript, FrameFragment, Limits,
MathContext, MathFragment,
FrameFragment, Limits, MathContext, MathFragment, stretch_fragment,
style_for_subscript, style_for_superscript,
};
macro_rules! measure {

View File

@ -7,8 +7,8 @@ use typst_library::visualize::{FixedStroke, Geometry};
use typst_syntax::Span;
use super::{
style_for_denominator, style_for_numerator, FrameFragment, GlyphFragment,
MathContext, DELIM_SHORT_FALL,
DELIM_SHORT_FALL, FrameFragment, GlyphFragment, MathContext, style_for_denominator,
style_for_numerator,
};
const FRAC_AROUND: Em = Em::new(0.1);

View File

@ -2,18 +2,18 @@ use std::fmt::{self, Debug, Formatter};
use az::SaturatingAs;
use rustybuzz::{BufferFlags, UnicodeBuffer};
use ttf_parser::math::{GlyphAssembly, GlyphConstruction, GlyphPart};
use ttf_parser::GlyphId;
use typst_library::diag::{bail, warning, SourceResult};
use ttf_parser::math::{GlyphAssembly, GlyphConstruction, GlyphPart};
use typst_library::diag::{SourceResult, bail, warning};
use typst_library::foundations::StyleChain;
use typst_library::introspection::Tag;
use typst_library::layout::{
Abs, Axes, Axis, Corner, Em, Frame, FrameItem, Point, Size, VAlignment,
};
use typst_library::math::{EquationElem, MathSize};
use typst_library::text::{features, language, Font, Glyph, TextElem, TextItem};
use typst_library::text::{Font, Glyph, TextElem, TextItem, features, language};
use typst_syntax::Span;
use typst_utils::{default_math_class, Get};
use typst_utils::{Get, default_math_class};
use unicode_math_class::MathClass;
use super::MathContext;
@ -681,7 +681,11 @@ fn min_connector_overlap(font: &Font) -> Option<Em> {
.map(|variants| font.to_em(variants.min_connector_overlap))
}
fn glyph_construction(font: &Font, id: GlyphId, axis: Axis) -> Option<GlyphConstruction<'_>> {
fn glyph_construction(
font: &Font,
id: GlyphId,
axis: Axis,
) -> Option<GlyphConstruction<'_>> {
font.ttf()
.tables()
.math?
@ -810,7 +814,10 @@ fn assemble(
/// Return an iterator over the assembly's parts with extenders repeated the
/// specified number of times.
fn parts(assembly: GlyphAssembly<'_>, repeat: usize) -> impl Iterator<Item = GlyphPart> + '_ {
fn parts(
assembly: GlyphAssembly<'_>,
repeat: usize,
) -> impl Iterator<Item = GlyphPart> + '_ {
assembly.parts.into_iter().flat_map(move |part| {
let count = if part.part_flags.extender() { repeat } else { 1 };
std::iter::repeat_n(part, count)

View File

@ -5,7 +5,7 @@ use typst_library::math::{EquationElem, LrElem, MidElem};
use typst_utils::SliceExt;
use unicode_math_class::MathClass;
use super::{stretch_fragment, MathContext, MathFragment, DELIM_SHORT_FALL};
use super::{DELIM_SHORT_FALL, MathContext, MathFragment, stretch_fragment};
/// Lays out an [`LrElem`].
#[typst_macros::time(name = "math.lr", span = elem.span())]
@ -22,7 +22,8 @@ pub fn layout_lr(
// Extract implicit LrElem.
if let Some(lr) = body.to_packed::<LrElem>()
&& lr.size.get(styles).is_one() {
&& lr.size.get(styles).is_one()
{
body = &lr.body;
}
@ -55,7 +56,8 @@ pub fn layout_lr(
// Handle MathFragment::Glyph fragments that should be scaled up.
for fragment in inner_fragments.iter_mut() {
if let MathFragment::Glyph(glyph) = fragment
&& glyph.mid_stretched == Some(false) {
&& glyph.mid_stretched == Some(false)
{
glyph.mid_stretched = Some(true);
scale(ctx, fragment, relative_to, height);
}

View File

@ -1,4 +1,4 @@
use typst_library::diag::{bail, warning, SourceResult};
use typst_library::diag::{SourceResult, bail, warning};
use typst_library::foundations::{Content, Packed, Resolve, StyleChain};
use typst_library::layout::{
Abs, Axes, Em, FixedAlignment, Frame, FrameItem, Point, Ratio, Rel, Size,
@ -9,8 +9,8 @@ use typst_library::visualize::{FillRule, FixedStroke, Geometry, LineCap, Shape};
use typst_syntax::Span;
use super::{
alignments, style_for_denominator, AlignmentResult, FrameFragment, GlyphFragment,
LeftRightAlternator, MathContext, DELIM_SHORT_FALL,
AlignmentResult, DELIM_SHORT_FALL, FrameFragment, GlyphFragment, LeftRightAlternator,
MathContext, alignments, style_for_denominator,
};
const VERTICAL_PADDING: Ratio = Ratio::new(0.1);

View File

@ -13,7 +13,8 @@ mod stretch;
mod text;
mod underover;
use typst_library::diag::{bail, SourceResult};
use typst_library::World;
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{
Content, NativeElement, Packed, Resolve, StyleChain, SymbolElem,
@ -28,15 +29,14 @@ use typst_library::math::*;
use typst_library::model::ParElem;
use typst_library::routines::{Arenas, RealizationKind};
use typst_library::text::{
families, variant, Font, LinebreakElem, SpaceElem, TextEdgeBounds, TextElem,
Font, LinebreakElem, SpaceElem, TextEdgeBounds, TextElem, families, variant,
};
use typst_library::World;
use typst_syntax::Span;
use typst_utils::Numeric;
use unicode_math_class::MathClass;
use self::fragment::{
has_dtls_feat, stretch_axes, FrameFragment, GlyphFragment, Limits, MathFragment,
FrameFragment, GlyphFragment, Limits, MathFragment, has_dtls_feat, stretch_axes,
};
use self::run::{LeftRightAlternator, MathRun, MathRunFrameBuilder};
use self::shared::*;
@ -604,11 +604,9 @@ fn layout_h(
styles: StyleChain,
) -> SourceResult<()> {
if let Spacing::Rel(rel) = elem.amount
&& rel.rel.is_zero() {
ctx.push(MathFragment::Spacing(
rel.abs.resolve(styles),
elem.weak.get(styles),
));
&& rel.rel.is_zero()
{
ctx.push(MathFragment::Spacing(rel.abs.resolve(styles), elem.weak.get(styles)));
}
Ok(())
}

View File

@ -5,7 +5,7 @@ use typst_library::math::{EquationElem, MathSize, RootElem};
use typst_library::text::TextElem;
use typst_library::visualize::{FixedStroke, Geometry};
use super::{style_cramped, FrameFragment, GlyphFragment, MathContext};
use super::{FrameFragment, GlyphFragment, MathContext, style_cramped};
/// Lays out a [`RootElem`].
///

View File

@ -2,11 +2,11 @@ use std::iter::once;
use typst_library::foundations::{Resolve, StyleChain};
use typst_library::layout::{Abs, AlignElem, Em, Frame, InlineItem, Point, Size};
use typst_library::math::{EquationElem, MathSize, MEDIUM, THICK, THIN};
use typst_library::math::{EquationElem, MEDIUM, MathSize, THICK, THIN};
use typst_library::model::ParElem;
use unicode_math_class::MathClass;
use super::{alignments, FrameFragment, MathFragment};
use super::{FrameFragment, MathFragment, alignments};
const TIGHT_LEADING: Em = Em::new(0.25);
@ -88,7 +88,8 @@ impl MathRun {
// Insert spacing between the last and this non-ignorant item.
if !fragment.is_ignorant() {
if let Some(i) = last
&& let Some(s) = spacing(&resolved[i], space.take(), &fragment) {
&& let Some(s) = spacing(&resolved[i], space.take(), &fragment)
{
resolved.insert(i + 1, s);
}
@ -123,7 +124,8 @@ impl MathRun {
// A linebreak at the very end does not introduce an extra row.
if let Some(f) = self.0.last()
&& matches!(f, MathFragment::Linebreak) {
&& matches!(f, MathFragment::Linebreak)
{
count -= 1
}
count
@ -343,7 +345,8 @@ impl MathRun {
space_is_visible = true;
if let Some(f_next) = iter.peek()
&& !is_space(f_next) {
&& !is_space(f_next)
{
items.push(InlineItem::Space(Abs::zero(), true));
}
} else {

View File

@ -1,5 +1,5 @@
use ttf_parser::math::MathValue;
use ttf_parser::Tag;
use ttf_parser::math::MathValue;
use typst_library::foundations::{Style, StyleChain};
use typst_library::layout::{Abs, Em, FixedAlignment, Frame, Point, Size};
use typst_library::math::{EquationElem, MathSize};

View File

@ -1,10 +1,10 @@
use typst_library::diag::{warning, SourceResult};
use typst_library::diag::{SourceResult, warning};
use typst_library::foundations::{Packed, StyleChain};
use typst_library::layout::{Abs, Axis, Rel};
use typst_library::math::StretchElem;
use typst_utils::Get;
use super::{stretch_axes, MathContext, MathFragment};
use super::{MathContext, MathFragment, stretch_axes};
/// Lays out a [`StretchElem`].
#[typst_macros::time(name = "math.stretch", span = elem.span())]

View File

@ -1,6 +1,6 @@
use std::f64::consts::SQRT_2;
use codex::styling::{to_style, MathStyle};
use codex::styling::{MathStyle, to_style};
use ecow::EcoString;
use typst_library::diag::SourceResult;
use typst_library::foundations::{Packed, StyleChain, SymbolElem};
@ -9,13 +9,13 @@ use typst_library::math::{EquationElem, MathSize};
use typst_library::text::{
BottomEdge, BottomEdgeMetric, TextElem, TopEdge, TopEdgeMetric,
};
use typst_syntax::{is_newline, Span};
use typst_syntax::{Span, is_newline};
use unicode_math_class::MathClass;
use unicode_segmentation::UnicodeSegmentation;
use super::{
has_dtls_feat, style_dtls, FrameFragment, GlyphFragment, MathContext, MathFragment,
MathRun,
FrameFragment, GlyphFragment, MathContext, MathFragment, MathRun, has_dtls_feat,
style_dtls,
};
/// Lays out a [`TextElem`].

View File

@ -10,8 +10,8 @@ use typst_library::visualize::{FixedStroke, Geometry};
use typst_syntax::Span;
use super::{
stack, style_cramped, style_for_subscript, style_for_superscript, FrameFragment,
GlyphFragment, LeftRightAlternator, MathContext, MathRun,
FrameFragment, GlyphFragment, LeftRightAlternator, MathContext, MathRun, stack,
style_cramped, style_for_subscript, style_for_superscript,
};
const BRACE_GAP: Em = Em::new(0.25);

View File

@ -7,6 +7,7 @@ mod run;
use std::num::NonZeroUsize;
use comemo::{Tracked, TrackedMut};
use typst_library::World;
use typst_library::diag::SourceResult;
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Content, StyleChain};
@ -16,11 +17,10 @@ use typst_library::introspection::{
use typst_library::layout::{FrameItem, Page, PagedDocument, Point, Transform};
use typst_library::model::DocumentInfo;
use typst_library::routines::{Arenas, Pair, RealizationKind, Routines};
use typst_library::World;
use self::collect::{collect, Item};
use self::collect::{Item, collect};
use self::finalize::finalize;
use self::run::{layout_blank_page, layout_page_run, LayoutedPage};
use self::run::{LayoutedPage, layout_blank_page, layout_page_run};
/// Layout content into a document.
///

View File

@ -1,4 +1,5 @@
use comemo::{Track, Tracked, TrackedMut};
use typst_library::World;
use typst_library::diag::SourceResult;
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{
@ -16,10 +17,9 @@ use typst_library::model::Numbering;
use typst_library::routines::{Pair, Routines};
use typst_library::text::{LocalName, TextElem};
use typst_library::visualize::Paint;
use typst_library::World;
use typst_utils::Numeric;
use crate::flow::{layout_flow, FlowMode};
use crate::flow::{FlowMode, layout_flow};
/// A mostly finished layout for one page. Needs only knowledge of its exact
/// page number to be finalized into a `Page`. (Because the margins can depend

View File

@ -1,4 +1,4 @@
use typst_library::diag::{bail, SourceResult};
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{Packed, Resolve, StyleChain};
use typst_library::introspection::Locator;

View File

@ -1,12 +1,12 @@
use std::num::NonZeroUsize;
use comemo::Track;
use ecow::{eco_format, EcoVec};
use ecow::{EcoVec, eco_format};
use smallvec::smallvec;
use typst_library::diag::{bail, At, SourceResult};
use typst_library::diag::{At, SourceResult, bail};
use typst_library::foundations::{
dict, Content, Context, NativeElement, NativeRuleMap, Packed, Resolve, ShowFn, Smart,
StyleChain, Target,
Content, Context, NativeElement, NativeRuleMap, Packed, Resolve, ShowFn, Smart,
StyleChain, Target, dict,
};
use typst_library::introspection::{Counter, Locator, LocatorLink};
use typst_library::layout::{
@ -161,11 +161,7 @@ const TERMS_RULE: ShowFn<TermsElem> = |elem, _, styles| {
let indent = elem.indent.get(styles);
let hanging_indent = elem.hanging_indent.get(styles);
let gutter = elem.spacing.get(styles).unwrap_or_else(|| {
if tight {
styles.get(ParElem::leading)
} else {
styles.get(ParElem::spacing)
}
if tight { styles.get(ParElem::leading) } else { styles.get(ParElem::spacing) }
});
let pad = hanging_indent + indent;

View File

@ -1,7 +1,7 @@
use std::f64::consts::SQRT_2;
use kurbo::{CubicBez, ParamCurveExtrema};
use typst_library::diag::{bail, SourceResult};
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{Content, Packed, Resolve, Smart, StyleChain};
use typst_library::introspection::Locator;

View File

@ -1,4 +1,4 @@
use typst_library::diag::{bail, SourceResult};
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{Content, Packed, Resolve, StyleChain, StyledElem};
use typst_library::introspection::{Locator, SplitLocator};

View File

@ -1,6 +1,6 @@
use std::cell::LazyCell;
use typst_library::diag::{bail, SourceResult};
use typst_library::diag::{SourceResult, bail};
use typst_library::engine::Engine;
use typst_library::foundations::{Content, Packed, Resolve, Smart, StyleChain};
use typst_library::introspection::Locator;

View File

@ -8,7 +8,7 @@ use std::string::FromUtf8Error;
use az::SaturatingAs;
use comemo::Tracked;
use ecow::{eco_vec, EcoVec};
use ecow::{EcoVec, eco_vec};
use typst_syntax::package::{PackageSpec, PackageVersion};
use typst_syntax::{Lines, Span, Spanned, SyntaxError};
use utf8_iter::ErrorReportingUtf8Chars;
@ -838,7 +838,9 @@ pub fn format_xml_like_error(format: &str, error: roxmltree::Error) -> LoadError
let pos = LineCol::one_based(error.pos().row as usize, error.pos().col as usize);
let message = match error {
roxmltree::Error::UnexpectedCloseTag(expected, actual, _) => {
eco_format!("failed to parse {format} (found closing tag '{actual}' instead of '{expected}')")
eco_format!(
"failed to parse {format} (found closing tag '{actual}' instead of '{expected}')"
)
}
roxmltree::Error::UnknownEntityReference(entity, _) => {
eco_format!("failed to parse {format} (unknown entity '{entity}')")

View File

@ -8,11 +8,11 @@ use ecow::EcoVec;
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
use typst_syntax::{FileId, Span};
use crate::diag::{bail, HintedStrResult, SourceDiagnostic, SourceResult, StrResult};
use crate::World;
use crate::diag::{HintedStrResult, SourceDiagnostic, SourceResult, StrResult, bail};
use crate::foundations::{Styles, Value};
use crate::introspection::Introspector;
use crate::routines::Routines;
use crate::World;
/// Holds all data needed during compilation.
pub struct Engine<'a> {
@ -47,7 +47,11 @@ impl Engine<'_> {
}
/// Runs tasks on the engine in parallel.
pub fn parallelize<P, I, T, U, F>(&mut self, iter: P, f: F) -> impl Iterator<Item = U> + use<P, I, T, U, F>
pub fn parallelize<P, I, T, U, F>(
&mut self,
iter: P,
f: F,
) -> impl Iterator<Item = U> + use<P, I, T, U, F>
where
P: IntoIterator<IntoIter = I>,
I: Iterator<Item = T>,
@ -111,11 +115,7 @@ impl Traced {
/// We hide the span if it isn't in the given file so that only results for
/// the file with the traced span are invalidated.
pub fn get(&self, id: FileId) -> Option<Span> {
if self.0.and_then(Span::id) == Some(id) {
self.0
} else {
None
}
if self.0.and_then(Span::id) == Some(id) { self.0 } else { None }
}
}

View File

@ -1,12 +1,12 @@
use std::fmt::{self, Debug, Formatter};
use std::ops::Add;
use ecow::{eco_format, eco_vec, EcoString, EcoVec};
use ecow::{EcoString, EcoVec, eco_format, eco_vec};
use typst_syntax::{Span, Spanned};
use crate::diag::{bail, error, At, SourceDiagnostic, SourceResult, StrResult};
use crate::diag::{At, SourceDiagnostic, SourceResult, StrResult, bail, error};
use crate::foundations::{
cast, func, repr, scope, ty, Array, Dict, FromValue, IntoValue, Repr, Str, Value,
Array, Dict, FromValue, IntoValue, Repr, Str, Value, cast, func, repr, scope, ty,
};
/// Captured arguments to a function.

View File

@ -4,16 +4,16 @@ use std::num::{NonZeroI64, NonZeroUsize};
use std::ops::{Add, AddAssign};
use comemo::Tracked;
use ecow::{eco_format, EcoString, EcoVec};
use ecow::{EcoString, EcoVec, eco_format};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use typst_syntax::{Span, Spanned};
use crate::diag::{bail, At, HintedStrResult, SourceDiagnostic, SourceResult, StrResult};
use crate::diag::{At, HintedStrResult, SourceDiagnostic, SourceResult, StrResult, bail};
use crate::engine::Engine;
use crate::foundations::{
cast, func, ops, repr, scope, ty, Args, Bytes, CastInfo, Context, Dict, FromValue,
Func, IntoValue, Reflect, Repr, Str, Value, Version,
Args, Bytes, CastInfo, Context, Dict, FromValue, Func, IntoValue, Reflect, Repr, Str,
Value, Version, cast, func, ops, repr, scope, ty,
};
/// Create a new [`Array`] from values.

View File

@ -4,8 +4,8 @@ use ecow::EcoString;
use crate::diag::HintedStrResult;
use crate::foundations::{
ty, CastInfo, Fold, FromValue, IntoValue, Reflect, Repr, Resolve, StyleChain, Type,
Value,
CastInfo, Fold, FromValue, IntoValue, Reflect, Repr, Resolve, StyleChain, Type,
Value, ty,
};
/// A value that indicates a smart default.

View File

@ -1,6 +1,6 @@
use ecow::EcoString;
use crate::foundations::{ty, Repr};
use crate::foundations::{Repr, ty};
/// A type with two states.
///

View File

@ -5,13 +5,13 @@ use std::ops::{Add, AddAssign, Deref};
use std::str::Utf8Error;
use std::sync::Arc;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use serde::{Serialize, Serializer};
use typst_syntax::Lines;
use typst_utils::LazyHash;
use crate::diag::{bail, StrResult};
use crate::foundations::{cast, func, scope, ty, Array, Reflect, Repr, Str, Value};
use crate::diag::{StrResult, bail};
use crate::foundations::{Array, Reflect, Repr, Str, Value, cast, func, scope, ty};
/// A sequence of bytes.
///

View File

@ -7,8 +7,8 @@ use az::SaturatingAs;
use typst_syntax::{Span, Spanned};
use typst_utils::{round_int_with_precision, round_with_precision};
use crate::diag::{bail, At, HintedString, SourceResult, StrResult};
use crate::foundations::{cast, func, ops, Decimal, IntoValue, Module, Scope, Value};
use crate::diag::{At, HintedString, SourceResult, StrResult, bail};
use crate::foundations::{Decimal, IntoValue, Module, Scope, Value, cast, func, ops};
use crate::layout::{Angle, Fr, Length, Ratio};
/// A module with calculation definitions.

View File

@ -14,7 +14,7 @@ use unicode_math_class::MathClass;
use crate::diag::{At, HintedStrResult, HintedString, SourceResult, StrResult};
use crate::foundations::{
array, repr, Fold, NativeElement, Packed, Repr, Str, Type, Value,
Fold, NativeElement, Packed, Repr, Str, Type, Value, array, repr,
};
/// Determine details of a type.
@ -348,7 +348,9 @@ impl CastInfo {
}
}
} else if let Value::Decimal(_) = found
&& !matching_type && parts.iter().any(|p| p == "float") {
&& !matching_type
&& parts.iter().any(|p| p == "float")
{
msg.hint(eco_format!(
"if loss of precision is acceptable, explicitly cast the \
decimal to a float with `float(value)`"

View File

@ -11,8 +11,8 @@ use typst_utils::Static;
use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{
cast, Args, Content, ContentVtable, FieldAccessError, Func, ParamInfo, Repr, Scope,
Selector, StyleChain, Styles, Value,
Args, Content, ContentVtable, FieldAccessError, Func, ParamInfo, Repr, Scope,
Selector, StyleChain, Styles, Value, cast,
};
use crate::text::{Lang, Region};

View File

@ -3,7 +3,7 @@ use std::hash::Hash;
use std::marker::PhantomData;
use std::sync::OnceLock;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use crate::foundations::{
Container, Content, FieldVtable, Fold, FoldFn, IntoValue, NativeElement, Packed,

View File

@ -17,7 +17,7 @@ use std::iter::{self, Sum};
use std::ops::{Add, AddAssign, ControlFlow};
use comemo::Tracked;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use serde::{Serialize, Serializer};
use typst_syntax::Span;
@ -26,8 +26,8 @@ use typst_utils::singleton;
use crate::diag::{SourceResult, StrResult};
use crate::engine::Engine;
use crate::foundations::{
func, repr, scope, ty, Context, Dict, IntoValue, Label, Property, Recipe,
RecipeIndex, Repr, Selector, Str, Style, StyleChain, Styles, Value,
Context, Dict, IntoValue, Label, Property, Recipe, RecipeIndex, Repr, Selector, Str,
Style, StyleChain, Styles, Value, func, repr, scope, ty,
};
use crate::introspection::Location;
use crate::layout::{AlignElem, Alignment, Axes, Length, MoveElem, PadElem, Rel, Sides};
@ -175,7 +175,8 @@ impl Content {
styles: Option<StyleChain>,
) -> Result<Value, FieldAccessError> {
if id == 255
&& let Some(label) = self.label() {
&& let Some(label) = self.label()
{
return Ok(label.into_value());
}

View File

@ -5,7 +5,7 @@ use std::ptr::NonNull;
use std::sync::atomic::{self, AtomicUsize, Ordering};
use typst_syntax::Span;
use typst_utils::{fat, HashLock, SmallBitSet};
use typst_utils::{HashLock, SmallBitSet, fat};
use super::vtable;
use crate::foundations::{Element, Label, NativeElement, Packed};

View File

@ -1,9 +1,9 @@
use comemo::Track;
use crate::diag::{bail, Hint, HintedStrResult, SourceResult};
use crate::diag::{Hint, HintedStrResult, SourceResult, bail};
use crate::engine::Engine;
use crate::foundations::{
elem, Args, Construct, Content, Func, ShowFn, StyleChain, Value,
Args, Construct, Content, Func, ShowFn, StyleChain, Value, elem,
};
use crate::introspection::{Locatable, Location};

View File

@ -2,17 +2,17 @@ use std::cmp::Ordering;
use std::hash::Hash;
use std::ops::{Add, Sub};
use ecow::{eco_format, EcoString, EcoVec};
use ecow::{EcoString, EcoVec, eco_format};
use time::error::{Format, InvalidFormatDescription};
use time::macros::format_description;
use time::{format_description, Month, PrimitiveDateTime};
use time::{Month, PrimitiveDateTime, format_description};
use crate::diag::{bail, StrResult};
use crate::World;
use crate::diag::{StrResult, bail};
use crate::engine::Engine;
use crate::foundations::{
cast, func, repr, scope, ty, Dict, Duration, Repr, Smart, Str, Value,
Dict, Duration, Repr, Smart, Str, Value, cast, func, repr, scope, ty,
};
use crate::World;
/// Represents a date, a time, or a combination of both.
///

View File

@ -3,14 +3,14 @@ use std::hash::{Hash, Hasher};
use std::ops::Neg;
use std::str::FromStr;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use rust_decimal::MathematicalOps;
use typst_syntax::{ast, Span, Spanned};
use typst_syntax::{Span, Spanned, ast};
use crate::diag::{warning, At, SourceResult};
use crate::engine::Engine;
use crate::foundations::{cast, func, repr, scope, ty, Repr, Str};
use crate::World;
use crate::diag::{At, SourceResult, warning};
use crate::engine::Engine;
use crate::foundations::{Repr, Str, cast, func, repr, scope, ty};
/// A fixed-point decimal number type.
///

View File

@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher};
use std::ops::{Add, AddAssign};
use std::sync::Arc;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use indexmap::IndexMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use typst_syntax::is_ident;
@ -11,7 +11,7 @@ use typst_utils::ArcExt;
use crate::diag::{Hint, HintedStrResult, StrResult};
use crate::foundations::{
array, cast, func, repr, scope, ty, Array, Module, Repr, Str, Value,
Array, Module, Repr, Str, Value, array, cast, func, repr, scope, ty,
};
/// Create a new [`Dict`] from key-value pairs.

View File

@ -1,10 +1,10 @@
use std::fmt::{self, Debug, Formatter};
use std::ops::{Add, Div, Mul, Neg, Sub};
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use time::ext::NumericalDuration;
use crate::foundations::{func, repr, scope, ty, Repr};
use crate::foundations::{Repr, func, repr, scope, ty};
/// Represents a positive or negative span of time.
#[ty(scope, cast)]

View File

@ -1,6 +1,6 @@
//! Fields on values.
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use crate::diag::StrResult;
use crate::foundations::{IntoValue, Type, Value, Version};

View File

@ -1,10 +1,10 @@
use std::num::ParseFloatError;
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use crate::diag::{bail, StrResult};
use crate::diag::{StrResult, bail};
use crate::foundations::{
cast, func, repr, scope, ty, Bytes, Decimal, Endianness, Repr, Str,
Bytes, Decimal, Endianness, Repr, Str, cast, func, repr, scope, ty,
};
use crate::layout::Ratio;

View File

@ -5,15 +5,15 @@ use std::fmt::{self, Debug, Formatter};
use std::sync::{Arc, LazyLock};
use comemo::{Tracked, TrackedMut};
use ecow::{eco_format, EcoString};
use typst_syntax::{ast, Span, SyntaxNode};
use typst_utils::{singleton, LazyHash, Static};
use ecow::{EcoString, eco_format};
use typst_syntax::{Span, SyntaxNode, ast};
use typst_utils::{LazyHash, Static, singleton};
use crate::diag::{bail, At, DeprecationSink, SourceResult, StrResult};
use crate::diag::{At, DeprecationSink, SourceResult, StrResult, bail};
use crate::engine::Engine;
use crate::foundations::{
cast, repr, scope, ty, Args, Bytes, CastInfo, Content, Context, Element, IntoArgs,
PluginFunc, Scope, Selector, Type, Value,
Args, Bytes, CastInfo, Content, Context, Element, IntoArgs, PluginFunc, Scope,
Selector, Type, Value, cast, repr, scope, ty,
};
/// A mapping from argument values to a return value.

View File

@ -2,12 +2,12 @@ use std::num::{
NonZeroI64, NonZeroIsize, NonZeroU32, NonZeroU64, NonZeroUsize, ParseIntError,
};
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use smallvec::SmallVec;
use crate::diag::{bail, StrResult};
use crate::diag::{StrResult, bail};
use crate::foundations::{
cast, func, repr, scope, ty, Bytes, Cast, Decimal, Repr, Str, Value,
Bytes, Cast, Decimal, Repr, Str, Value, cast, func, repr, scope, ty,
};
/// A whole number.

View File

@ -1,8 +1,8 @@
use ecow::{eco_format, EcoString};
use ecow::{EcoString, eco_format};
use typst_utils::{PicoStr, ResolvedPicoStr};
use crate::diag::StrResult;
use crate::foundations::{bail, func, scope, ty, Repr, Str};
use crate::foundations::{Repr, Str, bail, func, scope, ty};
/// A label for an element.
///

View File

@ -80,7 +80,7 @@ use comemo::TrackedMut;
use ecow::EcoString;
use typst_syntax::Spanned;
use crate::diag::{bail, SourceResult, StrResult};
use crate::diag::{SourceResult, StrResult, bail};
use crate::engine::Engine;
use crate::{Feature, Features};

Some files were not shown because too many files have changed in this diff Show More