Skip to content

Fix make static to not drop trivia#54216

Merged
ryzngard merged 4 commits intodotnet:mainfrom
Youssef1313:make-static-trivia
Jul 30, 2021
Merged

Fix make static to not drop trivia#54216
ryzngard merged 4 commits intodotnet:mainfrom
Youssef1313:make-static-trivia

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
@ghost ghost added the Area-IDE label Jun 18, 2021
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
Contributor

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
Contributor

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 modified the milestones: Next, 17.0.P4 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