public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out InterpolationSyntax interpolation)) { return; } string innerText = ((LiteralExpressionSyntax)interpolation.Expression).GetStringLiteralInnerText(); CodeAction codeAction = CodeAction.Create( $"Merge '{innerText}' into interpolated string", cancellationToken => MergeInterpolationIntoInterpolatedStringRefactoring.RefactorAsync(context.Document, interpolation, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.MergeInterpolationIntoInterpolatedString)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); InterpolationSyntax interpolation = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <InterpolationSyntax>(); Debug.Assert(interpolation != null, $"{nameof(interpolation)} is null"); if (interpolation == null) { return; } string innerText = SyntaxUtility.GetStringLiteralInnerText((LiteralExpressionSyntax)interpolation.Expression); CodeAction codeAction = CodeAction.Create( $"Merge '{innerText}' into interpolated string", cancellationToken => MergeInterpolationIntoInterpolatedStringRefactoring.RefactorAsync(context.Document, interpolation, cancellationToken), DiagnosticIdentifiers.MergeInterpolationIntoInterpolatedString + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }