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

Make event-hookup-completion async, and hook up to the background work indicator #72584

Merged
merged 22 commits into from
Mar 19, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Mar 18, 2024

Fixes AB#1991866

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 18, 2024 18:42
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 18, 2024
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)
Copy link
Member Author

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))
Copy link
Member Author

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));
Copy link
Member Author

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);
Copy link
Member Author

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;
}
Copy link
Member Author

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;
Copy link
Member Author

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);
Copy link
Member Author

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.

@Pilchie
Copy link
Member

Pilchie commented Mar 18, 2024

✅ Successfully linked to Azure Boards work item(s):

Copy link
Member

@sharwell sharwell left a 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

@@ -19,7 +18,7 @@ internal partial class EventHookupCommandHandler :
public bool ExecuteCommand(EscapeKeyCommandArgs args, CommandExecutionContext context)
{
_threadingContext.ThrowIfNotOnUIThread();
EventHookupSessionManager.CancelAndDismissExistingSessions();
EventHookupSessionManager.DismissExistingSessions();
Copy link
Member Author

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.

@CyrusNajmabadi
Copy link
Member Author

@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))
Copy link
Member Author

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()
Copy link
Member Author

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.

@CyrusNajmabadi CyrusNajmabadi merged commit 991d1f2 into dotnet:main Mar 19, 2024
27 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the eventHookup branch March 19, 2024 17:31
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Mar 19, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.10 P3 Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants