/// <summary> /// Fix the solution by applying the code fix one fix at the time until it stops fixing the code. /// </summary> /// <returns>The fixed solution or the same instance if no fix.</returns> internal static async Task <Solution> ApplyAllFixableScopeByScopeAsync(Solution solution, DiagnosticAnalyzer analyzer, CodeFixProvider fix, FixAllScope scope, string?fixTitle = null, CancellationToken cancellationToken = default) { var fixable = await Analyze.GetFixableDiagnosticsAsync(solution, analyzer, fix).ConfigureAwait(false); var fixedSolution = solution; int count; do { count = fixable.Count; if (count == 0) { return(fixedSolution); } var diagnosticProvider = await TestDiagnosticProvider.CreateAsync(fixedSolution, fix, fixTitle, fixable).ConfigureAwait(false); fixedSolution = await ApplyAsync(fix, scope, diagnosticProvider, cancellationToken).ConfigureAwait(false); fixable = await Analyze.GetFixableDiagnosticsAsync(fixedSolution, analyzer, fix).ConfigureAwait(false); }while (fixable.Count < count); return(fixedSolution); }
/// <summary> /// Fix the solution by applying the code fix one fix at the time until it stops fixing the code. /// </summary> /// <returns>The fixed solution or the same instance if no fix.</returns> internal static async Task <Solution> ApplyAllFixableOneByOneAsync(Solution solution, DiagnosticAnalyzer analyzer, CodeFixProvider fix, string?fixTitle = null, CancellationToken cancellationToken = default) { var fixable = await Analyze.GetFixableDiagnosticsAsync(solution, analyzer, fix).ConfigureAwait(false); fixable = fixable.OrderBy(x => x.Location, LocationComparer.BySourceSpan).ToArray(); var fixedSolution = solution; int count; do { count = fixable.Count; if (count == 0) { return(fixedSolution); } fixedSolution = await ApplyAsync(fixedSolution, fix, fixable[0], fixTitle, cancellationToken).ConfigureAwait(false); fixable = await Analyze.GetFixableDiagnosticsAsync(fixedSolution, analyzer, fix).ConfigureAwait(false); fixable = fixable.OrderBy(x => x.Location, LocationComparer.BySourceSpan).ToArray(); }while (fixable.Count < count); return(fixedSolution); }