1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

Merge pull request #117 from kamadorueda/kamadorueda

feat: start attr set in same line
This commit is contained in:
Kevin Amado 2022-02-16 21:15:11 -05:00 committed by GitHub
commit 635ba7a186
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 20 deletions

View file

@ -80,9 +80,6 @@ pub fn rule(
}
}
// in
let child = children.get_next().unwrap();
let indent = build_ctx.pos_new.column > 1;
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
@ -93,40 +90,69 @@ pub fn rule(
steps.push_back(crate::builder::Step::Whitespace);
}
}
steps.push_back(crate::builder::Step::Format(child.element));
// in
let child_in = children.get_next().unwrap();
let top_level = build_ctx.pos_new.column <= 1;
// /**/
let mut child_comments = std::collections::LinkedList::new();
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::Comment(text) => {
child_comments.push_back(crate::builder::Step::Comment(text))
}
crate::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr
let child_expr = children.get_next().unwrap();
// in
steps.push_back(crate::builder::Step::Format(child_in.element));
match layout {
crate::config::Layout::Tall => {
if indent {
steps.push_back(crate::builder::Step::Indent);
if child_comments.is_empty()
&& matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING
)
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
if !top_level {
steps.push_back(crate::builder::Step::Indent);
}
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
}
crate::config::Layout::Wide => {}
}
// /**/
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(_) => {}
});
for comment in child_comments {
steps.push_back(comment);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(child.element));
if indent {
steps.push_back(crate::builder::Step::FormatWider(
child_expr.element,
));
if !top_level {
steps.push_back(crate::builder::Step::Dedent);
}
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
steps.push_back(crate::builder::Step::Format(child_expr.element));
}
}

View file

@ -25,6 +25,11 @@ let
a = let /*b*/ c=1; /*d*/ in /*e*/ f;
/**/
a = let
in [
1
2
];
in

View file

@ -81,6 +81,12 @@ let
*/
f;
/**/
a = let
in [
1
2
];
in
/**/
a