-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Make event-hookup-completion async, and hook up to the background work indicator #72584
Conversation
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.CSharp.EventHookup; | ||
|
||
internal partial class EventHookupCommandHandler : IChainedCommandHandler<TabKeyCommandArgs> | ||
{ | ||
public void ExecuteCommand(TabKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) | ||
public CommandState GetCommandState(TabKeyCommandArgs args, Func<CommandState> nextHandler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved the simple GetCommandState helper to the top.
{ | ||
_threadingContext.ThrowIfNotOnUIThread(); | ||
if (EventHookupSessionManager.CurrentSession != null) | ||
if (!TryExecuteCommand(args, nextHandler)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execute first calls into the up front synchronous portion of TryExecute. if that part fails, we ensure we're reset back to normal and pass the tab into the editor.
return false; | ||
|
||
// Now emit the event asynchronously. | ||
var token = _asyncListener.BeginAsyncOperation(nameof(ExecuteCommand)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from this point on, we're doing all our work asynchronously, with a BWI in effect.
var eventHandlerMethodName = await getEventNameTask.WithCancellation(cancellationToken).ConfigureAwait(false); | ||
|
||
var solutionAndRenameSpan = await TryGetNewSolutionWithAddedMethodAsync( | ||
document, eventHandlerMethodName, initialCaretPoint.Position, cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doing everything expensive asynchronously.
{ | ||
nextHandler(); | ||
EventHookupSessionManager.CancelAndDismissExistingSessions(); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we check that nothing happened on the ui thread while we were doing the expensive work.
|
||
// The new solution is created, so start user observable changes | ||
var (solutionWithEventHandler, renameSpan) = solutionAndRenameSpan.Value; | ||
var workspace = document.Project.Solution.Workspace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
application to the workspace and start of rename session both happen on the UI thread as required.
|
||
// Ensure no matter what that once tab is hit that we're back to the initial no-session state. We do not | ||
// want to cancel the bg tasks kicked off as we need their values to actually emit the event. | ||
EventHookupSessionManager.DismissExistingSessions(cancelBackgroundTasks: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this dismissed the (Press TAB to insert)
tooltip. we'll then pop up the Generating event...
tooltip below in the BWI.
✅ Successfully linked to Azure Boards work item(s): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite done with review but have a few comments queued
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TypeCharCommand.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs
Outdated
Show resolved
Hide resolved
@@ -19,7 +18,7 @@ internal partial class EventHookupCommandHandler : | |||
public bool ExecuteCommand(EscapeKeyCommandArgs args, CommandExecutionContext context) | |||
{ | |||
_threadingContext.ThrowIfNotOnUIThread(); | |||
EventHookupSessionManager.CancelAndDismissExistingSessions(); | |||
EventHookupSessionManager.DismissExistingSessions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismiss inherently will cancel, if the work has not been detached from teh session.
@sharwell ptal |
var cancellationToken = _cancellationTokenSource.Token; | ||
_textView = textView; | ||
_subjectBuffer = subjectBuffer; | ||
_globalOptions = globalOptions; | ||
this.TESTSessionHookupMutex = testSessionHookupMutex; | ||
|
||
var document = textView.TextSnapshot.GetOpenDocumentInCurrentContextWithChanges(); | ||
var workspace = textView.TextSnapshot.TextBuffer.GetWorkspace(); | ||
if (document != null && workspace != null && workspace.CanApplyChange(ApplyChangesKind.ChangeDocument)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to the caller htat creates the session.
} | ||
} | ||
|
||
internal bool IsTrackingSession() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was actually unused. so just removed.
Fixes AB#1991866