diff --git a/src/Features/Core/Portable/Diagnostics/Service/DocumentAnalysisExecutor.cs b/src/Features/Core/Portable/Diagnostics/Service/DocumentAnalysisExecutor.cs index f8dbe964b2584..8e5c85286f611 100644 --- a/src/Features/Core/Portable/Diagnostics/Service/DocumentAnalysisExecutor.cs +++ b/src/Features/Core/Portable/Diagnostics/Service/DocumentAnalysisExecutor.cs @@ -93,7 +93,7 @@ public async ValueTask> ComputeDiagnosticsInProce if (kind == AnalysisKind.Syntax) { Logger.Log(FunctionId.Diagnostics_SyntaxDiagnostic, - (r, d, a, k) => $"Driver: {r != null}, {d.Id}, {d.Project.Id}, {a}, {k}", _compilationWithAnalyzers, textDocument, analyzer, kind); + static (r, d, a, k) => $"Driver: {r != null}, {d.Id}, {d.Project.Id}, {a}, {k}", _compilationWithAnalyzers, textDocument, analyzer, kind); } return []; @@ -105,7 +105,7 @@ public async ValueTask> ComputeDiagnosticsInProce { var isEnabled = await textDocument.Project.HasSuccessfullyLoadedAsync(cancellationToken).ConfigureAwait(false); - Logger.Log(FunctionId.Diagnostics_SemanticDiagnostic, (a, d, e) => $"{a}, ({d.Id}, {d.Project.Id}), Enabled:{e}", analyzer, textDocument, isEnabled); + Logger.Log(FunctionId.Diagnostics_SemanticDiagnostic, static (a, d, e) => $"{a}, ({d.Id}, {d.Project.Id}), Enabled:{e}", analyzer, textDocument, isEnabled); if (!isEnabled) return []; @@ -122,6 +122,9 @@ public async ValueTask> ComputeDiagnosticsInProce _ => throw ExceptionUtilities.UnexpectedValue(kind), }; + if (diagnostics.IsEmpty) + return []; + // Remap diagnostic locations, if required. diagnostics = await RemapDiagnosticLocationsIfRequiredAsync(diagnostics).ConfigureAwait(false); @@ -132,7 +135,12 @@ public async ValueTask> ComputeDiagnosticsInProce // TODO: Unclear if using the unmapped span here is correct. It does feel somewhat appropriate as the // caller should be asking about diagnostics in an actual document, and not where they were remapped to. diagnostics = diagnostics.WhereAsArray( - d => d.DocumentId is null || span.Value.IntersectsWith(d.DataLocation.UnmappedFileSpan.GetClampedTextSpan(sourceText))); + static (d, args) => + { + var (span, sourceText) = args; + return d.DocumentId is null || span.IntersectsWith(d.DataLocation.UnmappedFileSpan.GetClampedTextSpan(sourceText)); + }, + (span.Value, sourceText)); } #if DEBUG @@ -140,7 +148,7 @@ public async ValueTask> ComputeDiagnosticsInProce var compilation = _compilationWithAnalyzers.Compilation; RoslynDebug.AssertNotNull(compilation); Debug.Assert(diags.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diags, compilation).Count()); - Debug.Assert(diagnostics.Length == Extensions.ConvertToLocalDiagnostics(diags, textDocument, span).Count()); + Debug.Assert(diagnostics.Length == Extensions.ConvertToLocalDiagnostics(diags, textDocument, span).Length); #endif return diagnostics;