summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-01 09:59:43 +0200
committerGitHub <noreply@github.com>2024-10-01 07:59:43 +0000
commit4ef1096ad99059fd86526ed819bf8a7abd3aef2b (patch)
tree19ca441f6c863169a9d85005c33702174a89761f
parent75f646c9756634fe6bc7f94349f6496ed0fc5484 (diff)
Hint for `show par: set block(spacing: ..)` (#5076)
-rw-r--r--crates/typst/src/eval/rules.rs36
-rw-r--r--crates/typst/src/foundations/styles.rs5
-rw-r--r--tests/suite/model/par.typ6
3 files changed, 41 insertions, 6 deletions
diff --git a/crates/typst/src/eval/rules.rs b/crates/typst/src/eval/rules.rs
index 61fee84a..1748bbd7 100644
--- a/crates/typst/src/eval/rules.rs
+++ b/crates/typst/src/eval/rules.rs
@@ -1,6 +1,10 @@
-use crate::diag::{At, SourceResult};
+use crate::diag::{warning, At, SourceResult};
use crate::eval::{Eval, Vm};
-use crate::foundations::{Func, Recipe, ShowableSelector, Styles, Transformation};
+use crate::foundations::{
+ Element, Fields, Func, Recipe, Selector, ShowableSelector, Styles, Transformation,
+};
+use crate::layout::BlockElem;
+use crate::model::ParElem;
use crate::syntax::ast::{self, AstNode};
impl Eval for ast::SetRule<'_> {
@@ -39,13 +43,33 @@ impl Eval for ast::ShowRule<'_> {
.map(|selector| selector.0);
let transform = self.transform();
- let span = transform.span();
-
let transform = match transform {
ast::Expr::Set(set) => Transformation::Style(set.eval(vm)?),
- expr => expr.eval(vm)?.cast::<Transformation>().at(span)?,
+ expr => expr.eval(vm)?.cast::<Transformation>().at(transform.span())?,
};
- Ok(Recipe::new(selector, transform, span))
+ let recipe = Recipe::new(selector, transform, self.span());
+ check_show_par_set_block(vm, &recipe);
+
+ Ok(recipe)
+ }
+}
+
+/// Migration hint for `show par: set block(spacing: ..)`.
+fn check_show_par_set_block(vm: &mut Vm, recipe: &Recipe) {
+ if_chain::if_chain! {
+ if let Some(Selector::Elem(elem, _)) = recipe.selector();
+ if *elem == Element::of::<ParElem>();
+ if let Transformation::Style(styles) = recipe.transform();
+ if styles.has::<BlockElem>(<BlockElem as Fields>::Enum::Above as _) ||
+ styles.has::<BlockElem>(<BlockElem as Fields>::Enum::Below as _);
+ then {
+ vm.engine.sink.warn(warning!(
+ recipe.span(),
+ "`show par: set block(spacing: ..)` has no effect anymore";
+ hint: "write `set par(spacing: ..)` instead";
+ hint: "this is specific to paragraphs as they are not considered blocks anymore"
+ ))
+ }
}
}
diff --git a/crates/typst/src/foundations/styles.rs b/crates/typst/src/foundations/styles.rs
index e297db7d..a3c8e0c4 100644
--- a/crates/typst/src/foundations/styles.rs
+++ b/crates/typst/src/foundations/styles.rs
@@ -488,6 +488,11 @@ impl Recipe {
&self.transform
}
+ /// The recipe's span.
+ pub fn span(&self) -> Span {
+ self.span
+ }
+
/// Apply the recipe to the given content.
pub fn apply(
&self,
diff --git a/tests/suite/model/par.typ b/tests/suite/model/par.typ
index b2e400fc..0c2b5cb5 100644
--- a/tests/suite/model/par.typ
+++ b/tests/suite/model/par.typ
@@ -106,3 +106,9 @@ Lorem ipsum dolor #metadata(none) nonumy eirmod tempor.
#h(0pt) #box[] <a>
#context test(query(<a>).len(), 1)
+
+--- show-par-set-block-hint ---
+// Warning: 2-36 `show par: set block(spacing: ..)` has no effect anymore
+// Hint: 2-36 this is specific to paragraphs as they are not considered blocks anymore
+// Hint: 2-36 write `set par(spacing: ..)` instead
+#show par: set block(spacing: 12pt)