public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); Document document = context.Document; Diagnostic diagnostic = context.Diagnostics[0]; SyntaxTree syntaxTree = await document.GetSyntaxTreeAsync(context.CancellationToken).ConfigureAwait(false); int maxLength = AnalyzerOptions.MaxLineLength.GetInt32Value(syntaxTree, document.Project.AnalyzerOptions, AnalyzerSettings.Current.MaxLineLength); SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); var wrapLineNodeFinder = new WrapLineNodeFinder(document, semanticModel, context.Span, maxLength); SyntaxNode nodeToFix = wrapLineNodeFinder.FindNodeToFix(root); if (nodeToFix == null) { return; } CodeAction codeAction = CodeAction.Create( Title, GetCreateChangedDocument(document, nodeToFix), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); return; }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); Document document = context.Document; Diagnostic diagnostic = context.Diagnostics[0]; var maxLength = int.Parse(diagnostic.Properties[LineIsTooLongAnalyzer.PropertyKey]); SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); var wrapLineNodeFinder = new WrapLineNodeFinder(document, semanticModel, context.Span, maxLength); SyntaxNode nodeToFix = wrapLineNodeFinder.FindNodeToFix(root); if (nodeToFix == null) { return; } CodeAction codeAction = CodeAction.Create( Title, GetCreateChangedDocument(document, nodeToFix), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); return; }