未验证 提交 9948e3d4 编写于 作者: J Joey Robichaud 提交者: GitHub

Filter out missing import fixes that would add references (#36251)

* Filter out missing import fixes that would add references

* Remove superfluous IsEmpty check
上级 1e90094f
......@@ -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;
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册