Rewrap
Rewrap copied to clipboard
Feature request: option to put block start/end sequences like "/**" & "*/" on their own lines for multi-line comments
Right now if I type a long javadoc-style comment and trigger rewrap, it keeps the block comment start and end characters on the same line as the comment text, e.g.
/** foo bar
* baz */
Whereas some style guides (e.g. Google's) requires the javadoc start & end sequences to be on their own lines (when the whole jsdoc comment wouldn't fit on a single line), as in:
/**
* foo bar
* baz
*/
I took a look at the code hoping there'd be some straightforward spot I could wire this functionality in but then got 🤯 by the F#, which I've not used before (but have heard good things about from colleagues). Any pointers would be appreciated!
Hi, if you press Enter after typing /**, for a new comment, VS Code itself will reformat it for you with the start & end markers on separate lines. If you do wraps/use autowrap after that, Rewrap will preserve this.
I really wanted this extension just to work with what it's given rather than going into the business of reformatting. However due to the large number of requests, I will be adding a feature where people can add their own find/replace operations that run whenever a wrap is triggered. So that would work for you if you want to convert existing comments at the same time as wrapping.
I don't think either of the proposed workarounds work in my case:
- I could indeed press enter first and then continue typing. But I often don't know when I start typing whether my comment will be a single line or multiple, and the style guide (as well as my own aesthetic sense) says to put the start/end markers on their own lines only for multi-line doc comments.
- For the same reason, a basic replace operation won't really work, or at least it would probably take me a while on regex101 to craft the beast that would have the desired effect. But also, performing a replace operation on a whole file (that may or may not be consistently formatted yet) is generally going to be a non-starter.
I'm also generally confused by your distinction between wrapping and formatting, since at least in my experience wrapping long lines of code in sensible ways is one of the main jobs of almost all formatters (and some good ones like clang-format can be configured to wrap comments, too). This plugin seemed to me like the same sort of thing except for comments. It would be nice if this functionality already existed in all the regular formatters, too, but this is a nice way to add that behavior when the formatters don't have such features.
Ok I am warming to the idea :)