Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public async Task<Project> AddMissingImportsAsync(Document document, TextSpan te
}

// Find fixes for the diagnostic where there is only a single fix.
var usableFixes = await GetUnambiguousFixesAsync(document, diagnostics, cancellationToken).ConfigureAwait(false);
var unambiguousFixes = await GetUnambiguousFixesAsync(document, diagnostics, cancellationToken).ConfigureAwait(false);

// We do not want to add project or framework references without the user's input, so filter those out.
var usableFixes = unambiguousFixes.WhereAsArray(fixData => DoesNotAddReference(fixData, document.Project.Id));
if (usableFixes.IsEmpty)
{
return document.Project;
Expand All @@ -59,6 +62,13 @@ public async Task<Project> AddMissingImportsAsync(Document document, TextSpan te
return newDocument.Project;
}

private bool DoesNotAddReference(AddImportFixData fixData, ProjectId currentProjectId)
{
return (fixData.ProjectReferenceToAdd is null || fixData.ProjectReferenceToAdd == currentProjectId)
&& (fixData.PortableExecutableReferenceProjectId is null || fixData.PortableExecutableReferenceProjectId == currentProjectId)
&& string.IsNullOrEmpty(fixData.AssemblyReferenceAssemblyName);
}

private async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
Expand Down