mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-12-26 15:57:58 +01:00
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
namespace Spectre.Console.Analyzer.FixProviders;
|
|
|
|
/// <summary>
|
|
/// Fix provider to change System.Console calls to AnsiConsole calls.
|
|
/// </summary>
|
|
[ExportCodeFixProvider(LanguageNames.CSharp)]
|
|
[Shared]
|
|
public class StaticAnsiConsoleToInstanceFix : CodeFixProvider
|
|
{
|
|
/// <inheritdoc />
|
|
public sealed override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
|
|
Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id);
|
|
|
|
/// <inheritdoc />
|
|
public sealed override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;
|
|
|
|
/// <inheritdoc />
|
|
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
|
|
{
|
|
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
|
|
if (root != null)
|
|
{
|
|
var methodDeclaration = root.FindNode(context.Span, getInnermostNodeForTie: true).FirstAncestorOrSelf<InvocationExpressionSyntax>();
|
|
if (methodDeclaration != null)
|
|
{
|
|
context.RegisterCodeFix(
|
|
new SwitchToAnsiConsoleAction(
|
|
context.Document,
|
|
methodDeclaration,
|
|
"Convert static AnsiConsole calls to local instance."),
|
|
context.Diagnostics);
|
|
}
|
|
}
|
|
}
|
|
} |