提交 d53fce55 编写于 作者: C CyrusNajmabadi

Merge pull request #11658 from CyrusNajmabadi/fewerAccurateTags

Don't classify the entire document when we're accurate tagging.
......@@ -24,7 +24,7 @@ private class Tagger : ForegroundThreadAffinitizedObject, IAccurateTagger<IClass
private readonly ITaggerEventSource _eventSource;
private TagSpanIntervalTree<IClassificationTag> _cachedTags_doNotAccessDirectly;
private ITextSnapshot _cachedSnapshot_doNotAccessDirectly;
private SnapshotSpan? _cachedTaggedSpan_doNotAccessDirectly;
private IEditorClassificationService _classificationService;
......@@ -62,18 +62,18 @@ private TagSpanIntervalTree<IClassificationTag> CachedTags
}
}
private ITextSnapshot CachedSnapshot
private SnapshotSpan? CachedTaggedSpan
{
get
{
this.AssertIsForeground();
return _cachedSnapshot_doNotAccessDirectly;
return _cachedTaggedSpan_doNotAccessDirectly;
}
set
{
this.AssertIsForeground();
_cachedSnapshot_doNotAccessDirectly = value;
_cachedTaggedSpan_doNotAccessDirectly = value;
}
}
......@@ -94,7 +94,7 @@ private void OnEventSourceChanged()
// When something changes, clear the cached data we have.
this.CachedTags = null;
this.CachedSnapshot = null;
this.CachedTaggedSpan = null;
// And notify any concerned parties that we have new tags.
this.TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(_subjectBuffer.CurrentSnapshot.GetFullSpan()));
......@@ -122,9 +122,19 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetAllTags(NormalizedSnapshotSp
var snapshot = firstSpan.Snapshot;
Debug.Assert(snapshot.TextBuffer == _subjectBuffer);
var cachedSnapshot = this.CachedSnapshot;
// We want to classify from the start of the first requested span to the end of the
// last requested span.
var spanToTag = new SnapshotSpan(snapshot,
Span.FromBounds(spans.First().Start, spans.Last().End));
if (snapshot != cachedSnapshot)
// We don't need to actually classify if what we're being asked for is a subspan
// of the last classification we performed.
var cachedTaggedSpan = this.CachedTaggedSpan;
var canReuseCache =
cachedTaggedSpan?.Snapshot == snapshot &&
cachedTaggedSpan.Value.Contains(spanToTag);
if (!canReuseCache)
{
// Our cache is not there, or is out of date. We need to compute the up to date
// results.
......@@ -138,11 +148,13 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetAllTags(NormalizedSnapshotSp
_classificationService = _classificationService ?? document.Project.LanguageServices.GetService<IEditorClassificationService>();
var context = new TaggerContext<IClassificationTag>(document, snapshot, cancellationToken: cancellationToken);
var spanToTag = new DocumentSnapshotSpan(document, snapshot.GetFullSpan());
var task = SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, _classificationService, _owner._typeMap);
var task = SemanticClassificationUtilities.ProduceTagsAsync(
context, new DocumentSnapshotSpan(document, spanToTag),
_classificationService, _owner._typeMap);
task.Wait(cancellationToken);
CachedSnapshot = snapshot;
CachedTaggedSpan = spanToTag;
CachedTags = new TagSpanIntervalTree<IClassificationTag>(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册