mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 04:27:45 +00:00
Merge pull request #117 from kamadorueda/kamadorueda
feat: start attr set in same line
This commit is contained in:
commit
635ba7a186
3 changed files with 57 additions and 20 deletions
|
@ -80,9 +80,6 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// in
|
|
||||||
let child = children.get_next().unwrap();
|
|
||||||
let indent = build_ctx.pos_new.column > 1;
|
|
||||||
match layout {
|
match layout {
|
||||||
crate::config::Layout::Tall => {
|
crate::config::Layout::Tall => {
|
||||||
steps.push_back(crate::builder::Step::Dedent);
|
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::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 {
|
match layout {
|
||||||
crate::config::Layout::Tall => {
|
crate::config::Layout::Tall => {
|
||||||
if indent {
|
if child_comments.is_empty()
|
||||||
steps.push_back(crate::builder::Step::Indent);
|
&& 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 => {}
|
crate::config::Layout::Wide => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**/
|
// /**/
|
||||||
children.drain_comments_and_newlines(|element| match element {
|
for comment in child_comments {
|
||||||
crate::children::DrainCommentOrNewline::Comment(text) => {
|
steps.push_back(comment);
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
}
|
||||||
}
|
|
||||||
crate::children::DrainCommentOrNewline::Newline(_) => {}
|
|
||||||
});
|
|
||||||
|
|
||||||
// expr
|
// expr
|
||||||
let child = children.get_next().unwrap();
|
|
||||||
match layout {
|
match layout {
|
||||||
crate::config::Layout::Tall => {
|
crate::config::Layout::Tall => {
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::FormatWider(
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
child_expr.element,
|
||||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
));
|
||||||
if indent {
|
if !top_level {
|
||||||
steps.push_back(crate::builder::Step::Dedent);
|
steps.push_back(crate::builder::Step::Dedent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crate::config::Layout::Wide => {
|
crate::config::Layout::Wide => {
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,11 @@ let
|
||||||
a = let /*b*/ c=1; /*d*/ in /*e*/ f;
|
a = let /*b*/ c=1; /*d*/ in /*e*/ f;
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
|
a = let
|
||||||
|
in [
|
||||||
|
1
|
||||||
|
2
|
||||||
|
];
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,12 @@ let
|
||||||
*/
|
*/
|
||||||
f;
|
f;
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
|
a = let
|
||||||
|
in [
|
||||||
|
1
|
||||||
|
2
|
||||||
|
];
|
||||||
in
|
in
|
||||||
/**/
|
/**/
|
||||||
a
|
a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue