From 76d0d5541ef4f1f745c15cf13f8a6487084bf8d4 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Wed, 9 Feb 2022 20:38:01 -0500 Subject: [PATCH] feat: pat-entry without max-width --- src/rules/pat_entry.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/rules/pat_entry.rs b/src/rules/pat_entry.rs index ee30f6f..e92a3b7 100644 --- a/src/rules/pat_entry.rs +++ b/src/rules/pat_entry.rs @@ -4,9 +4,11 @@ pub fn rule( ) -> std::collections::LinkedList { let mut steps = std::collections::LinkedList::new(); - let mut children = crate::children::Children::new(build_ctx, node); + let mut children = crate::children::Children::new_with_configuration( + build_ctx, node, true, + ); - let layout = if children.has_comments() { + let layout = if children.has_comments() || children.has_newlines() { &crate::config::Layout::Tall } else { build_ctx.config.layout() @@ -26,13 +28,17 @@ pub fn rule( if children.has_next() { // /**/ - children.drain_comments(|text| { - steps.push_back(crate::builder::Step::NewLine); - steps.push_back(crate::builder::Step::Pad); - steps.push_back(crate::builder::Step::Comment(text)); + children.drain_comments_and_newlines(|element| match element { + crate::children::DrainCommentOrNewline::Comment(text) => { + steps.push_back(crate::builder::Step::NewLine); + steps.push_back(crate::builder::Step::Pad); + steps.push_back(crate::builder::Step::Comment(text)); + } + crate::children::DrainCommentOrNewline::Newline(_) => {} }); - if let rnix::SyntaxKind::TOKEN_COMMENT = + if let rnix::SyntaxKind::TOKEN_COMMENT + | rnix::SyntaxKind::TOKEN_WHITESPACE = children.peek_prev().unwrap().element.kind() { steps.push_back(crate::builder::Step::NewLine); @@ -46,10 +52,13 @@ pub fn rule( steps.push_back(crate::builder::Step::Format(child.element)); // /**/ - children.drain_comments(|text| { - steps.push_back(crate::builder::Step::NewLine); - steps.push_back(crate::builder::Step::Pad); - steps.push_back(crate::builder::Step::Comment(text)); + children.drain_comments_and_newlines(|element| match element { + crate::children::DrainCommentOrNewline::Comment(text) => { + steps.push_back(crate::builder::Step::NewLine); + steps.push_back(crate::builder::Step::Pad); + steps.push_back(crate::builder::Step::Comment(text)); + } + crate::children::DrainCommentOrNewline::Newline(_) => {} }); if let rnix::SyntaxKind::TOKEN_COMMENT =