sway
sway copied to clipboard
Fix formatting of multiline comments within function parameters
I agree that we do not need to format inside of `/**/` comments. This is what rust does to that block:
fn block() {
// ANCHOR: block
/*
a b c
ddd
ee f g
*/
let baz = 8;
// ANCHOR_END: block
}
Notice it indents everything, including the */
, which isn't desirable.
However I found a case where the formatter clearly does the wrong thing with /**/
comments. Inline comment with empty function:
fn my_function(my_parameter: u64 /* ... */ ) {}
formats to:
fn my_function(my_parameter: u64) { /* ... */ }
Originally posted by @sdankel in https://github.com/FuelLabs/sway/issues/2933#issuecomment-1709220764
Some other things to test related to this issue, mainly stability testing:
- what happens to the same code if formatted with empty params?
- what happens when formatting the bottom block, eg formatting the formatted code?
- what happens when formatting the same code when the multiline comment is placed between the ident and the opening parenthesis of the params? or between the function keyword and the ident? between the closing parenthesis and the opening curly brace of the fn body?
A good test for stability might be:
fn /* fn */ my_function /* ident */ ( /* params */ my_parameter /* */ : /* */ u64 /* */ ) /* */ { /* ... */ }
Though some of this we may expect to not parse.