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

Remove need to pass generator parameter to helper methods #76627

Merged
merged 6 commits into from
Jan 6, 2025

Conversation

CyrusNajmabadi
Copy link
Member

Found while doing extract method work. We have a lot of helpers that have to contort themselves to pass other helpers around due to the split between public/internal in syntax generator. Addressed this by makign sure the funcitonality we need is available on both interfaces, with the public side always deferring to the internal side (which can be accessed through a static singleton instance).

@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners January 6, 2025 04:06
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 6, 2025
@dotnet-policy-service dotnet-policy-service bot added VSCode Needs API Review Needs to be reviewed by the API review council labels Jan 6, 2025
@@ -3134,17 +3134,6 @@ private static StatementSyntax AsStatement(SyntaxNode node)
public override SyntaxNode ExpressionStatement(SyntaxNode expression)
=> SyntaxFactory.ExpressionStatement((ExpressionSyntax)expression);

internal override SyntaxNode MemberAccessExpressionWorker(SyntaxNode? expression, SyntaxNode simpleName)
Copy link
Member Author

Choose a reason for hiding this comment

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

lots of impls moved to CSharpSyntaxGeneratorInternal.

@@ -1776,7 +1776,9 @@ internal SyntaxNode InterpolationFormatClause(string format)
/// This is typically a null value for reference types or a zero-filled value for value types.
/// </summary>
public abstract SyntaxNode DefaultExpression(SyntaxNode type);
public abstract SyntaxNode DefaultExpression(ITypeSymbol type);
Copy link
Member Author

Choose a reason for hiding this comment

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

note: it is safe to make an abstract method a non-virtual method in a shipped API. That's because:

  1. callers to this already use callvirt, which works fine on an instance method.
  2. this is a type that is not publicly extendible (it has internal constructors). So no one but us could have been overriding this.

Microsoft.CodeAnalysis.Editing.SyntaxGenerator.ConvertExpression(Microsoft.CodeAnalysis.SyntaxNode type, Microsoft.CodeAnalysis.SyntaxNode expression) -> Microsoft.CodeAnalysis.SyntaxNode
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.DefaultExpression(Microsoft.CodeAnalysis.ITypeSymbol type) -> Microsoft.CodeAnalysis.SyntaxNode
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.IdentifierName(string identifier) -> Microsoft.CodeAnalysis.SyntaxNode
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.MemberAccessExpression(Microsoft.CodeAnalysis.SyntaxNode expression, Microsoft.CodeAnalysis.SyntaxNode memberName) -> Microsoft.CodeAnalysis.SyntaxNode
Copy link
Member Author

Choose a reason for hiding this comment

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

all these changes are safe, and just reflect these methods no longer being abstract. they are now instnace methods that defer to methods on SyntaxGeneratorInternal.

Copy link
Member Author

Choose a reason for hiding this comment

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

(this also means this needs no public API review as there is no actual effective public api change).

@@ -16,14 +15,16 @@ private CSharpFlagsEnumGenerator()
{
}

protected override SyntaxGeneratorInternal SyntaxGenerator
=> CSharpSyntaxGeneratorInternal.Instance;
Copy link
Member Author

Choose a reason for hiding this comment

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

instead of the flags-generator needing to be passed the syntax-generator, it can jsut ask its subclass to provide it. t he subclass provides the internal impl (which can be used from workspace/code-fixes layer), as it supplies everything needed.

@@ -239,4 +241,97 @@ public override SyntaxNode UnaryPattern(SyntaxToken operatorToken, SyntaxNode pa
=> SyntaxFactory.UnaryPattern(operatorToken, (PatternSyntax)Parenthesize(pattern));

#endregion

public override SyntaxNode CastExpression(SyntaxNode type, SyntaxNode expression)
Copy link
Member Author

Choose a reason for hiding this comment

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

these are all moves. From CSharpSyntaxGenerator to CSharpSyntaxGeneratorInternal.

@CyrusNajmabadi
Copy link
Member Author

@ToddGrun @JoeRobich ptal

@CyrusNajmabadi
Copy link
Member Author

@Cosifne ptal :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Needs API Review Needs to be reviewed by the API review council untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants