Skip to content

Commit ff7628d

Browse files
Remove unnecessary lambda in diag service (#77089)
2 parents 1cf42ac + 9e100f0 commit ff7628d

File tree

8 files changed

+17
-91
lines changed

8 files changed

+17
-91
lines changed

src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ void M()
10861086
: root.DescendantNodes().OfType<CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax>().First().Span;
10871087

10881088
await diagnosticIncrementalAnalyzer.GetDiagnosticsForIdsAsync(
1089-
sourceDocument.Project.Solution, sourceDocument.Project.Id, sourceDocument.Id, diagnosticIds: null, shouldIncludeAnalyzer: null, getDocuments: null,
1089+
sourceDocument.Project.Solution, sourceDocument.Project.Id, sourceDocument.Id, diagnosticIds: null, shouldIncludeAnalyzer: null,
10901090
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: true, CancellationToken.None);
10911091
// await diagnosticIncrementalAnalyzer.GetTestAccessor().TextDocumentOpenAsync(sourceDocument);
10921092

src/EditorFeatures/Test/Diagnostics/DiagnosticAnalyzerServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task TestHasSuccessfullyLoadedBeingFalse()
6868
var globalOptions = exportProvider.GetExportedValue<IGlobalOptionService>();
6969

7070
var diagnostics = await analyzer.GetDiagnosticsForIdsAsync(
71-
workspace.CurrentSolution, projectId: workspace.CurrentSolution.ProjectIds.Single(), documentId: null, diagnosticIds: null, shouldIncludeAnalyzer: null, getDocuments: null,
71+
workspace.CurrentSolution, projectId: workspace.CurrentSolution.ProjectIds.Single(), documentId: null, diagnosticIds: null, shouldIncludeAnalyzer: null,
7272
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: false, CancellationToken.None);
7373
Assert.NotEmpty(diagnostics);
7474
}

src/EditorFeatures/TestUtilities/Diagnostics/MockDiagnosticAnalyzerService.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(
7373
/// project must be analyzed to get the complete set of non-local document diagnostics.
7474
/// </param>
7575
/// <param name="cancellationToken">Cancellation token.</param>
76-
Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocumentIds, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken);
76+
Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken);
7777

7878
/// <summary>
7979
/// Get project diagnostics (diagnostics with no source location) of the given diagnostic ids and/or analyzers from
@@ -147,12 +147,4 @@ public static Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForSpanAsync(th
147147
includeCompilerDiagnostics: true, priorityProvider,
148148
diagnosticKind, isExplicit, cancellationToken);
149149
}
150-
151-
public static Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(
152-
this IDiagnosticAnalyzerService service, Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
153-
{
154-
return service.GetDiagnosticsForIdsAsync(
155-
solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, getDocumentIds: null,
156-
includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken);
157-
}
158150
}

src/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public async Task ForceAnalyzeProjectAsync(Project project, CancellationToken ca
107107
}
108108

109109
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(
110-
Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocuments, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
110+
Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
111111
{
112112
var analyzer = CreateIncrementalAnalyzer(solution.Workspace);
113-
return analyzer.GetDiagnosticsForIdsAsync(solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, getDocuments, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken);
113+
return analyzer.GetDiagnosticsForIdsAsync(solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken);
114114
}
115115

116116
public Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(

src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ internal partial class DiagnosticIncrementalAnalyzer
1818
public Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, CancellationToken cancellationToken)
1919
=> new IdeCachedDiagnosticGetter(this, solution, projectId, documentId).GetDiagnosticsAsync(cancellationToken);
2020

21-
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocuments, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
22-
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, getDocuments, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken);
21+
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
22+
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken);
2323

2424
public Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
25-
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId: null, diagnosticIds, shouldIncludeAnalyzer, getDocuments: null, includeLocalDocumentDiagnostics: false, includeNonLocalDocumentDiagnostics).GetProjectDiagnosticsAsync(cancellationToken);
25+
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId: null, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics: false, includeNonLocalDocumentDiagnostics).GetProjectDiagnosticsAsync(cancellationToken);
2626

2727
private abstract class DiagnosticGetter(
2828
DiagnosticIncrementalAnalyzer owner,
2929
Solution solution,
3030
ProjectId projectId,
3131
DocumentId? documentId,
32-
Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocuments,
3332
bool includeLocalDocumentDiagnostics,
3433
bool includeNonLocalDocumentDiagnostics)
3534
{
@@ -41,8 +40,6 @@ private abstract class DiagnosticGetter(
4140
protected readonly bool IncludeLocalDocumentDiagnostics = includeLocalDocumentDiagnostics;
4241
protected readonly bool IncludeNonLocalDocumentDiagnostics = includeNonLocalDocumentDiagnostics;
4342

44-
private readonly Func<Project, DocumentId?, IReadOnlyList<DocumentId>> _getDocuments = getDocuments ?? (static (project, documentId) => documentId != null ? [documentId] : project.DocumentIds);
45-
4643
protected StateManager StateManager => Owner._stateManager;
4744

4845
protected virtual bool ShouldIncludeDiagnostic(DiagnosticData diagnostic) => true;
@@ -59,7 +56,11 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Cancellati
5956
// return diagnostics specific to one project or document
6057
var includeProjectNonLocalResult = DocumentId == null;
6158
return await ProduceProjectDiagnosticsAsync(
62-
project, _getDocuments(project, DocumentId), includeProjectNonLocalResult, cancellationToken).ConfigureAwait(false);
59+
project,
60+
// Ensure we compute and return diagnostics for both the normal docs and the additional docs in this
61+
// project if no specific document id was requested.
62+
this.DocumentId != null ? [this.DocumentId] : [.. project.DocumentIds, .. project.AdditionalDocumentIds],
63+
includeProjectNonLocalResult, cancellationToken).ConfigureAwait(false);
6364
}
6465

6566
protected async Task<ImmutableArray<DiagnosticData>> ProduceProjectDiagnosticsAsync(
@@ -88,7 +89,7 @@ private sealed class IdeCachedDiagnosticGetter(
8889
ProjectId projectId,
8990
DocumentId? documentId)
9091
: DiagnosticGetter(
91-
owner, solution, projectId, documentId, getDocuments: null,
92+
owner, solution, projectId, documentId,
9293
includeLocalDocumentDiagnostics: documentId != null,
9394
includeNonLocalDocumentDiagnostics: documentId != null)
9495
{
@@ -187,11 +188,10 @@ private sealed class IdeLatestDiagnosticGetter(
187188
DocumentId? documentId,
188189
ImmutableHashSet<string>? diagnosticIds,
189190
Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer,
190-
Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocuments,
191191
bool includeLocalDocumentDiagnostics,
192192
bool includeNonLocalDocumentDiagnostics)
193193
: DiagnosticGetter(
194-
owner, solution, projectId, documentId, getDocuments, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics)
194+
owner, solution, projectId, documentId, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics)
195195
{
196196
private readonly ImmutableHashSet<string>? _diagnosticIds = diagnosticIds;
197197
private readonly Func<DiagnosticAnalyzer, bool>? _shouldIncludeAnalyzer = shouldIncludeAnalyzer;

src/LanguageServer/Protocol/Handler/Diagnostics/DiagnosticSources/AbstractWorkspaceDocumentDiagnosticSource.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ AsyncLazy<ILookup<DocumentId, DiagnosticData>> GetLazyDiagnostics()
7878
var allDiagnostics = await diagnosticAnalyzerService.GetDiagnosticsForIdsAsync(
7979
Document.Project.Solution, Document.Project.Id, documentId: null,
8080
diagnosticIds: null, shouldIncludeAnalyzer,
81-
// Ensure we compute and return diagnostics for both the normal docs and the additional docs in this project.
82-
static (project, _) => [.. project.DocumentIds.Concat(project.AdditionalDocumentIds)],
8381
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: true, cancellationToken).ConfigureAwait(false);
8482

8583
// TODO(cyrusn): Should we be filtering out suppressed diagnostics here? This is how the

src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
300300

301301
Private ReadOnly _analyzerInfoCache As DiagnosticAnalyzerInfoCache
302302

303-
Public Sub New(Optional data As ImmutableArray(Of DiagnosticData) = Nothing)
303+
Public Sub New()
304304
_analyzerInfoCache = New DiagnosticAnalyzerInfoCache()
305305
End Sub
306306

@@ -321,7 +321,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
321321
Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)()
322322
End Function
323323

324-
Public Function GetDiagnosticsForIdsAsync(solution As Solution, projectId As ProjectId, documentId As DocumentId, diagnosticIds As ImmutableHashSet(Of String), shouldIncludeAnalyzer As Func(Of DiagnosticAnalyzer, Boolean), getDocuments As Func(Of Project, DocumentId, IReadOnlyList(Of DocumentId)), includeLocalDocumentDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetDiagnosticsForIdsAsync
324+
Public Function GetDiagnosticsForIdsAsync(solution As Solution, projectId As ProjectId, documentId As DocumentId, diagnosticIds As ImmutableHashSet(Of String), shouldIncludeAnalyzer As Func(Of DiagnosticAnalyzer, Boolean), includeLocalDocumentDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetDiagnosticsForIdsAsync
325325
Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)()
326326
End Function
327327

0 commit comments

Comments
 (0)