Skip to content

Commit

Permalink
Merge pull request #73213 from CyrusNajmabadi/boxing
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Apr 24, 2024
2 parents 28b39fa + 5401043 commit c145155
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -31,7 +29,7 @@ private sealed class FullSolutionAnalysisDiagnosticSource(TextDocument document,
/// once we compute the diagnostics once for a particular project, we don't need to recompute them again as we
/// walk every document within it.
/// </summary>
private static readonly ConditionalWeakTable<Project, AsyncLazy<IReadOnlyList<DiagnosticData>>> s_projectToDiagnostics = new();
private static readonly ConditionalWeakTable<Project, AsyncLazy<ILookup<DocumentId, DiagnosticData>>> s_projectToDiagnostics = new();

/// <summary>
/// This is a normal document source that represents live/fresh diagnostics that should supersede everything else.
Expand Down Expand Up @@ -67,20 +65,24 @@ public override bool IsLiveSource()
}

var result = await lazyDiagnostics.GetValueAsync(cancellationToken).ConfigureAwait(false);
return (ImmutableArray<DiagnosticData>)result;
return result[Document.Id].ToImmutableArray();

AsyncLazy<IReadOnlyList<DiagnosticData>> GetLazyDiagnostics()
AsyncLazy<ILookup<DocumentId, DiagnosticData>> GetLazyDiagnostics()
{
return s_projectToDiagnostics.GetValue(
Document.Project,
_ => AsyncLazy.Create<IReadOnlyList<DiagnosticData>>(
async cancellationToken => await diagnosticAnalyzerService.GetDiagnosticsForIdsAsync(
Document.Project.Solution, Document.Project.Id, documentId: null,
diagnosticIds: null, shouldIncludeAnalyzer,
// Ensure we compute and return diagnostics for both the normal docs and the additional docs in this project.
static (project, _) => [.. project.DocumentIds.Concat(project.AdditionalDocumentIds)],
includeSuppressedDiagnostics: false,
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: true, cancellationToken).ConfigureAwait(false)));
_ => AsyncLazy.Create(
async cancellationToken =>
{
var allDiagnostics = await diagnosticAnalyzerService.GetDiagnosticsForIdsAsync(
Document.Project.Solution, Document.Project.Id, documentId: null,
diagnosticIds: null, shouldIncludeAnalyzer,
// Ensure we compute and return diagnostics for both the normal docs and the additional docs in this project.
static (project, _) => [.. project.DocumentIds.Concat(project.AdditionalDocumentIds)],
includeSuppressedDiagnostics: false,
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: true, cancellationToken).ConfigureAwait(false);
return allDiagnostics.Where(d => d.DocumentId != null).ToLookup(d => d.DocumentId!);
}));
}
}
}
Expand Down

0 comments on commit c145155

Please sign in to comment.