提交 10ff6af9 编写于 作者: T Tanner Gooding

Revert "Merge pull request #18383 from CyrusNajmabadi/fastInitialTagging"

This reverts commit 054509fd, reversing
changes made to fc11e8ad.
上级 2d75aa75
......@@ -80,13 +80,6 @@ private sealed partial class TagSource : ForegroundThreadAffinitizedObject
public event EventHandler Paused;
public event EventHandler Resumed;
/// <summary>
/// A cancellation source we use for the initial tagging computation. We only cancel
/// if our ref count actually reaches 0. Otherwise, we always try to compute the initial
/// set of tags for our view/buffer.
/// </summary>
private readonly CancellationTokenSource _initialComputationCancellationTokenSource = new CancellationTokenSource();
public TaggerDelay AddedTagNotificationDelay => _dataSource.AddedTagNotificationDelay;
public TaggerDelay RemovedTagNotificationDelay => _dataSource.RemovedTagNotificationDelay;
......@@ -118,22 +111,8 @@ private sealed partial class TagSource : ForegroundThreadAffinitizedObject
Connect();
// Kick off a task to immediately compute the initial set of tags. This work should
// not be cancellable (except if we get completely released), even if more events come
// in. That way we can get the initial set of results for the buffer as quickly as
// possible, without kicking the work down the road.
var initialTagsCancellationToken = _initialComputationCancellationTokenSource.Token;
if (_workQueue.IsForeground())
{
RecomputeTagsForeground(cancellationTokenOpt: initialTagsCancellationToken);
}
else
{
RegisterNotification(
() => RecomputeTagsForeground(cancellationTokenOpt: initialTagsCancellationToken),
delay: 0,
cancellationToken: initialTagsCancellationToken);
}
// Kick off a task to compute the initial set of tags.
RecalculateTagsOnChanged(new TaggerEventArgs(TaggerDelay.Short));
}
private ITaggerEventSource CreateEventSource()
......@@ -219,13 +198,17 @@ private bool UpToDate
public void RegisterNotification(Action action, int delay, CancellationToken cancellationToken)
=> _notificationService.RegisterNotification(action, delay, _asyncListener.BeginAsyncOperation("TagSource"), cancellationToken);
/// <summary>
/// Called by derived types to enqueue tags re-calculation request
/// </summary>
private void RecalculateTagsOnChanged(TaggerEventArgs e)
{
// First, cancel any previous requests (either still queued, or started). We no longer
// want to continue it if new changes have come in.
_workQueue.CancelCurrentWork();
RegisterNotification(
() => RecomputeTagsForeground(cancellationTokenOpt: null),
RecomputeTagsForeground,
(int)e.Delay.ComputeTimeDelay(_subjectBuffer).TotalMilliseconds,
_workQueue.CancellationToken);
}
......
......@@ -261,11 +261,9 @@ where tagSpan.Span.IntersectsWith(originalSpan)
}
/// <summary>
/// Called on the foreground thread. Can be passed an optional cancellationToken
/// that controls the work being done. If no cancellation token is passed, the one
/// from the <see cref="_workQueue"/> is used.
/// Called on the foreground thread.
/// </summary>
private void RecomputeTagsForeground(CancellationToken? cancellationTokenOpt)
private void RecomputeTagsForeground()
{
_workQueue.AssertIsForeground();
......@@ -277,8 +275,8 @@ private void RecomputeTagsForeground(CancellationToken? cancellationTokenOpt)
// Mark that we're not up to date. We'll remain in that state until the next
// tag production stage finally completes.
this.UpToDate = false;
var cancellationToken = _workQueue.CancellationToken;
var cancellationToken = cancellationTokenOpt ?? _workQueue.CancellationToken;
var spansToTag = GetSpansAndDocumentsToTag();
// Make a copy of all the data we need while we're on the foreground. Then
......@@ -587,6 +585,7 @@ private void ProduceTagsSynchronously(TaggerContext<TTag> context)
var newTagsByBuffer = context.tagSpans.Where(ts => buffersToTag.Contains(ts.Span.Snapshot.TextBuffer))
.ToLookup(t => t.Span.Snapshot.TextBuffer);
var newTagTrees = ConvertToTagTrees(oldTagTrees, newTagsByBuffer, context._spansTagged);
ProcessNewTagTrees(spansToTag, oldTagTrees, newTagTrees, context.State, context.CancellationToken);
}
......
......@@ -42,8 +42,6 @@ private void Dispose()
return;
}
// Stop computing any initial tags if we've been asked for them.
_initialComputationCancellationTokenSource.Cancel();
_disposed = true;
this.Disposed(this, EventArgs.Empty);
GC.SuppressFinalize(this);
......
......@@ -63,37 +63,6 @@ private sealed partial class Tagger : IAccurateTagger<TTag>, IDisposable
_tagSource.TagsChangedForBuffer += OnTagsChangedForBuffer;
_tagSource.Paused += OnPaused;
_tagSource.Resumed += OnResumed;
// There is a many-to-one relationship between Taggers and TagSources. i.e. one
// tag-source can be used by many Taggers. As such, we may be a tagger that is
// wrapping a tag-source that has already produced tags and had sent out the
// notifications about those tags.
//
// However, we still want to notify the code consuming us that we have tags to
// display. That way, tags can display as soon as possible when someone creates
// a new tagger for a view/buffer.
//
// Note: we have to do this in the future instead of right now because we haven't
// even been returned to the caller for them to hook up to change notifications
// from us.
notificationService.RegisterNotification(
() =>
{
if (this.TagsChanged == null)
{
// don't bother reporting tags if no one is listening.
return;
}
var tags = _tagSource.TryGetTagIntervalTreeForBuffer(_subjectBuffer);
if (tags != null)
{
var collection = new NormalizedSnapshotSpanCollection(
tags.GetSpans(_subjectBuffer.CurrentSnapshot).Select(ts => ts.Span));
this.NotifyEditorNow(collection);
}
},
listener.BeginAsyncOperation(GetType().FullName + ".ctor-ReportInitialTags"));
}
public void Dispose()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册