SyntaxGenerator is missing a few operator expression kinds
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
## Background and Motivation
`SyntaxGenerator` provides helpers for most operators, such as `generator.AddExpression`. However, a few are missing:
* `ExclusiveOrExpression`
* `LeftShiftExpression`
* `RightShiftExpression`
* `UnsignedRightShiftExpression` (C# only)
## Proposed API
```csharp
namespace Microsoft.CodeAnalysis.Editing;
public partial class SyntaxGenerator
{
public abstract SyntaxNode ExclusiveOrExpression(SyntaxNode left, SyntaxNode right);
public abstract SyntaxNode LeftShiftExpression(SyntaxNode left, SyntaxNode right);
public abstract SyntaxNode RightShiftExpression(SyntaxNode left, SyntaxNode right);
public abstract SyntaxNode? UnsignedRightShiftExpression(SyntaxNode left, SyntaxNode right);
}
```
## Usage Examples
``` C#
if (invocation.Arguments.Length != 2)
{
break;
}
replacementNode = CreateExclusiveOrExpression(
invocation.Arguments[0].Value.Syntax,
invocation.Arguments[1].Value.Syntax
);
```
## Alternative Designs
Expose the necessary `Parenthesize()` helpers as part of `CSharpSyntaxFactory` and `VisualBasicSyntaxFactory` so that developers can build their own `SyntaxFactory.BinaryExpression(SyntaxKind.ExclusiveOrExpression, (ExpressionSyntax)Parenthesize(left), (ExpressionSyntax)Parenthesize(right))`
## Risks
`UnsignedRightShiftExpression` is C# only. It might be better as some `Try` API or in some `CSharpSyntaxGenerator` specific type.
Contributor guide
Research direction
Start by locating the SyntaxGenerator implementations and existing AddExpression helpers for C# and Visual Basic. Compare how those implementations handle binary operator syntax and review the proposed Parenthesize-based alternative. Done means the listed operator expression helpers are exposed and behave consistently, with UnsignedRightShiftExpression limited appropriately to C#.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100