Add ReflowComments rule - #1251
Conversation
eb1bbcf to
3dd3631
Compare
|
Resolves #1235 |
3dd3631 to
66221fd
Compare
This opt-in rule joins comments that were hard-wrapped across multiple lines back into a single line when the combined text still fits within the configured line length. It reflows only line comments (//) and documentation line comments (///), and only joins lines that belong to the same Markdown paragraph. Lists, headings, code blocks, block quotes, thematic breaks, blank lines between paragraphs, divider lines such as //===----===//, and file headers are left untouched. The `reflowComments.reflowedCommentKinds` and `reflowComments.preservedLinePrefixes` options control which comments the rule reflows.
66221fd to
0d2d694
Compare
|
Thanks for taking a look at this! I think the problem is a bit trickier than it appears, and a pure syntax-node-based rule isn't going to suffice I'm afraid. Since this behavior deals with line breaking/reflowing, it can't really be applied until the pretty printer phase. Consider this example: struct S {
func f() {
// these lines are intentionally unindented, assume the column
// width is 80 and these lines will go past column 80
}
}swift-format works in two discrete phases:
Since I think the proper (and only correct) way to do this is to update the pretty printer to treat clusters of whole-line comments as atomic units. The place to start would be looking at how we handle comments in |
Thanks for the pointer! I underestimated this overwhelmingly since indentation has never been a problem in the repos that I work with 😅 I'll take a stab with this direction and come back with whatever I have. Thanks! |
This opt-in rule joins comments that were hard-wrapped across multiple
lines back into a single line when the combined text still fits within
the configured line length.
It reflows only line comments (
//) and documentation line comments(
///), and only joins lines that belong to the same Markdown paragraph.Lists, headings, code blocks, block quotes, thematic breaks, blank lines
between paragraphs, divider lines such as
//===----===//, and fileheaders are left untouched. The
reflowComments.reflowedCommentKindsandreflowComments.preservedLinePrefixesoptions control which comments therule reflows.