-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format function types. #1288
Format function types. #1288
Conversation
This involves formatting parameter lists which is a big piece of work. They work similar to argument lists and collection literals... except for the special syntax around `[ ... ]` and `{ ... }` for optional parameters. Getting that working right involved adding some more functionality to DelimitedListBuilder and ListPiece. Getting comments working with that syntax was particularly difficult. I ended up deciding that the formatter can move comments before or after the optional parameter delimiters if it needs to. Doing so produces better looking output, as in: ``` // Before: f(// weird comment location [param] // another ); // After: f([ // weird comment location param, // another ]); ``` It also, I think is cleaner to implement than trying to laboriously keep the comment where the user authored it. In the process of reworking how comments are handled in lists, I also tweaked how inline block comments are handled before commas. Previously, they would get moved after the comma, like: ``` // Before: [element /* comment */, another]; // After: [element, /* comment */ another]; ``` Now, they stay where they were, which is I think what users want. A common use case for block comments in argument/collection lists is describing the meaning of a preceding null argument and this keeps that. Line after an element but before the comma continue to be moved after the comma: ``` // Before: f(param // comment ,); // After: f( param, // comment ); ``` Also: - Added tests for the loosened behavior of equalIgnoringWhitespace(). - Added a test for a corner case of variable splitting that I ran into with parameters, which use the same VariablePiece.
equalIgnoringWhitespace().
test/type/function_comment.stmt
Outdated
@@ -0,0 +1,202 @@ | |||
40 columns | | |||
>>> Block comment before first parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have tests for inline block comments?
(And less exciting, but doc comments also)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These ones are all inline block comments. Updated the descriptions to match and added tests of non-inline block and doc comments.
Deciding how comprehensive to be in tests is always a challenge. In this case, you were exactly right. These tests turned up some bugs. Thanks!
Forgot to say :D |
This involves formatting parameter lists which is a big piece of work. They work similar to argument lists and collection literals... except for the special syntax around
[ ... ]
and{ ... }
for optional parameters.Getting that working right involved adding some more functionality to DelimitedListBuilder and ListPiece.
Getting comments working with that syntax was particularly difficult. I ended up deciding that the formatter can move comments before or after the optional parameter delimiters if it needs to. Doing so produces better looking output, as in:
It also, I think is cleaner to implement than trying to laboriously keep the comment where the user authored it.
In the process of reworking how comments are handled in lists, I also tweaked how inline block comments are handled before commas. Previously, they would get moved after the comma, like:
Now, they stay where they were, which is I think what users want. A common use case for block comments in argument/collection lists is describing the meaning of a preceding null argument and this keeps that.
Line after an element but before the comma continue to be moved after the comma:
Also: