Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ void M()
: root.DescendantNodes().OfType<CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax>().First().Span;

await diagnosticIncrementalAnalyzer.GetDiagnosticsForIdsAsync(
sourceDocument.Project.Solution, sourceDocument.Project.Id, sourceDocument.Id, diagnosticIds: null, shouldIncludeAnalyzer: null, getDocuments: null,
sourceDocument.Project.Solution, sourceDocument.Project.Id, sourceDocument.Id, diagnosticIds: null, shouldIncludeAnalyzer: null,
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: true, CancellationToken.None);
// await diagnosticIncrementalAnalyzer.GetTestAccessor().TextDocumentOpenAsync(sourceDocument);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task TestHasSuccessfullyLoadedBeingFalse()
var globalOptions = exportProvider.GetExportedValue<IGlobalOptionService>();

var diagnostics = await analyzer.GetDiagnosticsForIdsAsync(
workspace.CurrentSolution, projectId: workspace.CurrentSolution.ProjectIds.Single(), documentId: null, diagnosticIds: null, shouldIncludeAnalyzer: null, getDocuments: null,
workspace.CurrentSolution, projectId: workspace.CurrentSolution.ProjectIds.Single(), documentId: null, diagnosticIds: null, shouldIncludeAnalyzer: null,
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: false, CancellationToken.None);
Assert.NotEmpty(diagnostics);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Diagnostics;
Expand Down Expand Up @@ -73,7 +71,7 @@ Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(
/// project must be analyzed to get the complete set of non-local document diagnostics.
/// </param>
/// <param name="cancellationToken">Cancellation token.</param>
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);
Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken);

/// <summary>
/// Get project diagnostics (diagnostics with no source location) of the given diagnostic ids and/or analyzers from
Expand Down Expand Up @@ -103,7 +101,6 @@ Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(
/// </summary>
Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForSpanAsync(
TextDocument document, TextSpan? range, Func<string, bool>? shouldIncludeDiagnostic,
bool includeCompilerDiagnostics,
ICodeActionRequestPriorityProvider priorityProvider,
DiagnosticKind diagnosticKind,
bool isExplicit,
Expand Down Expand Up @@ -144,15 +141,6 @@ public static Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForSpanAsync(th
{
Func<string, bool>? shouldIncludeDiagnostic = diagnosticId != null ? id => id == diagnosticId : null;
return service.GetDiagnosticsForSpanAsync(document, range, shouldIncludeDiagnostic,
includeCompilerDiagnostics: true, priorityProvider,
diagnosticKind, isExplicit, cancellationToken);
}

public static Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(
this IDiagnosticAnalyzerService service, Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
{
return service.GetDiagnosticsForIdsAsync(
solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, getDocumentIds: null,
includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken);
priorityProvider, diagnosticKind, isExplicit, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ private async Task<Document> ApplyCodeFixesForSpecificDiagnosticIdAsync(
// Compute diagnostics for everything that is not an IDE analyzer
var diagnostics = await _diagnosticService.GetDiagnosticsForSpanAsync(document, range,
shouldIncludeDiagnostic: static diagnosticId => !(IDEDiagnosticIdToOptionMappingHelper.IsKnownIDEDiagnosticId(diagnosticId)),
includeCompilerDiagnostics: true,
priorityProvider: new DefaultCodeActionRequestPriorityProvider(),
DiagnosticKind.All, isExplicit: false,
cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override async Task<IEnumerable<Diagnostic>> GetDocumentSpanDiagnosticsAs
{
bool shouldIncludeDiagnostic(string id) => _diagnosticIds == null || _diagnosticIds.Contains(id);
var diagnostics = Filter(await _diagnosticService.GetDiagnosticsForSpanAsync(
document, fixAllSpan, shouldIncludeDiagnostic, includeCompilerDiagnostics: true,
document, fixAllSpan, shouldIncludeDiagnostic,
priorityProvider: new DefaultCodeActionRequestPriorityProvider(),
DiagnosticKind.All, isExplicit: false, cancellationToken).ConfigureAwait(false));
Contract.ThrowIfFalse(diagnostics.All(d => d.DocumentId != null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public CodeFixService(
{
allDiagnostics = await _diagnosticService.GetDiagnosticsForSpanAsync(
document, range, GetShouldIncludeDiagnosticPredicate(document, priorityProvider),
includeCompilerDiagnostics: true, priorityProvider, DiagnosticKind.All, isExplicit: false, cancellationToken).ConfigureAwait(false);
priorityProvider, DiagnosticKind.All, isExplicit: false, cancellationToken).ConfigureAwait(false);

// NOTE(cyrusn): We do not include suppressed diagnostics here as they are effectively hidden from the
// user in the editor. As far as the user is concerned, there is no squiggle for it and no lightbulb
Expand Down Expand Up @@ -199,7 +199,7 @@ public async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
{
diagnostics = await _diagnosticService.GetDiagnosticsForSpanAsync(
document, range, GetShouldIncludeDiagnosticPredicate(document, priorityProvider),
includeCompilerDiagnostics: true, priorityProvider, DiagnosticKind.All, isExplicit: true, cancellationToken).ConfigureAwait(false);
priorityProvider, DiagnosticKind.All, isExplicit: true, cancellationToken).ConfigureAwait(false);
if (!includeSuppressionFixes)
diagnostics = diagnostics.WhereAsArray(d => !d.IsSuppressed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForSpanAsync(
TextDocument document,
TextSpan? range,
Func<string, bool>? shouldIncludeDiagnostic,
bool includeCompilerDiagnostics,
ICodeActionRequestPriorityProvider priorityProvider,
DiagnosticKind diagnosticKinds,
bool isExplicit,
Expand All @@ -89,8 +88,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForSpanAsync(
priorityProvider ??= new DefaultCodeActionRequestPriorityProvider();

return await analyzer.GetDiagnosticsForSpanAsync(
document, range, shouldIncludeDiagnostic, includeCompilerDiagnostics,
priorityProvider, diagnosticKinds, isExplicit, cancellationToken).ConfigureAwait(false);
document, range, shouldIncludeDiagnostic, priorityProvider, diagnosticKinds, isExplicit, cancellationToken).ConfigureAwait(false);
}

public Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(
Expand All @@ -107,10 +105,10 @@ public async Task ForceAnalyzeProjectAsync(Project project, CancellationToken ca
}

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)
Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
{
var analyzer = CreateIncrementalAnalyzer(solution.Workspace);
return analyzer.GetDiagnosticsForIdsAsync(solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, getDocuments, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken);
return analyzer.GetDiagnosticsForIdsAsync(solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken);
}

public Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ internal partial class DiagnosticIncrementalAnalyzer
public Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, CancellationToken cancellationToken)
=> new IdeCachedDiagnosticGetter(this, solution, projectId, documentId).GetDiagnosticsAsync(cancellationToken);

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)
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, getDocuments, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken);
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken);

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

private abstract class DiagnosticGetter(
DiagnosticIncrementalAnalyzer owner,
Solution solution,
ProjectId projectId,
DocumentId? documentId,
Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocuments,
bool includeLocalDocumentDiagnostics,
bool includeNonLocalDocumentDiagnostics)
{
Expand All @@ -41,8 +40,6 @@ private abstract class DiagnosticGetter(
protected readonly bool IncludeLocalDocumentDiagnostics = includeLocalDocumentDiagnostics;
protected readonly bool IncludeNonLocalDocumentDiagnostics = includeNonLocalDocumentDiagnostics;

private readonly Func<Project, DocumentId?, IReadOnlyList<DocumentId>> _getDocuments = getDocuments ?? (static (project, documentId) => documentId != null ? [documentId] : project.DocumentIds);

protected StateManager StateManager => Owner._stateManager;

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

protected async Task<ImmutableArray<DiagnosticData>> ProduceProjectDiagnosticsAsync(
Expand Down Expand Up @@ -88,7 +89,7 @@ private sealed class IdeCachedDiagnosticGetter(
ProjectId projectId,
DocumentId? documentId)
: DiagnosticGetter(
owner, solution, projectId, documentId, getDocuments: null,
owner, solution, projectId, documentId,
includeLocalDocumentDiagnostics: documentId != null,
includeNonLocalDocumentDiagnostics: documentId != null)
{
Expand Down Expand Up @@ -187,11 +188,10 @@ private sealed class IdeLatestDiagnosticGetter(
DocumentId? documentId,
ImmutableHashSet<string>? diagnosticIds,
Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer,
Func<Project, DocumentId?, IReadOnlyList<DocumentId>>? getDocuments,
bool includeLocalDocumentDiagnostics,
bool includeNonLocalDocumentDiagnostics)
: DiagnosticGetter(
owner, solution, projectId, documentId, getDocuments, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics)
owner, solution, projectId, documentId, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics)
{
private readonly ImmutableHashSet<string>? _diagnosticIds = diagnosticIds;
private readonly Func<DiagnosticAnalyzer, bool>? _shouldIncludeAnalyzer = shouldIncludeAnalyzer;
Expand Down
Loading
Loading