Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an extensibility point in AnalyzerTest for sorting diagnostics. #1003

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ private static bool IsInSourceFile(DiagnosticResult result, (string filename, So

diagnostics.AddRange(additionalDiagnostics);
var results = SortDistinctDiagnostics(diagnostics);
return results.ToImmutableArray();
return results;
}

protected virtual Task<Compilation> GetProjectCompilationAsync(Project project, IVerifier verifier, CancellationToken cancellationToken)
Expand Down Expand Up @@ -1317,14 +1317,14 @@ protected virtual Workspace CreateWorkspaceImpl()
/// <param name="diagnostics">A collection of <see cref="Diagnostic"/>s to be sorted.</param>
/// <returns>A collection containing the input <paramref name="diagnostics"/>, sorted by
/// <see cref="Diagnostic.Location"/> and <see cref="Diagnostic.Id"/>.</returns>
private static (Project project, Diagnostic diagnostic)[] SortDistinctDiagnostics(IEnumerable<(Project project, Diagnostic diagnostic)> diagnostics)
protected virtual ImmutableArray<(Project project, Diagnostic diagnostic)> SortDistinctDiagnostics(IEnumerable<(Project project, Diagnostic diagnostic)> diagnostics)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
{
return diagnostics
.OrderBy(d => d.diagnostic.Location.GetLineSpan().Path, StringComparer.Ordinal)
.ThenBy(d => d.diagnostic.Location.SourceSpan.Start)
.ThenBy(d => d.diagnostic.Location.SourceSpan.End)
.ThenBy(d => d.diagnostic.Id)
.ThenBy(d => GetArguments(d.diagnostic), LexicographicComparer.Instance).ToArray();
.ThenBy(d => GetArguments(d.diagnostic), LexicographicComparer.Instance).ToImmutableArray();
}

private static IReadOnlyList<object?> GetArguments(Diagnostic diagnostic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ virtual Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.GetDefaultDiagnos
virtual Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.GetProjectCompilationAsync(Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Microsoft.CodeAnalysis.Compilation>
virtual Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.IsCompilerDiagnosticIncluded(Microsoft.CodeAnalysis.Diagnostic diagnostic, Microsoft.CodeAnalysis.Testing.CompilerDiagnostics compilerDiagnostics) -> bool
virtual Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.RunImplAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task
virtual Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.SortDistinctDiagnostics(System.Collections.Generic.IEnumerable<(Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.Diagnostic diagnostic)> diagnostics) -> System.Collections.Immutable.ImmutableArray<(Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.Diagnostic diagnostic)>
virtual Microsoft.CodeAnalysis.Testing.CodeActionTest<TVerifier>.FilterCodeActions(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeActions.CodeAction> actions) -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CodeActions.CodeAction>
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.CreateMessage(string message) -> string
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.Empty<T>(string collectionName, System.Collections.Generic.IEnumerable<T> collection) -> void
Expand Down