Support minimum severity in CreateFixAllContext
This commit is contained in:
Родитель
b3bd4d939b
Коммит
22c5e3fad5
|
@ -247,6 +247,7 @@ namespace Microsoft.CodeAnalysis.Testing
|
|||
/// <param name="scope"><see cref="FixAllScope"/> to fix all occurrences.</param>
|
||||
/// <param name="codeActionEquivalenceKey">The <see cref="CodeAction.EquivalenceKey"/> value expected of a <see cref="CodeAction"/> participating in this fix all.</param>
|
||||
/// <param name="diagnosticIds">Diagnostic Ids to fix.</param>
|
||||
/// <param name="minimumSeverity">The minimum severity of diagnostics to fix in this operation.</param>
|
||||
/// <param name="fixAllDiagnosticProvider">
|
||||
/// <see cref="FixAllContext.DiagnosticProvider"/> to fetch document/project diagnostics to fix in a <see cref="FixAllContext"/>.
|
||||
/// </param>
|
||||
|
@ -260,12 +261,13 @@ namespace Microsoft.CodeAnalysis.Testing
|
|||
FixAllScope scope,
|
||||
string? codeActionEquivalenceKey,
|
||||
IEnumerable<string> diagnosticIds,
|
||||
DiagnosticSeverity minimumSeverity,
|
||||
FixAllContext.DiagnosticProvider fixAllDiagnosticProvider,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return document != null
|
||||
? FixAllContextExtensions.Create(document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken)
|
||||
: new FixAllContext(project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken);
|
||||
? FixAllContextExtensions.Create(document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken)
|
||||
: FixAllContextExtensions.Create(project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -833,7 +835,8 @@ namespace Microsoft.CodeAnalysis.Testing
|
|||
var fixableDocument = project.Solution.GetDocument(firstDiagnostic.Value.diagnostic.Location.SourceTree);
|
||||
var diagnosticSpan = fixableDocument is not null ? firstDiagnostic.Value.diagnostic.Location.SourceSpan : (TextSpan?)null;
|
||||
var relevantIds = fixAllProvider.GetSupportedFixAllDiagnosticIds(effectiveCodeFixProvider);
|
||||
var fixAllContext = CreateFixAllContext(fixableDocument, diagnosticSpan, firstDiagnostic.Value.project, effectiveCodeFixProvider!, scope, equivalenceKey, relevantIds, fixAllDiagnosticProvider, cancellationToken);
|
||||
var minimumSeverity = firstDiagnostic.Value.diagnostic.Severity;
|
||||
var fixAllContext = CreateFixAllContext(fixableDocument, diagnosticSpan, firstDiagnostic.Value.project, effectiveCodeFixProvider!, scope, equivalenceKey, relevantIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken);
|
||||
|
||||
var action = await fixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false);
|
||||
if (action == null)
|
||||
|
|
|
@ -15,25 +15,51 @@ namespace Microsoft.CodeAnalysis.Testing.Extensions;
|
|||
|
||||
internal static class FixAllContextExtensions
|
||||
{
|
||||
private static readonly Func<Document?, TextSpan?, CodeFixProvider, FixAllScope, string?, IEnumerable<string>, FixAllContext.DiagnosticProvider, CancellationToken, FixAllContext> s_createFixAllContextDocument;
|
||||
private static readonly Func<Document?, TextSpan?, CodeFixProvider, FixAllScope, string?, IEnumerable<string>, DiagnosticSeverity, FixAllContext.DiagnosticProvider, CancellationToken, FixAllContext> s_createFixAllContextDocument;
|
||||
private static readonly Func<Project, CodeFixProvider, FixAllScope, string?, IEnumerable<string>, DiagnosticSeverity, FixAllContext.DiagnosticProvider, CancellationToken, FixAllContext> s_createFixAllContextProject;
|
||||
|
||||
static FixAllContextExtensions()
|
||||
{
|
||||
var constructorInfo = typeof(CompilationWithAnalyzers).GetConstructor(new[] { typeof(Document), typeof(TextSpan?), typeof(CodeFixProvider), typeof(FixAllScope), typeof(string), typeof(IEnumerable<string>), typeof(ImmutableArray<DiagnosticAnalyzer>), typeof(FixAllContext.DiagnosticProvider), typeof(CancellationToken) });
|
||||
var constructorInfo = typeof(CompilationWithAnalyzers).GetConstructor(new[] { typeof(Document), typeof(TextSpan?), typeof(CodeFixProvider), typeof(FixAllScope), typeof(string), typeof(IEnumerable<string>), typeof(DiagnosticSeverity), typeof(ImmutableArray<DiagnosticAnalyzer>), typeof(FixAllContext.DiagnosticProvider), typeof(CancellationToken) });
|
||||
if (constructorInfo is not null)
|
||||
{
|
||||
s_createFixAllContextDocument = (document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
s_createFixAllContextDocument = (document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
{
|
||||
return (FixAllContext)Activator.CreateInstance(typeof(FixAllContext), document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken)!;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
constructorInfo = typeof(CompilationWithAnalyzers).GetConstructor(new[] { typeof(Document), typeof(TextSpan?), typeof(CodeFixProvider), typeof(FixAllScope), typeof(string), typeof(IEnumerable<string>), typeof(ImmutableArray<DiagnosticAnalyzer>), typeof(FixAllContext.DiagnosticProvider), typeof(CancellationToken) });
|
||||
if (constructorInfo is not null)
|
||||
{
|
||||
s_createFixAllContextDocument = (document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
{
|
||||
return (FixAllContext)Activator.CreateInstance(typeof(FixAllContext), document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken)!;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
s_createFixAllContextDocument = (document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
s_createFixAllContextDocument = (document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
new FixAllContext(document, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
constructorInfo = typeof(CompilationWithAnalyzers).GetConstructor(new[] { typeof(Project), typeof(CodeFixProvider), typeof(FixAllScope), typeof(string), typeof(IEnumerable<string>), typeof(DiagnosticSeverity), typeof(ImmutableArray<DiagnosticAnalyzer>), typeof(FixAllContext.DiagnosticProvider), typeof(CancellationToken) });
|
||||
if (constructorInfo is not null)
|
||||
{
|
||||
s_createFixAllContextProject = (project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
{
|
||||
return (FixAllContext)Activator.CreateInstance(typeof(FixAllContext), project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken)!;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
s_createFixAllContextProject = (project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken) =>
|
||||
new FixAllContext(project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public static FixAllContext Create(
|
||||
Document document,
|
||||
TextSpan? diagnosticSpan,
|
||||
|
@ -41,9 +67,23 @@ internal static class FixAllContextExtensions
|
|||
FixAllScope scope,
|
||||
string? codeActionEquivalenceKey,
|
||||
IEnumerable<string> diagnosticIds,
|
||||
DiagnosticSeverity minimumSeverity,
|
||||
FixAllContext.DiagnosticProvider fixAllDiagnosticProvider,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return s_createFixAllContextDocument(document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider, cancellationToken);
|
||||
return s_createFixAllContextDocument(document, diagnosticSpan, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken);
|
||||
}
|
||||
|
||||
public static FixAllContext Create(
|
||||
Project project,
|
||||
CodeFixProvider codeFixProvider,
|
||||
FixAllScope scope,
|
||||
string? codeActionEquivalenceKey,
|
||||
IEnumerable<string> diagnosticIds,
|
||||
DiagnosticSeverity minimumSeverity,
|
||||
FixAllContext.DiagnosticProvider fixAllDiagnosticProvider,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return s_createFixAllContextProject(project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, minimumSeverity, fixAllDiagnosticProvider, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,5 +50,5 @@ static Microsoft.CodeAnalysis.Testing.CodeFixVerifier<TAnalyzer, TCodeFix, TTest
|
|||
static Microsoft.CodeAnalysis.Testing.CodeFixVerifier<TAnalyzer, TCodeFix, TTest, TVerifier>.VerifyCodeFixAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected, string fixedSource) -> System.Threading.Tasks.Task
|
||||
static Microsoft.CodeAnalysis.Testing.CodeFixVerifier<TAnalyzer, TCodeFix, TTest, TVerifier>.VerifyCodeFixAsync(string source, string fixedSource) -> System.Threading.Tasks.Task
|
||||
virtual Microsoft.CodeAnalysis.Testing.CodeFixTest<TVerifier>.CreateCodeFixContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostic> diagnostics, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostic>> registerCodeFix, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.CodeFixes.CodeFixContext
|
||||
virtual Microsoft.CodeAnalysis.Testing.CodeFixTest<TVerifier>.CreateFixAllContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan? diagnosticSpan, Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider codeFixProvider, Microsoft.CodeAnalysis.CodeFixes.FixAllScope scope, string codeActionEquivalenceKey, System.Collections.Generic.IEnumerable<string> diagnosticIds, Microsoft.CodeAnalysis.CodeFixes.FixAllContext.DiagnosticProvider fixAllDiagnosticProvider, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.CodeFixes.FixAllContext
|
||||
virtual Microsoft.CodeAnalysis.Testing.CodeFixTest<TVerifier>.CreateFixAllContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan? diagnosticSpan, Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider codeFixProvider, Microsoft.CodeAnalysis.CodeFixes.FixAllScope scope, string codeActionEquivalenceKey, System.Collections.Generic.IEnumerable<string> diagnosticIds, Microsoft.CodeAnalysis.DiagnosticSeverity minimumSeverity, Microsoft.CodeAnalysis.CodeFixes.FixAllContext.DiagnosticProvider fixAllDiagnosticProvider, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.CodeFixes.FixAllContext
|
||||
virtual Microsoft.CodeAnalysis.Testing.CodeFixTest<TVerifier>.TrySelectDiagnosticToFix(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostic> fixableDiagnostics) -> Microsoft.CodeAnalysis.Diagnostic
|
||||
|
|
Загрузка…
Ссылка в новой задаче