diff --git a/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs b/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs index 460fac4e1edc3f0eaba537a5fa6198de0a487101..740ec279132d238b494b849920eb7e5bdfc62479 100644 --- a/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs +++ b/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs @@ -220,34 +220,37 @@ public async Task> GetFixesAsync(Document docu { cancellationToken.ThrowIfCancellationRequested(); - Func hasFix = (d) => this.GetFixableDiagnosticIds(fixer, extensionManager).Contains(d.Id); - Func, Task>> getFixes = - async (dxs) => - { - var fixes = ArrayBuilder.GetInstance(); - var context = new CodeFixContext(document, span, dxs, - // TODO: Can we share code between similar lambdas that we pass to this API in BatchFixAllProvider.cs, CodeFixService.cs and CodeRefactoringService.cs? - (action, applicableDiagnostics) => - { - // Serialize access for thread safety - we don't know what thread the fix provider will call this delegate from. - lock (fixes) - { - fixes.Add(new CodeFix(document.Project, action, applicableDiagnostics)); - } - }, - verifyArguments: false, - cancellationToken: cancellationToken); - - var task = fixer.RegisterCodeFixesAsync(context) ?? SpecializedTasks.EmptyTask; - await task.ConfigureAwait(false); - return fixes.ToImmutableAndFree(); - }; - - await AppendFixesOrSuppressionsAsync(document, span, diagnostics, result, fixer, - hasFix, getFixes, cancellationToken).ConfigureAwait(false); + await AppendFixesOrSuppressionsAsync( + document, span, diagnostics, result, fixer, + hasFix: d => this.GetFixableDiagnosticIds(fixer, extensionManager).Contains(d.Id), + getFixes: dxs => GetCodeFixesAsync(document, span, fixer, dxs, cancellationToken), + cancellationToken: cancellationToken).ConfigureAwait(false); } } + private async Task> GetCodeFixesAsync( + Document document, TextSpan span, CodeFixProvider fixer, + ImmutableArray diagnostics, CancellationToken cancellationToken) + { + var fixes = ArrayBuilder.GetInstance(); + var context = new CodeFixContext(document, span, diagnostics, + // TODO: Can we share code between similar lambdas that we pass to this API in BatchFixAllProvider.cs, CodeFixService.cs and CodeRefactoringService.cs? + (action, applicableDiagnostics) => + { + // Serialize access for thread safety - we don't know what thread the fix provider will call this delegate from. + lock (fixes) + { + fixes.Add(new CodeFix(document.Project, action, applicableDiagnostics)); + } + }, + verifyArguments: false, + cancellationToken: cancellationToken); + + var task = fixer.RegisterCodeFixesAsync(context) ?? SpecializedTasks.EmptyTask; + await task.ConfigureAwait(false); + return fixes.ToImmutableAndFree(); + } + private async Task AppendSuppressionsAsync( Document document, TextSpan span, IEnumerable diagnostics, ArrayBuilder result, CancellationToken cancellationToken)