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

feat: align multiline comments

This commit is contained in:
Kevin Amado 2022-01-31 19:09:42 -05:00
parent 4633541af3
commit 2273912023
No known key found for this signature in database
GPG key ID: FFF341057F503148
4 changed files with 15 additions and 11 deletions

View file

@ -139,6 +139,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
// println!("{:?}", lines);
// println!("0\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
// Make sure it starts with empty line
if lines.len() == 1 {
lines.insert(0, "".to_string());
lines[1] = format!("{0:<1$}{2}", "", pos.column + 2, lines[1]);
@ -146,26 +147,26 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
lines[0] = "".to_string();
} else {
lines.insert(0, format!("{0:<1$}", "", pos.column + 1));
lines[1] = format!("{0:<1$}{2}", "", pos.column + 2, lines[1]);
lines[1] = format!("{0:<1$}{2}", "", pos.column + 1, lines[1]);
}
// println!("{:?}", lines);
// println!("1\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
// Make sure it ends with empty line
let len = lines.len();
if len == 2 {
lines.push(format!("{0:<1$}", "", pos.column + 1));
} else if lines[len - 1].trim().len() == 0 {
lines[len - 1] = format!("{0:<1$}", "", pos.column + 1)
} else {
// lines[len - 1] =
// format!("{0:<1$}{2}", "", pos.column + 2, lines[len - 1]);
lines.push(format!("{0:<1$}", "", pos.column + 1));
}
// println!("{:?}", lines);
// println!("2\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
// Compute the distance to the first character from the left
let mut indentation: usize = usize::MAX;
for (index, line) in lines.iter().enumerate() {
if index != 0 && index + 1 != lines.len() {
@ -183,6 +184,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
indentation = pos.column;
};
// Re-align everything with respect to the vertical
lines = lines
.iter()
.enumerate()
@ -211,6 +213,8 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
// println!("3\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
// println!("indentation={} pos.column{}", indentation, pos.column);
// Dedent everything as much as possible so that upstream components
// can indent as they see convenient
lines = lines
.iter()
.enumerate()

View file

@ -9,32 +9,32 @@
@
*/
/*
*
*
@
*
*/
/*
@
@
@
@
*/
/*
@
@
@
@
*/
/*
@
@
@
@
*/
/*
@
@
@
@
*/
/*
test
test
* test
*/
]

View file

@ -1,9 +1,9 @@
/*
Some functions f
name attribute.
name attribute.
*/
/*
Add to or over
Add to or over
derivation.
Example: