mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: pattern without max-width
This commit is contained in:
parent
76d0d5541e
commit
6d47a4b680
2 changed files with 34 additions and 14 deletions
|
@ -61,7 +61,8 @@ pub fn rule(
|
||||||
crate::children::DrainCommentOrNewline::Newline(_) => {}
|
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()
|
children.peek_prev().unwrap().element.kind()
|
||||||
{
|
{
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
|
|
|
@ -4,7 +4,9 @@ pub fn rule(
|
||||||
) -> std::collections::LinkedList<crate::builder::Step> {
|
) -> std::collections::LinkedList<crate::builder::Step> {
|
||||||
let mut steps = std::collections::LinkedList::new();
|
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 has_comments = children.has_comments();
|
let has_comments = children.has_comments();
|
||||||
let has_comments_between_curly_b = node
|
let has_comments_between_curly_b = node
|
||||||
|
@ -26,7 +28,7 @@ pub fn rule(
|
||||||
})
|
})
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
let layout = if has_comments {
|
let layout = if has_comments || children.has_newlines() {
|
||||||
&crate::config::Layout::Tall
|
&crate::config::Layout::Tall
|
||||||
} else {
|
} else {
|
||||||
build_ctx.config.layout()
|
build_ctx.config.layout()
|
||||||
|
@ -55,10 +57,13 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**/
|
// /**/
|
||||||
children.drain_comments(|text| {
|
children.drain_comments_and_newlines(|element| match element {
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
crate::children::DrainCommentOrNewline::Comment(text) => {
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
}
|
||||||
|
crate::children::DrainCommentOrNewline::Newline(_) => {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// {
|
// {
|
||||||
|
@ -79,6 +84,7 @@ pub fn rule(
|
||||||
|
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||||
|
| rnix::SyntaxKind::TOKEN_WHITESPACE
|
||||||
| rnix::SyntaxKind::NODE_PAT_ENTRY = prev_kind
|
| rnix::SyntaxKind::NODE_PAT_ENTRY = prev_kind
|
||||||
{
|
{
|
||||||
steps.push_back(crate::builder::Step::Indent);
|
steps.push_back(crate::builder::Step::Indent);
|
||||||
|
@ -86,14 +92,18 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
}
|
}
|
||||||
|
|
||||||
children.drain_comment(|text| {
|
children.drain_comments_and_newlines(|element| match element {
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
crate::children::DrainCommentOrNewline::Comment(text) => {
|
||||||
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
|
}
|
||||||
|
crate::children::DrainCommentOrNewline::Newline(_) => {}
|
||||||
});
|
});
|
||||||
|
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||||
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
|
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
|
||||||
| rnix::SyntaxKind::TOKEN_COMMENT
|
| rnix::SyntaxKind::TOKEN_COMMENT
|
||||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||||
|
| rnix::SyntaxKind::TOKEN_WHITESPACE
|
||||||
| rnix::SyntaxKind::NODE_PAT_ENTRY = prev_kind
|
| rnix::SyntaxKind::NODE_PAT_ENTRY = prev_kind
|
||||||
{
|
{
|
||||||
steps.push_back(crate::builder::Step::Dedent);
|
steps.push_back(crate::builder::Step::Dedent);
|
||||||
|
@ -110,7 +120,9 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMENT = prev_kind {
|
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||||
|
| rnix::SyntaxKind::TOKEN_WHITESPACE = prev_kind
|
||||||
|
{
|
||||||
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::Whitespace);
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
|
@ -143,6 +155,10 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
children.move_next();
|
children.move_next();
|
||||||
}
|
}
|
||||||
|
// \n
|
||||||
|
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
||||||
|
children.move_next();
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -160,10 +176,13 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
|
|
||||||
// /**/
|
// /**/
|
||||||
children.drain_comments(|text| {
|
children.drain_comments_and_newlines(|element| match element {
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
crate::children::DrainCommentOrNewline::Comment(text) => {
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
|
}
|
||||||
|
crate::children::DrainCommentOrNewline::Newline(_) => {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ x
|
// @ x
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue