diff --git a/src/children.rs b/src/children.rs index 25f7ba7..9bf2c5b 100644 --- a/src/children.rs +++ b/src/children.rs @@ -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() diff --git a/tests/cases/comments/in b/tests/cases/comment/in similarity index 100% rename from tests/cases/comments/in rename to tests/cases/comment/in diff --git a/tests/cases/comments/out b/tests/cases/comment/out similarity index 80% rename from tests/cases/comments/out rename to tests/cases/comment/out index b42f492..fea61d8 100644 --- a/tests/cases/comments/out +++ b/tests/cases/comment/out @@ -9,32 +9,32 @@ @ */ /* - * + * @ * */ /* - @ + @ @ @ */ /* - @ + @ @ @ */ /* - @ + @ @ @ */ /* - @ + @ @ @ */ /* - test + test * test */ ] diff --git a/tests/cases/root/out b/tests/cases/root/out index 7bb735c..ea4d594 100644 --- a/tests/cases/root/out +++ b/tests/cases/root/out @@ -1,9 +1,9 @@ /* Some functions f - name attribute. + name attribute. */ /* - Add to or over + Add to or over derivation. Example: