Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find usage message severity #72326

Merged
merged 1 commit into from
Mar 2, 2024
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 @@ -17,7 +17,7 @@ public IVSTypeScriptStreamingProgressTracker ProgressTracker
=> new VSTypeScriptStreamingProgressTracker(UnderlyingObject.ProgressTracker);

public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
=> UnderlyingObject.ReportMessageAsync(message, cancellationToken);
=> UnderlyingObject.ReportNoResultsAsync(message, cancellationToken);

public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
=> UnderlyingObject.SetSearchTitleAsync(title, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IVSTypeScriptStreamingProgressTracker ProgressTracker
=> new ProgressTracker(_context.ProgressTracker);

public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
=> _context.ReportMessageAsync(message, cancellationToken);
=> _context.ReportNoResultsAsync(message, cancellationToken);

public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
=> _context.SetSearchTitleAsync(title, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Roslyn.Utilities;
Expand Down Expand Up @@ -101,10 +102,10 @@ public async Task AttachToStreamingPresenterAsync(IFindUsagesContext presenterCo
await presenterContext.SetSearchTitleAsync(_state.SearchTitle, cancellationToken).ConfigureAwait(false);

if (_state.Message != null)
await presenterContext.ReportMessageAsync(_state.Message, cancellationToken).ConfigureAwait(false);
await presenterContext.ReportNoResultsAsync(_state.Message, cancellationToken).ConfigureAwait(false);

if (_state.InformationalMessage != null)
await presenterContext.ReportInformationalMessageAsync(_state.InformationalMessage, cancellationToken).ConfigureAwait(false);
await presenterContext.ReportMessageAsync(_state.InformationalMessage, NotificationSeverity.Information, cancellationToken).ConfigureAwait(false);

foreach (var definition in _state.Definitions)
await presenterContext.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -148,25 +149,25 @@ async ValueTask IStreamingProgressTracker.ItemsCompletedAsync(int count, Cancell

#region IFindUsagesContext

async ValueTask IFindUsagesContext.ReportMessageAsync(string message, CancellationToken cancellationToken)
async ValueTask IFindUsagesContext.ReportNoResultsAsync(string message, CancellationToken cancellationToken)
{
using var _ = await _gate.DisposableWaitAsync(cancellationToken).ConfigureAwait(false);
if (IsSwapped)
{
await _streamingPresenterContext.ReportMessageAsync(message, cancellationToken).ConfigureAwait(false);
await _streamingPresenterContext.ReportNoResultsAsync(message, cancellationToken).ConfigureAwait(false);
}
else
{
_state.Message = message;
}
}

async ValueTask IFindUsagesContext.ReportInformationalMessageAsync(string message, CancellationToken cancellationToken)
async ValueTask IFindUsagesContext.ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken)
{
using var _ = await _gate.DisposableWaitAsync(cancellationToken).ConfigureAwait(false);
if (IsSwapped)
{
await _streamingPresenterContext.ReportInformationalMessageAsync(message, cancellationToken).ConfigureAwait(false);
await _streamingPresenterContext.ReportMessageAsync(message, severity, cancellationToken).ConfigureAwait(false);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
Expand Down Expand Up @@ -262,8 +263,8 @@ private async Task FindResultsAsync(
var isFullyLoaded = await service.IsFullyLoadedAsync(cancellationToken).ConfigureAwait(false);
if (!isFullyLoaded)
{
await findContext.ReportInformationalMessageAsync(
EditorFeaturesResources.The_results_may_be_incomplete_due_to_the_solution_still_loading_projects, cancellationToken).ConfigureAwait(false);
await findContext.ReportMessageAsync(
EditorFeaturesResources.The_results_may_be_incomplete_due_to_the_solution_still_loading_projects, NotificationSeverity.Information, cancellationToken).ConfigureAwait(false);
}

// We were able to find the doc prior to loading the workspace (or else we would not have the service).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Utilities;

namespace Microsoft.CodeAnalysis.FindUsages;
Expand All @@ -32,11 +33,11 @@ private sealed class DefinitionTrackingContext(IFindUsagesContext underlyingCont
public IStreamingProgressTracker ProgressTracker
=> _underlyingContext.ProgressTracker;

public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
=> _underlyingContext.ReportMessageAsync(message, cancellationToken);
public ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken)
=> _underlyingContext.ReportNoResultsAsync(message, cancellationToken);

public ValueTask ReportInformationalMessageAsync(string message, CancellationToken cancellationToken)
=> _underlyingContext.ReportInformationalMessageAsync(message, cancellationToken);
public ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken)
=> _underlyingContext.ReportMessageAsync(message, severity, cancellationToken);

public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
=> _underlyingContext.SetSearchTitleAsync(title, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task FindImplementationsAsync(
document, position, cancellationToken).ConfigureAwait(false);
if (symbolAndProjectOpt == null)
{
await context.ReportMessageAsync(
await context.ReportNoResultsAsync(
FeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret, cancellationToken).ConfigureAwait(false);
return;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ await context.SetSearchTitleAsync(

if (implementations.IsEmpty)
{
await context.ReportMessageAsync(FeaturesResources.The_symbol_has_no_implementations, cancellationToken).ConfigureAwait(false);
await context.ReportNoResultsAsync(FeaturesResources.The_symbol_has_no_implementations, cancellationToken).ConfigureAwait(false);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static async Task FindSymbolReferencesAsync(
document, position, cancellationToken).ConfigureAwait(false);
if (symbolAndProject == null)
{
await context.ReportMessageAsync(FeaturesResources.Find_All_References_not_invoked_on_applicable_symbol, cancellationToken).ConfigureAwait(false);
await context.ReportNoResultsAsync(FeaturesResources.Find_All_References_not_invoked_on_applicable_symbol, cancellationToken).ConfigureAwait(false);
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Features/Core/Portable/FindUsages/FindUsagesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Utilities;

namespace Microsoft.CodeAnalysis.FindUsages;
Expand All @@ -17,9 +18,9 @@ protected FindUsagesContext()
ProgressTracker = new StreamingProgressTracker(ReportProgressAsync);
}

public virtual ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken) => default;
public virtual ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken) => default;

public virtual ValueTask ReportInformationalMessageAsync(string message, CancellationToken cancellationToken) => default;
public virtual ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken) => default;

public virtual ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => default;

Expand Down
11 changes: 5 additions & 6 deletions src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Utilities;

namespace Microsoft.CodeAnalysis.FindUsages;
Expand All @@ -19,16 +19,15 @@ internal interface IFindUsagesContext
IStreamingProgressTracker ProgressTracker { get; }

/// <summary>
/// Report a failure message to be displayed to the user. This will be reported if the find operation returns
/// no results.
/// Report a message that the find operation returned no results.
/// </summary>
ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken);
ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken);

/// <summary>
/// Report a informational message to be displayed to the user. This may appear to the user in the results
/// Report a message to be displayed to the user. This may appear to the user in the results
/// UI in some fashion (for example: in an info-bar).
/// </summary>
ValueTask ReportInformationalMessageAsync(string message, CancellationToken cancellationToken);
ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken);

/// <summary>
/// Set the title of the window that results are displayed in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
Expand Down Expand Up @@ -100,10 +101,10 @@ public ValueTask ItemsCompletedAsync(int count, CancellationToken cancellationTo
=> _context.ProgressTracker.ItemsCompletedAsync(count, cancellationToken);

public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
=> _context.ReportMessageAsync(message, cancellationToken);
=> _context.ReportNoResultsAsync(message, cancellationToken);

public ValueTask ReportInformationalMessageAsync(string message, CancellationToken cancellationToken)
=> _context.ReportInformationalMessageAsync(message, cancellationToken);
=> _context.ReportMessageAsync(message, NotificationSeverity.Information, cancellationToken);

public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
=> _context.SetSearchTitleAsync(title, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task FindBasesAsync(IFindUsagesContext context, Document document,

if (symbolAndProjectOpt == null)
{
await context.ReportMessageAsync(
await context.ReportNoResultsAsync(
FeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret, cancellationToken).ConfigureAwait(false);
return;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ await context.SetSearchTitleAsync(

if (!found)
{
await context.ReportMessageAsync(FeaturesResources.The_symbol_has_no_base, cancellationToken).ConfigureAwait(false);
await context.ReportNoResultsAsync(FeaturesResources.The_symbol_has_no_base, cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.Notification;

namespace Microsoft.CodeAnalysis.FindUsages
{
Expand All @@ -29,7 +28,7 @@ internal sealed class SimpleFindUsagesContext : FindUsagesContext
public string Message { get; private set; }
public string SearchTitle { get; private set; }

public override ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
public override ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken)
{
Message = message;
return default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Task OnReferenceFoundAsync(FSharp.FindUsages.FSharpSourceReferenceItem re

public Task ReportMessageAsync(string message)
{
return _context.ReportMessageAsync(message, _cancellationToken).AsTask();
return _context.ReportNoResultsAsync(message, _cancellationToken).AsTask();
}

public Task ReportProgressAsync(int current, int maximum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.CodeAnalysis.FindSymbols.Finders;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
Expand Down Expand Up @@ -489,7 +490,7 @@ protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem defi
}
}

public sealed override ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
public sealed override ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken)
{
lock (Gate)
{
Expand All @@ -499,9 +500,9 @@ public sealed override ValueTask ReportMessageAsync(string message, Cancellation
return ValueTaskFactory.CompletedTask;
}

public sealed override async ValueTask ReportInformationalMessageAsync(string message, CancellationToken cancellationToken)
public sealed override async ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken)
{
await this.Presenter.ReportInformationalMessageAsync(message, cancellationToken).ConfigureAwait(false);
await this.Presenter.ReportMessageAsync(message, severity, cancellationToken).ConfigureAwait(false);
}

protected sealed override ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.TestHooks;
Expand Down Expand Up @@ -326,7 +327,7 @@ private void RemoveExistingInfoBar()
return infoBarHost;
}

private async Task ReportInformationalMessageAsync(string message, CancellationToken cancellationToken)
private async Task ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken)
{
await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
RemoveExistingInfoBar();
Expand All @@ -340,7 +341,13 @@ private async Task ReportInformationalMessageAsync(string message, CancellationT

_infoBar = factory.CreateInfoBar(new InfoBarModel(
message,
KnownMonikers.StatusInformation,
severity switch
{
NotificationSeverity.Information => KnownMonikers.StatusInformation,
NotificationSeverity.Error => KnownMonikers.StatusError,
NotificationSeverity.Warning => KnownMonikers.StatusWarning,
_ => throw ExceptionUtilities.UnexpectedValue(severity),
},
isCloseButtonVisible: false));

infoBarHost.AddInfoBar(_infoBar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;

Expand Down Expand Up @@ -96,10 +97,10 @@ public ValueTask ItemsCompletedAsync(int count, CancellationToken cancellationTo

public IStreamingProgressTracker ProgressTracker => this;

public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
public ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken)
=> _callback.InvokeAsync((callback, cancellationToken) => callback.ReportMessageAsync(_callbackId, message, cancellationToken), cancellationToken);

public ValueTask ReportInformationalMessageAsync(string message, CancellationToken cancellationToken)
public ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken)
=> _callback.InvokeAsync((callback, cancellationToken) => callback.ReportInformationalMessageAsync(_callbackId, message, cancellationToken), cancellationToken);

public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
Expand Down
Loading