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:
parent
0f7f0afa42
commit
264e235466
3 changed files with 44 additions and 9 deletions
|
@ -193,15 +193,27 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
|||
if text.starts_with('#') {
|
||||
text.to_string()
|
||||
} else {
|
||||
let mut lines: Vec<String> = text[2..text.len() - 2]
|
||||
let is_doc = text.starts_with("/**") && !text.starts_with("/**/");
|
||||
let mut lines: Vec<String> = if is_doc {
|
||||
text[3..text.len() - 2]
|
||||
.lines()
|
||||
.map(|line| line.to_string())
|
||||
.collect();
|
||||
.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 lines.iter().all(|line| line.trim().is_empty()) {
|
||||
if is_doc {
|
||||
return "/***/".to_string();
|
||||
} else {
|
||||
return "/**/".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure it starts with empty line
|
||||
if lines.len() == 1 {
|
||||
|
@ -279,7 +291,10 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
|||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
if is_doc {
|
||||
format!("/**{}*/", lines.join("\n"))
|
||||
} else {
|
||||
format!("/*{}*/", lines.join("\n"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,15 @@
|
|||
|
||||
/*@*/
|
||||
|
||||
/**@*/
|
||||
|
||||
/**@
|
||||
@
|
||||
@*/
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
/**
|
||||
@
|
||||
**/
|
||||
|
|
|
@ -14,8 +14,19 @@
|
|||
@
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
@
|
||||
*/
|
||||
|
||||
/**
|
||||
@
|
||||
@
|
||||
@
|
||||
*/
|
||||
|
||||
/***/
|
||||
|
||||
/**
|
||||
@
|
||||
*
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue