private Task <Document> FixDocumentAsync( Document document, ImmutableArray <Diagnostic> diagnostics, CancellationToken cancellationToken) { var filteredDiagnostics = diagnostics.WhereAsArray(_codeFixProvider.IncludeDiagnosticDuringFixAll); return(_codeFixProvider.FixAllAsync(document, filteredDiagnostics, cancellationToken)); }
private Task <Document> FixDocumentAsync( Document document, ImmutableArray <Diagnostic> diagnostics, CancellationToken cancellationToken) { // Ensure that diagnostics for this document are always in document location // order. This provides a consistent and deterministic order for fixers // that want to update a document. var filteredDiagnostics = diagnostics.WhereAsArray(_codeFixProvider.IncludeDiagnosticDuringFixAll) .Sort((d1, d2) => d1.Location.SourceSpan.Start - d2.Location.SourceSpan.Start); return(_codeFixProvider.FixAllAsync(document, filteredDiagnostics, cancellationToken)); }
private async Task <Document> FixDocumentAsync( FixAllState fixAllState, Document document, ImmutableArray <Diagnostic> diagnostics, CancellationToken cancellationToken) { // Ensure that diagnostics for this document are always in document location // order. This provides a consistent and deterministic order for fixers // that want to update a document. // Also ensure that we do not pass in duplicates by invoking Distinct. // See https://github.com/dotnet/roslyn/issues/31381, that seems to be causing duplicate diagnostics. var filteredDiagnostics = diagnostics.Distinct() .WhereAsArray(d => _codeFixProvider.IncludeDiagnosticDuringFixAll(fixAllState, d, cancellationToken)) .Sort((d1, d2) => d1.Location.SourceSpan.Start - d2.Location.SourceSpan.Start); // PERF: Do not invoke FixAllAsync on the code fix provider if there are no diagnostics to be fixed. if (filteredDiagnostics.Length == 0) { return(document); } return(await _codeFixProvider.FixAllAsync(document, filteredDiagnostics, cancellationToken).ConfigureAwait(false)); }