Skip to content

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
@ghost ghost 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
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.

/// 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).

}

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.


#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 :)

@CyrusNajmabadi CyrusNajmabadi merged commit f28e37d into dotnet:main Jan 6, 2025
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the generatorParam branch January 6, 2025 21:29
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jan 6, 2025
@dibarbet dibarbet modified the milestones: Next, 17.13 P3 Jan 7, 2025
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