mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: inline lists comments
This commit is contained in:
parent
53218545a5
commit
10f984fb7d
2 changed files with 17 additions and 8 deletions
|
@ -33,16 +33,23 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut item_index: usize = 0;
|
let mut item_index: usize = 0;
|
||||||
|
let mut inline_next_comment = false;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// /**/
|
// /**/
|
||||||
children.drain_comments_and_newlines(|element| {
|
children.drain_comments_and_newlines(|element| {
|
||||||
match element {
|
match element {
|
||||||
crate::children::DrainCommentOrNewline::Comment(text) => {
|
crate::children::DrainCommentOrNewline::Comment(text) => {
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
if inline_next_comment && text.starts_with("#") {
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
|
} else {
|
||||||
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
}
|
||||||
|
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
item_index += 1;
|
item_index += 1;
|
||||||
|
inline_next_comment = false;
|
||||||
}
|
}
|
||||||
crate::children::DrainCommentOrNewline::Newline(newlines) => {
|
crate::children::DrainCommentOrNewline::Newline(newlines) => {
|
||||||
if newlines > 1
|
if newlines > 1
|
||||||
|
@ -51,13 +58,16 @@ pub fn rule(
|
||||||
{
|
{
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline_next_comment = newlines == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(child) = children.peek_next() {
|
if let Some(child) = children.peek_next() {
|
||||||
if let rnix::SyntaxKind::TOKEN_SQUARE_B_CLOSE = child.element.kind()
|
let child_kind = child.element.kind();
|
||||||
{
|
|
||||||
|
if let rnix::SyntaxKind::TOKEN_SQUARE_B_CLOSE = child_kind {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +91,7 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
|
|
||||||
children.move_next();
|
children.move_next();
|
||||||
|
inline_next_comment = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,9 @@
|
||||||
[
|
[
|
||||||
# 1
|
# 1
|
||||||
#2
|
#2
|
||||||
a
|
a # 3
|
||||||
# 3
|
|
||||||
b
|
b
|
||||||
c
|
c # 4
|
||||||
# 4
|
|
||||||
#5
|
#5
|
||||||
|
|
||||||
#6
|
#6
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue