예제 #1
0
            public void AppendIntersectingSpans(int start, int length, IntervalIntrospector introspector, List <ITagSpan <TTag> > list)
            {
                if (_owner.SubjectBuffer != introspector.Snapshot.TextBuffer)
                {
                    // in venus case, buffer comes and goes and tag source might hold onto diagnostics that belong to
                    // old/new buffers which are different than current subject buffer.
                    return;
                }

                var result = _lastDiagnostics.GetIntersectingInOrderIntervals(start, length, introspector, skipZeroLengthIntervals: false);

                if (result.Count == 0)
                {
                    return;
                }

                foreach (var data in result)
                {
                    var span = data.GetSnapshotSpan(introspector.Snapshot, _owner.MinimumLength);
                    if (span.Length == 0)
                    {
                        continue;
                    }

                    list.Add(_owner.CreateTagSpan(span, data.Diagnostic));
                }
            }
예제 #2
0
        public IList <ITagSpan <TTag> > GetNonIntersectingSpans(SnapshotSpan snapshotSpan)
        {
            var snapshot = snapshotSpan.Snapshot;

            Contract.Requires(snapshot.TextBuffer == _textBuffer);

            var introspector = new IntervalIntrospector(snapshot);

            var beforeSpan = new SnapshotSpan(snapshot, 0, snapshotSpan.Start);
            var before     = _tree.GetIntersectingIntervals(beforeSpan.Start, beforeSpan.Length, introspector)
                             .Where(n => beforeSpan.Contains(n.Span.GetSpan(snapshot)));

            var afterSpan = new SnapshotSpan(snapshot, snapshotSpan.End, snapshot.Length - snapshotSpan.End);
            var after     = _tree.GetIntersectingIntervals(afterSpan.Start, afterSpan.Length, introspector)
                            .Where(n => afterSpan.Contains(n.Span.GetSpan(snapshot)));

            List <ITagSpan <TTag> > result = null;

            foreach (var tagNode in before.Concat(after))
            {
                result = result ?? new List <ITagSpan <TTag> >();
                result.Add(new TagSpan <TTag>(tagNode.Span.GetSpan(snapshot), tagNode.Tag));
            }

            return(result ?? SpecializedCollections.EmptyList <ITagSpan <TTag> >());
        }
예제 #3
0
            public void AppendIntersectingSpans(int start, int length, IntervalIntrospector introspector, List <ITagSpan <TTag> > list)
            {
                if (_owner.SubjectBuffer != introspector.Snapshot.TextBuffer)
                {
                    // in venus case, buffer comes and goes and tag source might hold onto diagnostics that belong to
                    // old/new buffers which are different than current subject buffer.
                    return;
                }

                var result = _lastDiagnostics.GetIntersectingInOrderIntervals(start, length, introspector);

                if (result.Count == 0)
                {
                    return;
                }

                // only follow minimum length for live diagnostic. otherwise, let it be zero length.
                var minimumLegnth = _id is ISupportLiveUpdate ? _owner.MinimumLength : 0;

                foreach (var data in result)
                {
                    var span = data.GetSnapshotSpan(introspector.Snapshot, minimumLegnth);
                    if (span.Length == 0)
                    {
                        continue;
                    }

                    list.Add(_owner.CreateTagSpan(span, data.Diagnostic));
                }
            }
예제 #4
0
        public TagSpanIntervalTree(ITextBuffer textBuffer,
                                   SpanTrackingMode trackingMode,
                                   IEnumerable <ITagSpan <TTag> > values = null)
        {
            _textBuffer       = textBuffer;
            _spanTrackingMode = trackingMode;

            var nodeValues = values?.Select(ts => new TagNode(ts, trackingMode));

            var introspector = new IntervalIntrospector(textBuffer.CurrentSnapshot);

            _tree = IntervalTree.Create(introspector, nodeValues);
        }
예제 #5
0
        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));
                }
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        public IList <ITagSpan <TTag> > GetIntersectingSpans(SnapshotSpan snapshotSpan)
        {
            var snapshot = snapshotSpan.Snapshot;

            Debug.Assert(snapshot.TextBuffer == _textBuffer);

            var introspector          = new IntervalIntrospector(snapshot);
            var intersectingIntervals = _tree.GetIntervalsThatIntersectWith(snapshotSpan.Start, snapshotSpan.Length, introspector);

            List <ITagSpan <TTag> > result = null;

            foreach (var tagNode in intersectingIntervals)
            {
                result = result ?? new List <ITagSpan <TTag> >();
                result.Add(new TagSpan <TTag>(tagNode.Span.GetSpan(snapshot), tagNode.Tag));
            }

            return(result ?? SpecializedCollections.EmptyList <ITagSpan <TTag> >());
        }
예제 #8
0
            private void RecomputeTagsBackground(DiagnosticsUpdatedArgs e, SourceText text, ITextSnapshot snapshot, CancellationToken cancellationToken)
            {
                Contract.ThrowIfNull(e.Solution);

                cancellationToken.ThrowIfCancellationRequested();

                // no diagnostics
                if (e.Diagnostics.IsEmpty)
                {
                    ClearExistingTags(snapshot);
                    return;
                }

                // e.Diagnostics is unordered list and the list could contains overlapping elements
                var diagnostics = GetAugmentedDiagnostics(e.Diagnostics, text, snapshot);

                var introspector = new IntervalIntrospector(snapshot);
                var newTree      = IntervalTree.Create(introspector, diagnostics);

                // new diagnostics
                if (_lastDiagnostics.IsEmpty())
                {
                    _lastDiagnostics = newTree;
                    RaiseTagsChanged(newTree, snapshot);
                    return;
                }

                // diagnostics changed
                var oldTree = _lastDiagnostics;

                _lastDiagnostics = newTree;

                var spans = new NormalizedSnapshotSpanCollection(Difference(newTree, oldTree, new DiffSpanComparer(snapshot, _owner.MinimumLength)));

                if (spans.Count == 0)
                {
                    // no changes
                    return;
                }

                _owner.RaiseTagsChanged(snapshot.TextBuffer, spans);
            }
예제 #9
0
            public override IList <ITagSpan <TTag> > GetIntersectingSpans(SnapshotSpan snapshotSpan)
            {
                if (snapshotSpan.Snapshot.TextBuffer != this.SubjectBuffer)
                {
                    // in venus case, buffer comes and goes and tag source might hold onto diagnostics that belong to
                    // old/new buffers which are different than current subject buffer.
                    return(null);
                }

                var introspector = new IntervalIntrospector(snapshotSpan.Snapshot);

                var result = new List <ITagSpan <TTag> >();

                foreach (var tagSource in _tagSources.Values)
                {
                    tagSource.AppendIntersectingSpans(snapshotSpan.Start, snapshotSpan.Length, introspector, result);
                }

                return(result);
            }
예제 #10
0
        public IList <ITagSpan <TTag> > GetIntersectingSpans(SnapshotSpan snapshotSpan)
        {
            var snapshot = snapshotSpan.Snapshot;

            Contract.Requires(snapshot.TextBuffer == _textBuffer);

            var introspector          = new IntervalIntrospector(snapshot);
            var intersectingIntervals = _tree.GetIntersectingInOrderIntervals(snapshotSpan.Start, snapshotSpan.Length, introspector);

            if (intersectingIntervals.Count == 0)
            {
                return(SpecializedCollections.EmptyList <ITagSpan <TTag> >());
            }

            var result = new List <ITagSpan <TTag> >();

            foreach (var tagNode in intersectingIntervals)
            {
                result.Add(new TagSpan <TTag>(tagNode.Span.GetSpan(snapshot), tagNode.Tag));
            }

            return(result);
        }