Skip to content

Commit

Permalink
Diagnostics in additional files are not fixable
Browse files Browse the repository at this point in the history
Fixes #578
  • Loading branch information
sharwell committed Aug 7, 2020
1 parent 93b092f commit 2d3dd7c
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,10 @@ private async Task VerifyFixAsync(

previousDiagnostics = analyzerDiagnostics;

var fixableDiagnostics = analyzerDiagnostics.Where(
diagnostic => codeFixProviders.Any(provider => provider.FixableDiagnosticIds.Contains(diagnostic.Id))).ToImmutableArray();
var fixableDiagnostics = analyzerDiagnostics
.Where(diagnostic => codeFixProviders.Any(provider => provider.FixableDiagnosticIds.Contains(diagnostic.Id)))
.Where(diagnostic => project.GetDocument(diagnostic.Location.SourceTree) is object)
.ToImmutableArray();

if (CodeFixTestBehaviors.HasFlag(CodeFixTestBehaviors.FixOne))
{
Expand Down Expand Up @@ -603,14 +605,15 @@ private async Task VerifyFixAsync(

foreach (var codeFixProvider in codeFixProviders)
{
if (!codeFixProvider.FixableDiagnosticIds.Contains(diagnostic.Id))
if (!codeFixProvider.FixableDiagnosticIds.Contains(diagnostic.Id)
|| !(project.GetDocument(diagnostic.Location.SourceTree) is { } document))
{
// do not pass unsupported diagnostics to a code fix provider
continue;
}

var actionsBuilder = ImmutableArray.CreateBuilder<CodeAction>();
var context = new CodeFixContext(project.GetDocument(diagnostic.Location.SourceTree), diagnostic, (a, d) => actionsBuilder.Add(a), cancellationToken);
var context = new CodeFixContext(document, diagnostic, (a, d) => actionsBuilder.Add(a), cancellationToken);
await codeFixProvider.RegisterCodeFixesAsync(context).ConfigureAwait(false);
actions.AddRange(FilterCodeActions(actionsBuilder.ToImmutable()).Select(action => (action, codeFixProvider)));
}
Expand Down

0 comments on commit 2d3dd7c

Please sign in to comment.