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 @@ -93,7 +93,7 @@ public async ValueTask<ImmutableArray<DiagnosticData>> 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 [];
Expand All @@ -105,7 +105,7 @@ public async ValueTask<ImmutableArray<DiagnosticData>> 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 [];
Expand All @@ -122,6 +122,9 @@ public async ValueTask<ImmutableArray<DiagnosticData>> ComputeDiagnosticsInProce
_ => throw ExceptionUtilities.UnexpectedValue(kind),
};

if (diagnostics.IsEmpty)
return [];

// Remap diagnostic locations, if required.
diagnostics = await RemapDiagnosticLocationsIfRequiredAsync(diagnostics).ConfigureAwait(false);

Expand All @@ -132,15 +135,20 @@ public async ValueTask<ImmutableArray<DiagnosticData>> 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
var diags = await diagnostics.ToDiagnosticsAsync(textDocument.Project, cancellationToken).ConfigureAwait(false);
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;
Expand Down
Loading