-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Implement Initializer expression wrappers #39878
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
Implement Initializer expression wrappers #39878
Conversation
The basic class is in place for visual basic to have the appropriate wrapping refactoring. The wrapping is mostly correct and just needs a small tweak for the closing brace to be on a line by itself.
The closing brace is calculated based on what kind of syntax we are dealing with. If it is a DeclarationKind then we can just align it based on the span start. If it is a return statement we need to add an extra tab for spacing because there is no declarationkind for returns and we passed our starting point.
- After wrapping if you tried to get refactorings again it was throwing an exception. Calculating the distance between first node before the { fixed the issue. - The unwrap refactoring wasn't moving the opening { to the previous line
These tests confirm that one when one of the refactoring offerings has been choosen if the user asks for more refactorings they are offered the other two options to rewrite the initializer.
Also, remove the old comments that were copied over from the other wrapping code computer implementations
Resolve the conflicts in FeatureResources.resx
src/EditorFeatures/CSharpTest/Wrapping/InitializerExpressionWrappingTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/Wrapping/InitializerExpressionWrappingTests.cs
Show resolved
Hide resolved
src/EditorFeatures/VisualBasicTest/Wrapping/InitializerExpressionWrappingTests.vb
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/Wrapping/CSharpWrappingCodeRefactoringProvider.cs
Show resolved
Hide resolved
...CSharp/Portable/Wrapping/InitializerExpression/AbstractCSharpInitializerExpressionWrapper.cs
Outdated
Show resolved
Hide resolved
where TListSyntax : SyntaxNode | ||
where TListItemSyntax : SyntaxNode | ||
{ | ||
protected override string Indent_all_items => FeaturesResources.Indent_all_arguments; |
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.
"arguments"?
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.
Whoops, I thought I changed that. I was going to look at removing these sub labels too unless you think they would be better left in. But, as of now each refactoring only has one option and that seems pointless.
|
||
namespace Microsoft.CodeAnalysis.CSharp.Wrapping.InitializerExpression | ||
{ | ||
internal partial class CSharpInitializerExpression : AbstractCSharpInitializerExpressionWrapper<InitializerExpressionSyntax, ExpressionSyntax> |
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.
CSharpInitializerExpressionWrapper
src/Features/CSharp/Portable/Wrapping/InitializerExpression/CSharpInitializerExpression.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/Wrapping/InitializerExpression/CSharpInitializerExpression.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/Wrapping/InitializerExpression/CSharpInitializerExpression.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/Wrapping/InitializerExpression/AbstractInitializerExpression.cs
Outdated
Show resolved
Hide resolved
@jasonmalinowski i believe this community PR is ready for team review. thanks! |
@CyrusNajmabadi, yep, it's on my list along with seemingly everybody else's. Should get to it in a day or two. |
…omputer.cs Co-Authored-By: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Co-Authored-By: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Co-Authored-By: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Thanks @jasonmalinowski ! |
I'm working on resolving the merge conflicts... |
...Core/Portable/Wrapping/AbstractSeparatedListWrapper`2+AbstractSeparatedListCodeComputer`1.cs
Show resolved
Hide resolved
425c27b
to
cb26d8f
Compare
// MethodName( | ||
// int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) | ||
unwrapActions.Add(await GetUnwrapAllCodeActionAsync(parentTitle, WrappingStyle.WrapFirst_IndentRest).ConfigureAwait(false)); | ||
if (this.Wrapper.Supports_UnwrapGroup_WrapFirst_IndentRest) |
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 recommend reviewing with whitespace off.
e4f5b2c
to
425c27b
Compare
Users will now be offered refactoring options for collection initializers. The implementation was modelled after the AbstractSeparatedSyntaxList implementation. This applies to visual basic and c#.
There are 3 choices for users:
Resolves #37428