Skip to content

Commit

Permalink
React to breaking api change
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Feb 27, 2025
1 parent 5c13e97 commit 2a40af0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,21 @@ protected override CodeAction CreateCodeAction(Document document, SyntaxNode arg
return new CSharpReplaceStringLiteralWithCharLiteralCodeAction(document, argumentListNode, sourceCharLiteral);
}

private sealed class CSharpReplaceStringLiteralWithCharLiteralCodeAction : ReplaceStringLiteralWithCharLiteralCodeAction
private sealed class CSharpReplaceStringLiteralWithCharLiteralCodeAction(
Document document, SyntaxNode argumentListNode, char sourceCharLiteral)
: ReplaceStringLiteralWithCharLiteralCodeAction(document, argumentListNode, sourceCharLiteral)
{
public CSharpReplaceStringLiteralWithCharLiteralCodeAction(Document document, SyntaxNode argumentListNode, char sourceCharLiteral) : base(document, argumentListNode, sourceCharLiteral)
{
}

protected override void ApplyFix(
DocumentEditor editor,
SemanticModel model,
SyntaxNode oldArgumentListNode,
char c)
{
var argumentNode = editor.Generator.Argument(editor.Generator.LiteralExpression(c));
var argumentNode = (ArgumentSyntax)editor.Generator.Argument(editor.Generator.LiteralExpression(c));
var arguments = new[] { argumentNode }.Concat(((ArgumentListSyntax)oldArgumentListNode).Arguments
.Select(arg => model.GetOperation(arg) as IArgumentOperation)
.Where(PreserveArgument)
.Select(arg => arg!.Syntax));
.Select(arg => (arg, operation: model.GetOperation(arg) as IArgumentOperation))
.Where(t => PreserveArgument(t.operation))
.Select(t => t.arg));
var argumentListNode = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments));

editor.ReplaceNode(oldArgumentListNode, argumentListNode.WithTriviaFrom(oldArgumentListNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.NetCore.Analyzers.Performance

Namespace Microsoft.NetCore.VisualBasic.Analyzers.Performance

<ExportCodeFixProvider(LanguageNames.VisualBasic), [Shared]>
Public NotInheritable Class BasicUseStringMethodCharOverloadWithSingleCharactersFixer
Inherits UseStringMethodCharOverloadWithSingleCharactersFixer
Expand Down Expand Up @@ -65,15 +64,16 @@ Namespace Microsoft.NetCore.VisualBasic.Analyzers.Performance
End Sub

Protected Overrides Sub ApplyFix(editor As DocumentEditor, model As SemanticModel, oldArgumentListNode As SyntaxNode, c As Char)
Dim argumentNode = editor.Generator.Argument(editor.Generator.LiteralExpression(c))
Dim argumentNode = DirectCast(editor.Generator.Argument(editor.Generator.LiteralExpression(c)), ArgumentSyntax)
Dim arguments = {argumentNode}.Concat(
CType(oldArgumentListNode, ArgumentListSyntax).Arguments.
[Select](Function(arg) TryCast(model.GetOperation(arg), IArgumentOperation)).Where(Function(arg) PreserveArgument(arg)).[Select](Function(arg) arg.Syntax))
Select(Function(arg) (arg, operation:=TryCast(model.GetOperation(arg), IArgumentOperation))).
Where(Function(t) PreserveArgument(t.operation)).
Select(Function(t) t.arg))
Dim argumentListNode = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))

editor.ReplaceNode(oldArgumentListNode, argumentListNode.WithTriviaFrom(oldArgumentListNode))
End Sub
End Class
End Class

End Namespace

0 comments on commit 2a40af0

Please sign in to comment.