diff --git a/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs b/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs index d83a650c6a00cb8622e0d19a837b6e4944b646d0..7c55f92eeb5ec82a1c6cef63b6e512a5aeb5341a 100644 --- a/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs +++ b/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs @@ -160,7 +160,8 @@ public async Task> GetFixesAsync(Document docu // group diagnostics by their diagnostics span // invariant: later code gathers & runs CodeFixProviders for diagnostics with one identical diagnostics span (that gets set later as CodeFixCollection's TextSpan) - Dictionary>? aggregatedDiagnostics = null; + // order diagnostics by span and then diagnostic ID. + SortedDictionary>? aggregatedDiagnostics = null; foreach (var diagnostic in await _diagnosticService.GetDiagnosticsForSpanAsync(document, range, diagnosticIdOpt: null, includeConfigurationFixes, addOperationScope, cancellationToken).ConfigureAwait(false)) { if (diagnostic.IsSuppressed) @@ -170,8 +171,8 @@ public async Task> GetFixesAsync(Document docu cancellationToken.ThrowIfCancellationRequested(); - aggregatedDiagnostics ??= new Dictionary>(); - aggregatedDiagnostics.GetOrAdd(diagnostic.GetTextSpan(), _ => new List()).Add(diagnostic); + aggregatedDiagnostics ??= new SortedDictionary>(); + aggregatedDiagnostics.GetOrAdd(diagnostic.GetTextSpan(), _ => new SortedList()).Add(diagnostic.Id, diagnostic); } if (aggregatedDiagnostics == null) @@ -184,7 +185,7 @@ public async Task> GetFixesAsync(Document docu foreach (var spanAndDiagnostic in aggregatedDiagnostics) { await AppendFixesAsync( - document, spanAndDiagnostic.Key, spanAndDiagnostic.Value, fixAllForInSpan: false, isBlocking, + document, spanAndDiagnostic.Key, spanAndDiagnostic.Value.Values, fixAllForInSpan: false, isBlocking, result, addOperationScope, cancellationToken).ConfigureAwait(false); } @@ -204,7 +205,7 @@ int GetValue(CodeFixCollection c) foreach (var spanAndDiagnostic in aggregatedDiagnostics) { await AppendConfigurationsAsync( - document, spanAndDiagnostic.Key, spanAndDiagnostic.Value, + document, spanAndDiagnostic.Key, spanAndDiagnostic.Value.Values, result, cancellationToken).ConfigureAwait(false); } }