Skip to content

Commit ccaf149

Browse files
Merge remote-tracking branch 'origin/renameTrackingExtensino2' into waitAndGetResult
2 parents ba9194b + cdb3c71 commit ccaf149

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.TrackingSession.cs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,8 @@ public TrackingSession(
7373
_isRenamableIdentifierTask = DetermineIfRenamableIdentifierAsync(snapshotSpan, initialCheck: true);
7474
_isRenamableIdentifierTask.ReportNonFatalErrorAsync();
7575

76-
var asyncToken = _asyncListener.BeginAsyncOperation(GetType().Name + ".UpdateTrackingSessionAfterIsRenamableIdentifierTask");
77-
78-
_isRenamableIdentifierTask.SafeContinueWithFromAsync(
79-
async t =>
80-
{
81-
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken).NoThrowAwaitable();
82-
83-
// Avoid throwing an exception in this common case
84-
if (_cancellationToken.IsCancellationRequested)
85-
return;
86-
87-
stateMachine.UpdateTrackingSessionIfRenamable();
88-
},
89-
_cancellationToken,
90-
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
91-
TaskScheduler.Default).CompletesAsyncOperation(asyncToken);
76+
SwitchToMainThreadAfterAndUpdateSessionTrackerAsync(_isRenamableIdentifierTask).CompletesAsyncOperation(
77+
_asyncListener.BeginAsyncOperation(GetType().Name + ".UpdateTrackingSessionAfterIsRenamableIdentifierTask"));
9278

9379
QueueUpdateToStateMachine(stateMachine, _isRenamableIdentifierTask);
9480
}
@@ -101,28 +87,41 @@ public TrackingSession(
10187

10288
_isRenamableIdentifierTask = s_notRenamableTask;
10389
}
90+
91+
return;
92+
93+
async Task SwitchToMainThreadAfterAndUpdateSessionTrackerAsync(Task isRenamableIdentifierTask)
94+
{
95+
// Use CA(true) so we can stay on the UI thread if already there.
96+
await isRenamableIdentifierTask.ConfigureAwait(true);
97+
98+
// Avoid throwing an exception in this common case
99+
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken).NoThrowAwaitable();
100+
if (_cancellationToken.IsCancellationRequested)
101+
return;
102+
103+
stateMachine.UpdateTrackingSessionIfRenamable();
104+
}
104105
}
105106

106107
private void QueueUpdateToStateMachine(StateMachine stateMachine, Task task)
107108
{
108-
var asyncToken = _asyncListener.BeginAsyncOperation($"{GetType().Name}.{nameof(QueueUpdateToStateMachine)}");
109-
110-
task.SafeContinueWithFromAsync(async t =>
111-
{
112-
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken).NoThrowAwaitable();
113-
114-
// Avoid throwing an exception in this common case
115-
if (_cancellationToken.IsCancellationRequested)
116-
return;
117-
118-
if (_isRenamableIdentifierTask.Result != TriggerIdentifierKind.NotRenamable)
119-
{
120-
stateMachine.OnTrackingSessionUpdated(this);
121-
}
122-
},
123-
_cancellationToken,
124-
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
125-
TaskScheduler.Default).CompletesAsyncOperation(asyncToken);
109+
QueueUpdateToStateMachineAsync().CompletesAsyncOperation(
110+
_asyncListener.BeginAsyncOperation($"{GetType().Name}.{nameof(QueueUpdateToStateMachine)}"));
111+
112+
async Task QueueUpdateToStateMachineAsync()
113+
{
114+
// Use CA(true) so we can stay on the UI thread if already there.
115+
await task.ConfigureAwait(true);
116+
117+
// Avoid throwing an exception in this common case
118+
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationToken).NoThrowAwaitable();
119+
if (_cancellationToken.IsCancellationRequested)
120+
return;
121+
122+
if (await _isRenamableIdentifierTask.ConfigureAwait(true) != TriggerIdentifierKind.NotRenamable)
123+
stateMachine.OnTrackingSessionUpdated(this);
124+
}
126125
}
127126

128127
internal void CheckNewIdentifier(StateMachine stateMachine, ITextSnapshot snapshot)

0 commit comments

Comments
 (0)