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

add formatting for doc-comments

This commit is contained in:
hsjobeki 2023-09-14 08:53:55 +02:00 committed by Kevin Amado
parent 0f7f0afa42
commit 264e235466
3 changed files with 44 additions and 9 deletions

View file

@ -193,14 +193,26 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
if text.starts_with('#') { if text.starts_with('#') {
text.to_string() text.to_string()
} else { } else {
let mut lines: Vec<String> = text[2..text.len() - 2] let is_doc = text.starts_with("/**") && !text.starts_with("/**/");
.lines() let mut lines: Vec<String> = if is_doc {
.map(|line| line.to_string()) text[3..text.len() - 2]
.collect(); .lines()
.map(|line| line.to_string())
.collect()
} else {
text[2..text.len() - 2]
.lines()
.map(|line| line.to_string())
.collect()
};
// If all lines are whitespace just return a compact comment // If all lines are whitespace just return a compact comment
if lines.iter().all(|line| line.trim().is_empty()) { if lines.iter().all(|line| line.trim().is_empty()) {
return "/**/".to_string(); if is_doc {
return "/***/".to_string();
} else {
return "/**/".to_string();
}
} }
// Make sure it starts with empty line // Make sure it starts with empty line
@ -279,7 +291,10 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
} }
}) })
.collect(); .collect();
if is_doc {
format!("/*{}*/", lines.join("\n")) format!("/**{}*/", lines.join("\n"))
} else {
format!("/*{}*/", lines.join("\n"))
}
} }
} }

View file

@ -17,6 +17,15 @@
*/ */
/*@*/ /*@*/
/**@*/
/**@
@
@*/
/**
*/
/** /**
@ @

View file

@ -14,8 +14,19 @@
@ @
*/ */
/* /**
* @
*/
/**
@
@
@
*/
/***/
/**
@ @
* *
*/ */