public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeParameterConstraintClauseSyntax constraintClause)) { return; } Document document = context.Document; Diagnostic diagnostic = context.Diagnostics[0]; CodeAction codeAction = CodeAction.Create( CodeFixTitles.AddNewLine, ct => { return(CodeFixHelpers.AddNewLineBeforeAndIncreaseIndentationAsync( document, constraintClause.WhereKeyword, constraintClause.Parent.GetIndentation(ct), ct)); }, GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out MemberDeclarationSyntax memberDeclaration)) { return; } Document document = context.Document; Diagnostic diagnostic = context.Diagnostics[0]; switch (diagnostic.Id) { case DiagnosticIdentifiers.AddNewLineAfterOpeningBraceOfTypeDeclaration: { CodeAction codeAction = CodeAction.Create( CodeFixTitles.AddNewLine, ct => AddNewLineAfterOpeningBraceOfTypeDeclarationAsync(document, memberDeclaration, ct), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } case DiagnosticIdentifiers.AddNewLineBeforeConstructorInitializer: { CodeAction codeAction = CodeAction.Create( CodeFixTitles.AddNewLine, ct => { return(CodeFixHelpers.AddNewLineBeforeAndIncreaseIndentationAsync( document, ((ConstructorDeclarationSyntax)memberDeclaration).Initializer.ColonToken, SyntaxTriviaAnalysis.AnalyzeIndentation(memberDeclaration, ct), ct)); }, GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } } }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out MemberDeclarationSyntax memberDeclaration)) { return; } Document document = context.Document; Diagnostic diagnostic = context.Diagnostics[0]; switch (diagnostic.Id) { case DiagnosticIdentifiers.FormatTypeDeclarationBraces: { CodeAction codeAction = CodeAction.Create( "Format braces on multiple lines", ct => FormatTypeDeclarationBracesOnMultipleLinesAsync(document, memberDeclaration, ct), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } case DiagnosticIdentifiers.PutConstructorInitializerOnItsOwnLine: { CodeAction codeAction = CodeAction.Create( "Put constructor initializer on its own line", ct => { return(CodeFixHelpers.AddNewLineBeforeAndIncreaseIndentationAsync( document, ((ConstructorDeclarationSyntax)memberDeclaration).Initializer.ColonToken, SyntaxTriviaAnalysis.AnalyzeIndentation(memberDeclaration, ct), ct)); }, GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } } }