Skip to content
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

Fix make static to not drop trivia #54216

Merged
merged 4 commits into from
Jul 30, 2021
Merged

Conversation

Youssef1313
Copy link
Member

Fixes #54202

First commit is just a cleanup.
Second commit fixes the above issue as well as fixing dropping other modifiers.

Why the old code wasn't working? No idea tbh, I tried to dig into it but wasn't able to find the root cause. I found that SyntaxGenerator is more happy with declarations rather than declarators.

@Youssef1313 Youssef1313 requested a review from a team as a code owner June 18, 2021 18:57
@@ -18,12 +18,12 @@ internal abstract class AbstractMakeMemberStaticCodeFixProvider : SyntaxEditorBa
{
internal sealed override CodeFixCategory CodeFixCategory => CodeFixCategory.Compile;

protected abstract bool IsValidMemberNode([NotNullWhen(true)] SyntaxNode? node);
protected abstract bool TryGetMemberDeclaration(SyntaxNode node, [NotNullWhen(true)] out SyntaxNode? memberDeclaration);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for an abstract class here, only C# is implemented. But I didn't cleanup this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a lot of optimism that this could be in VB :)

Fine to leave for now I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryzngard The situation is the exact opposite in VB.

For C#, a static class requires all members to be static
For VB, a module requires all members to be non-Shared (they're Shared implicitly).

There is a code fix for the VB situation:

https://github.com/dotnet/roslyn/blob/main/src/Features/VisualBasic/Portable/RemoveSharedFromModuleMembers/VisualBasicRemoveSharedFromModuleMembersCodeFixProvider.vb


if (node.IsKind(SyntaxKind.VariableDeclarator))
{
memberDeclaration = node.FirstAncestorOrSelf<MemberDeclarationSyntax>(a => a.IsKind(SyntaxKind.FieldDeclaration) || a.IsKind(SyntaxKind.EventFieldDeclaration));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of walking arbitrarily high, we should check for exactly the shapes we expect here. that prevents thigns like matching on a variable inside a lambda inside a field initializer. In this case, we jsut want to match node { Parent: VaraibleDeclaration { Parent: FieldDeclarationSyntax or EventFieldDeclarationSyntax } }

@Youssef1313
Copy link
Member Author

CI is stuck. Closing and reopening

@Youssef1313 Youssef1313 reopened this Jun 23, 2021
@Youssef1313
Copy link
Member Author

@CyrusNajmabadi Is this ready to merge?

@jinujoseph jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jul 10, 2021
@Youssef1313
Copy link
Member Author

Ping @CyrusNajmabadi

@ryzngard ryzngard enabled auto-merge July 19, 2021 05:38
@ryzngard
Copy link
Contributor

Rerunning tests and enabling automerge. Apologies for the delay @Youssef1313

@Youssef1313
Copy link
Member Author

@ryzngard Can you rerun the failing jobs?

@CyrusNajmabadi
Copy link
Member

i got it.

@ryzngard ryzngard merged commit b818d6a into dotnet:main Jul 30, 2021
@ghost ghost added this to the Next milestone Jul 30, 2021
@dibarbet dibarbet removed this from the Next milestone Aug 31, 2021
@dibarbet dibarbet added this to the 17.0.P4 milestone Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performing quick actions makes unwanted changes
5 participants