mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: align multiline comments
This commit is contained in:
parent
4633541af3
commit
2273912023
4 changed files with 15 additions and 11 deletions
|
@ -139,6 +139,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
||||||
// println!("{:?}", lines);
|
// println!("{:?}", lines);
|
||||||
// println!("0\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
|
// println!("0\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
|
||||||
|
|
||||||
|
// Make sure it starts with empty line
|
||||||
if lines.len() == 1 {
|
if lines.len() == 1 {
|
||||||
lines.insert(0, "".to_string());
|
lines.insert(0, "".to_string());
|
||||||
lines[1] = format!("{0:<1$}{2}", "", pos.column + 2, lines[1]);
|
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();
|
lines[0] = "".to_string();
|
||||||
} else {
|
} else {
|
||||||
lines.insert(0, format!("{0:<1$}", "", pos.column + 1));
|
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!("{:?}", lines);
|
||||||
// println!("1\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
|
// println!("1\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
|
||||||
|
|
||||||
|
// Make sure it ends with empty line
|
||||||
let len = lines.len();
|
let len = lines.len();
|
||||||
if len == 2 {
|
if len == 2 {
|
||||||
lines.push(format!("{0:<1$}", "", pos.column + 1));
|
lines.push(format!("{0:<1$}", "", pos.column + 1));
|
||||||
} else if lines[len - 1].trim().len() == 0 {
|
} else if lines[len - 1].trim().len() == 0 {
|
||||||
lines[len - 1] = format!("{0:<1$}", "", pos.column + 1)
|
lines[len - 1] = format!("{0:<1$}", "", pos.column + 1)
|
||||||
} else {
|
} else {
|
||||||
// lines[len - 1] =
|
|
||||||
// format!("{0:<1$}{2}", "", pos.column + 2, lines[len - 1]);
|
|
||||||
lines.push(format!("{0:<1$}", "", pos.column + 1));
|
lines.push(format!("{0:<1$}", "", pos.column + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!("{:?}", lines);
|
// println!("{:?}", lines);
|
||||||
// println!("2\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
|
// 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;
|
let mut indentation: usize = usize::MAX;
|
||||||
for (index, line) in lines.iter().enumerate() {
|
for (index, line) in lines.iter().enumerate() {
|
||||||
if index != 0 && index + 1 != lines.len() {
|
if index != 0 && index + 1 != lines.len() {
|
||||||
|
@ -183,6 +184,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
||||||
indentation = pos.column;
|
indentation = pos.column;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Re-align everything with respect to the vertical
|
||||||
lines = lines
|
lines = lines
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.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!("3\n{0:<1$}/*{2}*/\n", "", pos.column, lines.join("\n"));
|
||||||
// println!("indentation={} pos.column{}", indentation, pos.column);
|
// 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
|
lines = lines
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|
|
@ -9,32 +9,32 @@
|
||||||
@
|
@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@
|
@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
@
|
@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
test
|
test
|
||||||
* test
|
* test
|
||||||
*/
|
*/
|
||||||
]
|
]
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
Some functions f
|
Some functions f
|
||||||
name attribute.
|
name attribute.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
Add to or over
|
Add to or over
|
||||||
derivation.
|
derivation.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue