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
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ private async Task ProduceTagsAsync(
var suppressedDiagnosticsSpans = (NormalizedSnapshotSpanCollection?)null;
buffer?.Properties.TryGetProperty(PredefinedPreviewTaggerKeys.SuppressDiagnosticsSpansKey, out suppressedDiagnosticsSpans);

var diagnosticMode = GlobalOptions.GetDiagnosticMode(InternalDiagnosticsOptions.NormalDiagnosticMode);

var buckets = _diagnosticService.GetPushDiagnosticBuckets(
workspace, document.Project.Id, document.Id, InternalDiagnosticsOptions.NormalDiagnosticMode, cancellationToken);
workspace, document.Project.Id, document.Id, diagnosticMode, cancellationToken);

foreach (var bucket in buckets)
{
Expand All @@ -170,11 +172,13 @@ private async Task ProduceTagsAsync(
{
try
{
var diagnosticMode = GlobalOptions.GetDiagnosticMode(InternalDiagnosticsOptions.NormalDiagnosticMode);

var id = bucket.Id;
var diagnostics = await _diagnosticService.GetPushDiagnosticsAsync(
workspace, document.Project.Id, document.Id, id,
includeSuppressedDiagnostics: false,
diagnosticMode: InternalDiagnosticsOptions.NormalDiagnosticMode,
diagnosticMode,
cancellationToken).ConfigureAwait(false);

var isLiveUpdate = id is ISupportLiveUpdate;
Expand Down
28 changes: 17 additions & 11 deletions src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ public async Task TestGetDiagnostics1()
var id = Tuple.Create(workspace, document);
var diagnostic = RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, document.Id, id);

var data1 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var diagnosticMode = DiagnosticMode.Default;

var data1 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(diagnostic, data1.Single());

var data2 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, null, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data2 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, null, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(diagnostic, data2.Single());

var data3 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data3 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(diagnostic, data3.Single());

var data4 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, id, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data4 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, id, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(diagnostic, data4.Single());
}

Expand Down Expand Up @@ -86,19 +88,21 @@ public async Task TestGetDiagnostics2()
RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, null, id3);
RaiseDiagnosticEvent(mutex, source, workspace, null, null, Tuple.Create(workspace));

var data1 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var diagnosticMode = DiagnosticMode.Default;

var data1 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(5, data1.Count());

var data2 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, null, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data2 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, null, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(4, data2.Count());

var data3 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, null, id3, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data3 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, null, id3, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(1, data3.Count());

var data4 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data4 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(2, data4.Count());

var data5 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, id, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data5 = await diagnosticService.GetPushDiagnosticsAsync(workspace, document.Project.Id, document.Id, id, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(1, data5.Count());
}

Expand Down Expand Up @@ -128,8 +132,10 @@ public async Task TestCleared()
RaiseDiagnosticEvent(mutex, source2, workspace, document.Project.Id, null, Tuple.Create(workspace, document.Project));
RaiseDiagnosticEvent(mutex, source2, workspace, null, null, Tuple.Create(workspace));

var diagnosticMode = DiagnosticMode.Default;

// confirm data is there.
var data1 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data1 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(5, data1.Count());

diagnosticService.DiagnosticsUpdated -= MarkSet;
Expand All @@ -144,7 +150,7 @@ public async Task TestCleared()
mutex.WaitOne();

// confirm there are 2 data left
var data2 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, InternalDiagnosticsOptions.NormalDiagnosticMode, CancellationToken.None);
var data2 = await diagnosticService.GetPushDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, diagnosticMode, CancellationToken.None);
Assert.Equal(2, data2.Count());

void MarkCalled(object sender, DiagnosticsUpdatedArgs args)
Expand Down
10 changes: 5 additions & 5 deletions src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public MockDiagnosticService()

[Obsolete]
public ImmutableArray<DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
=> GetPushDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, InternalDiagnosticsOptions.NormalDiagnosticMode, cancellationToken).AsTask().WaitAndGetResult_CanCallOnBackground(cancellationToken);
=> GetPushDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, DiagnosticMode.Default, cancellationToken).AsTask().WaitAndGetResult_CanCallOnBackground(cancellationToken);

public ValueTask<ImmutableArray<DiagnosticData>> GetPullDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<DiagnosticData>> GetPullDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
{
return new ValueTask<ImmutableArray<DiagnosticData>>(GetDiagnostics(workspace, projectId, documentId));
}

public ValueTask<ImmutableArray<DiagnosticData>> GetPushDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<DiagnosticData>> GetPushDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
{
return new ValueTask<ImmutableArray<DiagnosticData>>(GetDiagnostics(workspace, projectId, documentId));
}
Expand All @@ -55,12 +55,12 @@ private ImmutableArray<DiagnosticData> GetDiagnostics(Workspace workspace, Proje
return _diagnostic == null ? ImmutableArray<DiagnosticData>.Empty : ImmutableArray.Create(_diagnostic);
}

public ImmutableArray<DiagnosticBucket> GetPullDiagnosticBuckets(Workspace workspace, ProjectId? projectId, DocumentId? documentId, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ImmutableArray<DiagnosticBucket> GetPullDiagnosticBuckets(Workspace workspace, ProjectId? projectId, DocumentId? documentId, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
{
return GetDiagnosticBuckets(workspace, projectId, documentId);
}

public ImmutableArray<DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId? projectId, DocumentId? documentId, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ImmutableArray<DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId? projectId, DocumentId? documentId, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
{
return GetDiagnosticBuckets(workspace, projectId, documentId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics
{
internal static class DiagnosticModeExtensions
{
private static DiagnosticMode GetDiagnosticMode(IGlobalOptionService globalOptions, Option2<DiagnosticMode> option)
public static DiagnosticMode GetDiagnosticMode(this IGlobalOptionService globalOptions, Option2<DiagnosticMode> option)
{
var diagnosticModeOption = globalOptions.GetOption(option);

Expand Down
20 changes: 9 additions & 11 deletions src/Features/Core/Portable/Diagnostics/DiagnosticService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ private void OnCleared(object sender, EventArgs e)

[Obsolete]
ImmutableArray<DiagnosticData> IDiagnosticService.GetDiagnostics(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
=> GetPushDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, InternalDiagnosticsOptions.NormalDiagnosticMode, cancellationToken).AsTask().WaitAndGetResult_CanCallOnBackground(cancellationToken);
=> GetPushDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, _globalOptions.GetDiagnosticMode(InternalDiagnosticsOptions.NormalDiagnosticMode), cancellationToken).AsTask().WaitAndGetResult_CanCallOnBackground(cancellationToken);

public ValueTask<ImmutableArray<DiagnosticData>> GetPullDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<DiagnosticData>> GetPullDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
=> GetDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, forPullDiagnostics: true, diagnosticMode, cancellationToken);

public ValueTask<ImmutableArray<DiagnosticData>> GetPushDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<DiagnosticData>> GetPushDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
=> GetDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, forPullDiagnostics: false, diagnosticMode, cancellationToken);

private ValueTask<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
Expand All @@ -232,13 +232,12 @@ private ValueTask<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
object id,
bool includeSuppressedDiagnostics,
bool forPullDiagnostics,
Option2<DiagnosticMode> diagnosticMode,
DiagnosticMode diagnosticMode,
CancellationToken cancellationToken)
{
// If this is a pull client, but pull diagnostics is not on, then they get nothing. Similarly, if this is a
// push client and pull diagnostics are on, they get nothing.
var isPull = _globalOptions.IsPullDiagnostics(diagnosticMode);
if (forPullDiagnostics != isPull)
if (forPullDiagnostics != (diagnosticMode == DiagnosticMode.Pull))
return new ValueTask<ImmutableArray<DiagnosticData>>(ImmutableArray<DiagnosticData>.Empty);

if (id != null)
Expand Down Expand Up @@ -317,24 +316,23 @@ private async ValueTask<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
return result.ToImmutable();
}

public ImmutableArray<DiagnosticBucket> GetPullDiagnosticBuckets(Workspace workspace, ProjectId projectId, DocumentId documentId, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ImmutableArray<DiagnosticBucket> GetPullDiagnosticBuckets(Workspace workspace, ProjectId projectId, DocumentId documentId, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
=> GetDiagnosticBuckets(workspace, projectId, documentId, forPullDiagnostics: true, diagnosticMode, cancellationToken);

public ImmutableArray<DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId projectId, DocumentId documentId, Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken)
public ImmutableArray<DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId projectId, DocumentId documentId, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
=> GetDiagnosticBuckets(workspace, projectId, documentId, forPullDiagnostics: false, diagnosticMode, cancellationToken);

private ImmutableArray<DiagnosticBucket> GetDiagnosticBuckets(
Workspace workspace,
ProjectId projectId,
DocumentId documentId,
bool forPullDiagnostics,
Option2<DiagnosticMode> diagnosticMode,
DiagnosticMode diagnosticMode,
CancellationToken cancellationToken)
{
// If this is a pull client, but pull diagnostics is not on, then they get nothing. Similarly, if this is a
// push client and pull diagnostics are on, they get nothing.
var isPull = _globalOptions.IsPullDiagnostics(diagnosticMode);
if (forPullDiagnostics != isPull)
if (forPullDiagnostics != (diagnosticMode == DiagnosticMode.Pull))
return ImmutableArray<DiagnosticBucket>.Empty;

using var _1 = ArrayBuilder<DiagnosticBucket>.GetInstance(out var result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Diagnostics
{
Expand Down Expand Up @@ -39,7 +38,7 @@ ImmutableArray<DiagnosticData> GetDiagnostics(
/// will return the requested diagnostics.</param>
ValueTask<ImmutableArray<DiagnosticData>> GetPullDiagnosticsAsync(
Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics,
Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken);
DiagnosticMode diagnosticMode, CancellationToken cancellationToken);

/// <summary>
/// Get current diagnostics stored in IDiagnosticUpdateSource.
Expand All @@ -50,7 +49,7 @@ ValueTask<ImmutableArray<DiagnosticData>> GetPullDiagnosticsAsync(
/// will return the requested diagnostics.</param>
ValueTask<ImmutableArray<DiagnosticData>> GetPushDiagnosticsAsync(
Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics,
Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken);
DiagnosticMode diagnosticMode, CancellationToken cancellationToken);

/// <summary>
/// Get current buckets storing our grouped diagnostics. Specific buckets can be retrieved by calling <see
Expand All @@ -62,7 +61,7 @@ ValueTask<ImmutableArray<DiagnosticData>> GetPushDiagnosticsAsync(
/// will return the requested buckets.</param>
ImmutableArray<DiagnosticBucket> GetPullDiagnosticBuckets(
Workspace workspace, ProjectId? projectId, DocumentId? documentId,
Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken);
DiagnosticMode diagnosticMode, CancellationToken cancellationToken);

/// <summary>
/// Get current buckets storing our grouped diagnostics. Specific buckets can be retrieved by calling <see
Expand All @@ -74,6 +73,6 @@ ImmutableArray<DiagnosticBucket> GetPullDiagnosticBuckets(
/// will return the requested buckets.</param>
ImmutableArray<DiagnosticBucket> GetPushDiagnosticBuckets(
Workspace workspace, ProjectId? projectId, DocumentId? documentId,
Option2<DiagnosticMode> diagnosticMode, CancellationToken cancellationToken);
DiagnosticMode diagnosticMode, CancellationToken cancellationToken);
}
}
Loading