mirror of
https://github.com/typst/typst
synced 2025-05-21 20:45:27 +08:00
Hint for show par: set block(spacing: ..)
(#5076)
This commit is contained in:
parent
75f646c975
commit
4ef1096ad9
@ -1,6 +1,10 @@
|
|||||||
use crate::diag::{At, SourceResult};
|
use crate::diag::{warning, At, SourceResult};
|
||||||
use crate::eval::{Eval, Vm};
|
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};
|
use crate::syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
impl Eval for ast::SetRule<'_> {
|
impl Eval for ast::SetRule<'_> {
|
||||||
@ -39,13 +43,33 @@ impl Eval for ast::ShowRule<'_> {
|
|||||||
.map(|selector| selector.0);
|
.map(|selector| selector.0);
|
||||||
|
|
||||||
let transform = self.transform();
|
let transform = self.transform();
|
||||||
let span = transform.span();
|
|
||||||
|
|
||||||
let transform = match transform {
|
let transform = match transform {
|
||||||
ast::Expr::Set(set) => Transformation::Style(set.eval(vm)?),
|
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"
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,6 +488,11 @@ impl Recipe {
|
|||||||
&self.transform
|
&self.transform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The recipe's span.
|
||||||
|
pub fn span(&self) -> Span {
|
||||||
|
self.span
|
||||||
|
}
|
||||||
|
|
||||||
/// Apply the recipe to the given content.
|
/// Apply the recipe to the given content.
|
||||||
pub fn apply(
|
pub fn apply(
|
||||||
&self,
|
&self,
|
||||||
|
@ -106,3 +106,9 @@ Lorem ipsum dolor #metadata(none) nonumy eirmod tempor.
|
|||||||
#h(0pt) #box[] <a>
|
#h(0pt) #box[] <a>
|
||||||
|
|
||||||
#context test(query(<a>).len(), 1)
|
#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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user