-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use the same spacing between members in decompilation that we do for Metadata-as-Source. #42809
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
Conversation
…Metadata-as-Source.
| else | ||
| { | ||
| newLeadingTrivia.Add(trivia); | ||
| } |
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 was a required and unpleasant change to make. it has to do with how the formatting engine subtly treats the source produced by ILSpy different from normal MAS source. Specifically in MAS we generate like this:
int Foo {get;}//
// this is the comment for Bar
int Bar {get;}
With our formatting rule the formatter converts this to the expected:
int Foo {get;}
//
// this is the comment for Bar
int Bar {get;}
However, with decompilation we start with:
int Foo {get;}
//
// this is the comment for Bar
int Bar {get;}
And no matter what rules i specify the formatting engine will not remove that blank line. I've debugged through the deep bowels of teh formatting engine, and i cannot make any sort of sense of what it is doing here. it literally has an embedded rule deep in the core engine that simply overries any actual provided rules here and change things to be 'preserve lines' for comments. I do not want to change that code, so i'm taking hte much simple approach here of just not having the blank line trivia at the start be jammed in. This seems to have no negative consequences anywhere, and is trivial to do.
| new CSharpParenthesesReducer(), | ||
| new CSharpDefaultExpressionReducer()); | ||
|
|
||
| private class FormattingRule : AbstractMetadataFormattingRule |
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.
moved to its own file.
src/Features/CSharp/Portable/Microsoft.CodeAnalysis.CSharp.Features.csproj
Outdated
Show resolved
Hide resolved
|
|
||
| namespace Microsoft.CodeAnalysis.MetadataAsSource | ||
| { | ||
| internal abstract class AbstractMetadataFormattingRule : AbstractFormattingRule |
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 just a move.
src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj
Outdated
Show resolved
Hide resolved
| using var _ = ArrayBuilder<SyntaxTrivia>.GetInstance(out var newLeadingTrivia); | ||
|
|
||
| foreach (var trivia in node.GetLeadingTrivia()) | ||
| foreach (var trivia in node.GetLeadingTrivia().SkipWhile(t => !t.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia))) |
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 was a required and unpleasant change to make. it has to do with how the formatting engine subtly treats the source produced by ILSpy different from normal MAS source. Specifically in MAS we generate like this:
int Foo {get;}//
// this is the comment for Bar
int Bar {get;}
With our formatting rule the formatter converts this to the expected:
int Foo {get;}
//
// this is the comment for Bar
int Bar {get;}
However, with decompilation we start with:
int Foo {get;}
//
// this is the comment for Bar
int Bar {get;}
And no matter what rules i specify the formatting engine will not remove that blank line. I've debugged through the deep bowels of teh formatting engine, and i cannot make any sort of sense of what it is doing here. it literally has an embedded rule deep in the core engine that simply overries any actual provided rules here and change things to be 'preserve lines' for comments. I do not want to change that code, so i'm taking hte much simple approach here of just not having the blank line trivia at the start be jammed in. This seems to have no negative consequences anywhere, and is trivial to do.
|
Closing out. We're going to go with #42850 as that allows the members to still be spaced (when expanded) but be combined when collapsed. |
Followup to @sharwell's great work
Before:
After: