提交 2b370e3e 编写于 作者: S Sam Harwell

Remove code that is no longer used following simplifications to ConvertToTagTrees

上级 b9e81c97
......@@ -59,34 +59,6 @@ public IList<ITagSpan<TTag>> GetIntersectingSpans(SnapshotSpan snapshotSpan)
return result ?? SpecializedCollections.EmptyList<ITagSpan<TTag>>();
}
public void GetNonIntersectingSpans(SnapshotSpan snapshotSpan, List<ITagSpan<TTag>> beforeSpans, List<ITagSpan<TTag>> afterSpans)
{
var snapshot = snapshotSpan.Snapshot;
Contract.Requires(snapshot.TextBuffer == _textBuffer);
var introspector = new IntervalIntrospector(snapshot);
var beforeSpan = new SnapshotSpan(snapshot, 0, snapshotSpan.Start);
AddNonIntersectingSpans(beforeSpan, introspector, beforeSpans);
var afterSpan = new SnapshotSpan(snapshot, snapshotSpan.End, snapshot.Length - snapshotSpan.End);
AddNonIntersectingSpans(afterSpan, introspector, afterSpans);
}
private void AddNonIntersectingSpans(
SnapshotSpan span, IntervalIntrospector introspector, List<ITagSpan<TTag>> spans)
{
var snapshot = span.Snapshot;
foreach (var tagNode in _tree.GetIntervalsThatIntersectWith(span.Start, span.Length, introspector))
{
var tagNodeSpan = tagNode.Span.GetSpan(snapshot);
if (span.Contains(tagNodeSpan))
{
spans.Add(new TagSpan<TTag>(tagNodeSpan, tagNode.Tag));
}
}
}
public IEnumerable<ITagSpan<TTag>> GetSpans(ITextSnapshot snapshot)
{
return _tree.Select(tn => new TagSpan<TTag>(tn.Span.GetSpan(snapshot), tn.Tag));
......
......@@ -451,112 +451,6 @@ private IEnumerable<ITagSpan<TTag>> GetNonIntersectingTagSpans(IEnumerable<Snaps
return oldTagTree.GetSpans(snapshot).Except(tagSpansToInvalidate, _tagSpanComparer);
}
private ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> ConvertToTagTree(
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
ILookup<ITextBuffer, ITagSpan<TTag>> newTagsByBuffer,
SnapshotSpan spanTagged)
{
var allBuffers = oldTagTrees.Keys.Concat(newTagsByBuffer.Select(g => g.Key))
.Concat(spanTagged.Snapshot.TextBuffer).Distinct();
var newTagTrees = ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>>.Empty;
foreach (var buffer in allBuffers)
{
var newTagTree = ComputeNewTagTree(spanTagged, oldTagTrees, buffer, newTagsByBuffer[buffer]);
if (newTagTree != null)
{
newTagTrees = newTagTrees.Add(buffer, newTagTree);
}
}
return newTagTrees;
}
/// <summary>
/// This is the same as <see cref="ComputeNewTagTree(ImmutableDictionary{ITextBuffer, TagSpanIntervalTree{TTag}}, ITextBuffer, IEnumerable{ITagSpan{TTag}}, IEnumerable{SnapshotSpan})"/>,
/// just optimized for the case where we were tagging a single snapshot span.
/// </summary>
private TagSpanIntervalTree<TTag> ComputeNewTagTree(
SnapshotSpan spanToInvalidate,
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
ITextBuffer textBuffer,
IEnumerable<ITagSpan<TTag>> newTags)
{
oldTagTrees.TryGetValue(textBuffer, out var oldTagTree);
if (oldTagTree == null)
{
if (newTags.IsEmpty())
{
// We have no new tags, and no old tags either. No need to store anything
// for this buffer.
return null;
}
// If we don't have any old tags then we just need to return the new tags.
return new TagSpanIntervalTree<TTag>(textBuffer, _dataSource.SpanTrackingMode, newTags);
}
// If we're examining a text buffer other than the one we tagged.
if (textBuffer != spanToInvalidate.Snapshot.TextBuffer)
{
// If we have no new tags produced for it, we can just use the old tags for it.
if (newTags.IsEmpty())
{
return oldTagTree;
}
// Otherwise, merge the old and new tags.
var finalTags = oldTagTree.GetSpans(newTags.First().Span.Snapshot).Concat(newTags);
return new TagSpanIntervalTree<TTag>(textBuffer, _dataSource.SpanTrackingMode, finalTags);
}
else
{
// We're examining the buffer we tagged. If we tagged just a portion in the middle
// then produce the new set of tags by taking the old set before the retagged portion,
// then the new tags, then the old tags after the retagged portion. This keeps the
// tags mostly sorted, which helps with producing an accurate diff.
// These lists only live as long as this method. So it's fine for us to do whatever
// we want with them (including mutating them) inside this body.
var beforeTagsToKeep = new List<ITagSpan<TTag>>();
var afterTagsToKeep = new List<ITagSpan<TTag>>();
GetTagsToKeep(oldTagTrees, spanToInvalidate, beforeTagsToKeep, afterTagsToKeep);
// Then union those with the new tags to produce the final tag tree.
var finalTags = beforeTagsToKeep;
finalTags.AddRange(newTags);
finalTags.AddRange(afterTagsToKeep);
return new TagSpanIntervalTree<TTag>(textBuffer, _dataSource.SpanTrackingMode, finalTags);
}
}
/// <summary>
/// Returns all that tags that fully precede 'spanToInvalidate' and all the tags that
/// fully follow it. All the tag spans are normalized to the snapshot passed in through
/// 'spanToInvalidate'.
/// </summary>
private void GetTagsToKeep(
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
SnapshotSpan spanTagged,
List<ITagSpan<TTag>> beforeTags,
List<ITagSpan<TTag>> afterTags)
{
var fullRefresh = spanTagged.Length == spanTagged.Snapshot.Length;
if (fullRefresh)
{
return;
}
// we actually have span to invalidate from old tree
if (!oldTagTrees.TryGetValue(spanTagged.Snapshot.TextBuffer, out var treeForBuffer))
{
return;
}
treeForBuffer.GetNonIntersectingSpans(spanTagged, beforeTags, afterTags);
}
private async Task RecomputeTagsAsync(
object oldState,
SnapshotPoint? caretPosition,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册