提交 daef1603 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #20993 from CyrusNajmabadi/emptySpansToTag

Be resilient to getting back no spans to tag.
......@@ -69,6 +69,8 @@ protected override ITaggerEventSource CreateEventSource(ITextView textView, ITex
protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textViewOpt, ITextBuffer subjectBuffer)
{
// Note: this may return no snapshot spans. We have to be resilient to that
// when processing the TaggerContext<>.SpansToTag below.
return textViewOpt.BufferGraph.GetTextBuffers(b => IsSupportedContentType(b.ContentType))
.Select(b => b.CurrentSnapshot.GetFullSpan())
.ToList();
......@@ -91,7 +93,8 @@ protected override Task ProduceTagsAsync(TaggerContext<NavigableHighlightTag> co
return SpecializedTasks.EmptyTask;
}
var document = context.SpansToTag.First(vt => vt.SnapshotSpan.Snapshot == caretPosition.Snapshot).Document;
// GetSpansToTag may have produced no actual spans to tag. Be resilient to that.
var document = context.SpansToTag.FirstOrDefault(vt => vt.SnapshotSpan.Snapshot == caretPosition.Snapshot).Document;
if (document == null)
{
return SpecializedTasks.EmptyTask;
......
......@@ -335,7 +335,7 @@ private CancellationToken GetCancellationToken(bool initialTags)
? _initialComputationCancellationTokenSource.Token
: _workQueue.CancellationToken;
private List<DocumentSnapshotSpan> GetSpansAndDocumentsToTag()
private ImmutableArray<DocumentSnapshotSpan> GetSpansAndDocumentsToTag()
{
_workQueue.AssertIsForeground();
......@@ -356,9 +356,8 @@ private List<DocumentSnapshotSpan> GetSpansAndDocumentsToTag()
// document can be null if the buffer the given span is part of is not part of our workspace.
return new DocumentSnapshotSpan(document, span);
}).ToList();
}).ToImmutableArray();
Debug.Assert(spansAndDocumentsToTag.Count > 0);
return spansAndDocumentsToTag;
}
......@@ -573,7 +572,7 @@ private IEnumerable<ITagSpan<TTag>> GetNonIntersectingTagSpans(IEnumerable<Snaps
object oldState,
SnapshotPoint? caretPosition,
TextChangeRange? textChangeRange,
List<DocumentSnapshotSpan> spansToTag,
ImmutableArray<DocumentSnapshotSpan> spansToTag,
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
bool initialTags,
CancellationToken cancellationToken)
......@@ -618,7 +617,7 @@ private void ProduceTagsSynchronously(TaggerContext<TTag> context)
}
private void ProcessContext(
List<DocumentSnapshotSpan> spansToTag,
ImmutableArray<DocumentSnapshotSpan> spansToTag,
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
TaggerContext<TTag> context,
bool initialTags)
......@@ -636,7 +635,7 @@ private void ProduceTagsSynchronously(TaggerContext<TTag> context)
}
private void ProcessNewTagTrees(
List<DocumentSnapshotSpan> spansToTag,
ImmutableArray<DocumentSnapshotSpan> spansToTag,
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> newTagTrees,
object newState,
......
......@@ -20,7 +20,7 @@ internal class TaggerContext<TTag> where TTag : ITag
internal IEnumerable<DocumentSnapshotSpan> _spansTagged;
internal ImmutableArray<ITagSpan<TTag>>.Builder tagSpans = ImmutableArray.CreateBuilder<ITagSpan<TTag>>();
public IEnumerable<DocumentSnapshotSpan> SpansToTag { get; }
public ImmutableArray<DocumentSnapshotSpan> SpansToTag { get; }
public SnapshotPoint? CaretPosition { get; }
/// <summary>
......@@ -47,14 +47,14 @@ internal class TaggerContext<TTag> where TTag : ITag
SnapshotPoint? caretPosition = null,
TextChangeRange? textChangeRange = null,
CancellationToken cancellationToken = default)
: this(null, new[] { new DocumentSnapshotSpan(document, snapshot.GetFullSpan()) },
: this(null, ImmutableArray.Create(new DocumentSnapshotSpan(document, snapshot.GetFullSpan())),
caretPosition, textChangeRange, null, cancellationToken)
{
}
internal TaggerContext(
object state,
IEnumerable<DocumentSnapshotSpan> spansToTag,
ImmutableArray<DocumentSnapshotSpan> spansToTag,
SnapshotPoint? caretPosition,
TextChangeRange? textChangeRange,
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> existingTags,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册