From 46ef8e1dfa39d2ee953e7af722b3b6ff20907443 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 20 Jul 2024 14:52:17 +0200 Subject: [PATCH] Deprecate some things (#4562) --- crates/typst/src/foundations/styles.rs | 9 ++++++++- crates/typst/src/introspection/counter.rs | 17 ++++++++++++++--- crates/typst/src/introspection/locate.rs | 18 ++++++++++++------ crates/typst/src/introspection/query.rs | 14 +++++++++++--- crates/typst/src/introspection/state.rs | 19 ++++++++++++++++--- crates/typst/src/layout/measure.rs | 14 ++++++++++---- tests/suite/foundations/context.typ | 13 +++++++++++++ tests/suite/introspection/counter.typ | 2 +- tests/suite/layout/grid/footers.typ | 6 +++--- tests/suite/layout/grid/headers.typ | 4 ++-- tests/suite/layout/grid/rowspan.typ | 2 +- tests/suite/layout/spacing.typ | 2 +- tests/suite/styling/fold.typ | 5 +++++ 13 files changed, 97 insertions(+), 28 deletions(-) diff --git a/crates/typst/src/foundations/styles.rs b/crates/typst/src/foundations/styles.rs index 42be89229..48009c8c3 100644 --- a/crates/typst/src/foundations/styles.rs +++ b/crates/typst/src/foundations/styles.rs @@ -7,7 +7,7 @@ use comemo::{Track, Tracked}; use ecow::{eco_vec, EcoString, EcoVec}; use smallvec::SmallVec; -use crate::diag::{SourceResult, Trace, Tracepoint}; +use crate::diag::{warning, SourceResult, Trace, Tracepoint}; use crate::engine::Engine; use crate::foundations::{ cast, elem, func, ty, Content, Context, Element, Func, NativeElement, Packed, Repr, @@ -33,6 +33,8 @@ use crate::utils::LazyHash; /// ``` #[func] pub fn style( + /// The engine. + engine: &mut Engine, /// The call site span. span: Span, /// A function to call with the styles. Its return value is displayed @@ -43,6 +45,11 @@ pub fn style( /// content that depends on the style context it appears in. func: Func, ) -> Content { + engine.sink.warn(warning!( + span, "`style` is deprecated"; + hint: "use a `context` expression instead" + )); + StyleElem::new(func).pack().spanned(span) } diff --git a/crates/typst/src/introspection/counter.rs b/crates/typst/src/introspection/counter.rs index 13ea4d142..2aefb68ec 100644 --- a/crates/typst/src/introspection/counter.rs +++ b/crates/typst/src/introspection/counter.rs @@ -5,7 +5,7 @@ use comemo::{Track, Tracked, TrackedMut}; use ecow::{eco_format, eco_vec, EcoString, EcoVec}; use smallvec::{smallvec, SmallVec}; -use crate::diag::{bail, At, HintedStrResult, SourceResult}; +use crate::diag::{bail, warning, At, HintedStrResult, SourceResult}; use crate::engine::{Engine, Route, Sink, Traced}; use crate::foundations::{ cast, elem, func, scope, select_where, ty, Args, Array, Construct, Content, Context, @@ -464,6 +464,11 @@ impl Counter { if let Ok(loc) = context.location() { self.display_impl(engine, loc, numbering, both, context.styles().ok()) } else { + engine.sink.warn(warning!( + span, "`counter.display` without context is deprecated"; + hint: "use it in a `context` expression instead" + )); + Ok(CounterDisplayElem::new(self, numbering, both) .pack() .spanned(span) @@ -508,13 +513,19 @@ impl Counter { context: Tracked, /// The callsite span. span: Span, - /// _Compatibility:_ This argument only exists for compatibility with - /// Typst 0.10 and lower and shouldn't be used anymore. + /// _Compatibility:_ This argument is deprecated. It only exists for + /// compatibility with Typst 0.10 and lower and shouldn't be used + /// anymore. #[default] location: Option, ) -> SourceResult { if location.is_none() { context.location().at(span)?; + } else { + engine.sink.warn(warning!( + span, "calling `counter.final` with a location is deprecated"; + hint: "try removing the location argument" + )); } let sequence = self.sequence(engine)?; diff --git a/crates/typst/src/introspection/locate.rs b/crates/typst/src/introspection/locate.rs index 373b1fe27..8991ae9be 100644 --- a/crates/typst/src/introspection/locate.rs +++ b/crates/typst/src/introspection/locate.rs @@ -1,6 +1,6 @@ use comemo::{Track, Tracked}; -use crate::diag::{HintedStrResult, SourceResult}; +use crate::diag::{warning, HintedStrResult, SourceResult}; use crate::engine::Engine; use crate::foundations::{ cast, elem, func, Content, Context, Func, LocatableSelector, NativeElement, Packed, @@ -29,11 +29,12 @@ use crate::syntax::Span; /// /// # Compatibility /// In Typst 0.10 and lower, the `locate` function took a closure that made the -/// current location in the document available (like [`here`] does now). -/// Compatibility with the old way will remain for a while to give package -/// authors time to upgrade. To that effect, `locate` detects whether it -/// received a selector or a user-defined function and adjusts its semantics -/// accordingly. This behaviour will be removed in the future. +/// current location in the document available (like [`here`] does now). This +/// usage pattern is deprecated. Compatibility with the old way will remain for +/// a while to give package authors time to upgrade. To that effect, `locate` +/// detects whether it received a selector or a user-defined function and +/// adjusts its semantics accordingly. This behaviour will be removed in the +/// future. #[func(contextual)] pub fn locate( /// The engine. @@ -56,6 +57,11 @@ pub fn locate( LocateOutput::Location(selector.resolve_unique(engine.introspector, context)?) } LocateInput::Func(func) => { + engine.sink.warn(warning!( + span, "`locate` with callback function is deprecated"; + hint: "use a `context` expression instead" + )); + LocateOutput::Content(LocateElem::new(func).pack().spanned(span)) } }) diff --git a/crates/typst/src/introspection/query.rs b/crates/typst/src/introspection/query.rs index e416bfc9d..07f761a8d 100644 --- a/crates/typst/src/introspection/query.rs +++ b/crates/typst/src/introspection/query.rs @@ -1,9 +1,10 @@ use comemo::Tracked; -use crate::diag::HintedStrResult; +use crate::diag::{warning, HintedStrResult}; use crate::engine::Engine; use crate::foundations::{func, Array, Context, LocatableSelector, Value}; use crate::introspection::Location; +use crate::syntax::Span; /// Finds elements in the document. /// @@ -141,6 +142,8 @@ pub fn query( engine: &mut Engine, /// The callsite context. context: Tracked, + /// The span of the `query` call. + span: Span, /// Can be /// - an element function like a `heading` or `figure`, /// - a `{