summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-20 21:39:40 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-20 21:40:08 +0100
commit46d469f4bee6afd6b0d7dfdb3f095b98b18ac5f9 (patch)
tree4c1a2507ec28e10eff5ab9b29e1e589ebcb71754 /src
parent72361106bcef403ef88f1745a215e0d911148072 (diff)
Ignore linebreak directly after markup statement
Diffstat (limited to 'src')
-rw-r--r--src/syntax/ast.rs12
-rw-r--r--src/syntax/kind.rs12
2 files changed, 23 insertions, 1 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index 381ba712..46ce40c8 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -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)
}
}
diff --git a/src/syntax/kind.rs b/src/syntax/kind.rs
index b3948c66..c973632c 100644
--- a/src/syntax/kind.rs
+++ b/src/syntax/kind.rs
@@ -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 {