private static async Task <Solution> ApplyFixAsync(Document document, SyntaxToken token, string newName, CancellationToken cancellationToken) { var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken) .ConfigureAwait(false); return(await RenameHelper.RenameSymbolAsync(document, syntaxRoot, token, newName, cancellationToken) .ConfigureAwait(false)); }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var syntaxRoot = await document.GetSyntaxRootAsync(context.CancellationToken) .ConfigureAwait(false); foreach (var diagnostic in context.Diagnostics) { if (syntaxRoot.FindToken(diagnostic.Location.SourceSpan.Start) is var token && token.IsKind(SyntaxKind.IdentifierToken) && diagnostic.Properties.TryGetValue("ExpectedName", out var newName)) { context.RegisterCodeFix( CodeAction.Create( $"Rename to: '{newName}'.", cancellationToken => RenameHelper.RenameSymbolAsync(document, syntaxRoot, token, newName, cancellationToken), this.GetType().FullName), diagnostic); } } }