-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Allow ignore spaces around declaration
to work when preserve single line statements
is set to false
#34959
Conversation
ignore spaces around declaration
to work when preserve single line statements
is set to falseignore spaces around declaration
to work when preserve single line statements
is set to false
@@ -166,7 +166,7 @@ private void RemoveSuppressOperationForBlock(List<SuppressOperation> list, Synta | |||
|
|||
for (int i = 0; i < list.Count; i++) | |||
{ | |||
if (list[i] != null && list[i].TextSpan.Start >= span.Start && list[i].TextSpan.End <= span.End) | |||
if (list[i] != null && list[i].TextSpan.Start >= span.Start && list[i].TextSpan.End <= span.End && list[i].Option == SuppressOption.NoWrappingIfOnSingleLine) |
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.
this is a pretty core method. Can you add comments explaining why this behavior is correct?
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.
When setting these options:
changingOptions.Add(CSharpFormattingOptions.SpacesIgnoreAroundVariableDeclaration, true);
changingOptions.Add(CSharpFormattingOptions.WrappingKeepStatementsOnSingleLine, false);
and running this code:
class Program
{
public void FixMyType()
{
var myint = 0;
}
}
This line of code is removing all three of these entries:
If I leave the NoSpacing entry in the list, it keeps the spacing intact as desired.
There might be another place that is more appropriate to fix it. Any ideas where?
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.
The fix could also be this, if (list[i] != null && list[i].TextSpan.Start >= span.Start && list[i].TextSpan.End <= span.End && list[i].Option != SuppressOption.NoSpacing)
. I'm not familiar enough with this code to know if other features are affected by the same setting.
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.
I would definitely ask @heejaechang about this. I think he's the only one qualified to state the best place for this fix.
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.
I am not sure why code is written this way, but it looks like we are removing suppression operation based on option rather than add suppression operation based on option.
because it is blindly add all suppression rule first and then later try to remove those suppression added, we have this strange code flow.
I think we should have an issue opened saying we should do thing in opposite way where we add suppression rules based on option rather than remove rule based on options
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.
that being said, in current form, what @chborl did is right.
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.
I think we should have an issue opened saying we should do thing in opposite way where we add suppression rules based on option rather than remove rule based on options
I filed this follow-up issue: #35377
a93cd30
to
2a1ae6d
Compare
2a1ae6d
to
5039423
Compare
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.
Thanks for the explanations.
@ManishJayaswal for approval |
Fixes #31868
Who is impacted by this bug?
Users who use Format Document and have these two settings in the .editorconfig
csharp_space_around_declaration_statements = ignore
csharp_preserve_single_line_statements = false
What is the customer scenario and impact of the bug?
If a user has these two settings in their .editorconfig:
csharp_space_around_declaration_statements = ignore
csharp_preserve_single_line_statements = false
When they Format Document the extra spaces around their declaration statements are removed when they should have been ignored.
Expected
Original spacing around the declaration statements should be left alone since user specified
csharp_space_around_declaration_statements = ignore
.Example,
Actual
The original spacing is not maintained. It becomes,
What is the workaround?
After using Format Document, manually redo spacing around declaration statements.
How was the bug found?
Developer Community issue
If this fix is for a regression - what had regressed, when was the regression introduced, and why was the regression originally missed?
Not a regression. Repros in 15.9.11