Ignore linebreak directly after markup statement

This commit is contained in:
Laurenz 2022-11-20 21:39:40 +01:00
parent 72361106bc
commit 46d469f4be
2 changed files with 23 additions and 1 deletions

View File

@ -56,7 +56,17 @@ node! {
impl Markup {
/// The children.
pub fn children(&self) -> impl DoubleEndedIterator<Item = MarkupNode> + '_ {
self.0.children().filter_map(SyntaxNode::cast)
let mut was_stmt = false;
self.0
.children()
.filter(move |node| {
// Ignore linebreak directly after statements without semicolons.
let kind = node.kind();
let keep = !was_stmt || !matches!(kind, NodeKind::Space { newlines: 1 });
was_stmt = kind.is_stmt();
keep
})
.filter_map(SyntaxNode::cast)
}
}

View File

@ -314,6 +314,18 @@ impl NodeKind {
matches!(self, NodeKind::Error(_, _))
}
/// Does this node need termination through a semicolon or linebreak?
pub fn is_stmt(&self) -> bool {
matches!(
self,
NodeKind::LetBinding
| NodeKind::SetRule
| NodeKind::ShowRule
| NodeKind::ModuleImport
| NodeKind::ModuleInclude
)
}
/// A human-readable name for the kind.
pub fn name(&self) -> &'static str {
match self {