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

Decouple a bit of RenameTrackingTaggerProvider #31890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ private void Buffer_Changed(object sender, TextContentChangedEventArgs e)
SnapshotSpan trackingSpanInNewSnapshot = this.TrackingSession.TrackingSpan.GetSpan(e.After);
if (trackingSpanInNewSnapshot.Contains(change.NewSpan))
{
// Continuing an existing tracking session. If there may have been a tag
// showing, then update the tags.
UpdateTrackingSessionIfRenamable();
this.TrackingSession.CheckNewIdentifier(this, _buffer.CurrentSnapshot);
}
else
{
Expand All @@ -117,16 +115,6 @@ private void Buffer_Changed(object sender, TextContentChangedEventArgs e)
}
}

public void UpdateTrackingSessionIfRenamable()
{
AssertIsForeground();
if (this.TrackingSession.IsDefinitelyRenamableIdentifier())
{
this.TrackingSession.CheckNewIdentifier(this, _buffer.CurrentSnapshot);
TrackingSessionUpdated();
}
}

private bool ShouldClearTrackingSession(ITextChange change)
{
AssertIsForeground();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ public TrackingSession(StateMachine stateMachine, SnapshotSpan snapshotSpan, IAs
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken);
stateMachine.UpdateTrackingSessionIfRenamable();

// While we are still recomputing IsRenamableIdentifier, we skip queueing continuations.
// Now, we should reanalyze what we previously skipped.
CheckNewIdentifier(stateMachine, _trackingSpan.TextBuffer.CurrentSnapshot);
},
_cancellationToken,
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default).CompletesAsyncOperation(asyncToken);

QueueUpdateToStateMachine(stateMachine, _isRenamableIdentifierTask);
}
else
{
Expand Down Expand Up @@ -118,6 +119,18 @@ internal void CheckNewIdentifier(StateMachine stateMachine, ITextSnapshot snapsh
{
AssertIsForeground();

// If we conclusively know the original identifier couldn't be renamed, there's nothing further for us to do.
// If text is typed while we're still determining the answer, we won't process them, but we'll call this again
// in our original continuation of _isRenameableIdentifierTask we started in the constructor.
if (!IsDefinitelyRenamableIdentifier())
{
return;
}

// We call this whenever we have a new snapshot, which means we need to reraise this since
// the tracking span has changed.
stateMachine.OnTrackingSessionUpdated(this);

_newIdentifierBindsTask = _isRenamableIdentifierTask.SafeContinueWithFromAsync(
async t => t.Result != TriggerIdentifierKind.NotRenamable &&
TriggerIdentifierKind.RenamableReference ==
Expand Down