示例#1
0
        public static SpanData <TData>?GetCurrentSpanReference <TData>(SpanDataCollection <TData> spanReferenceCollection, ITextView textView)
        {
            var caretPos = textView.Caret.Position;

            // There are no refs in virtual space
            if (caretPos.VirtualSpaces > 0)
            {
                return(null);
            }
            var pos = caretPos.BufferPosition;

            // If it's at the end of a word wrapped line, don't mark the reference that's
            // shown on the next line.
            if (caretPos.Affinity == PositionAffinity.Predecessor && pos.Position != 0)
            {
                pos = pos - 1;
                var prevSpanData = spanReferenceCollection.Find(pos.Position);
                if (prevSpanData == null || prevSpanData.Value.Span.End != pos.Position)
                {
                    return(prevSpanData);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(spanReferenceCollection.Find(pos.Position));
            }
        }
示例#2
0
 public void GetData(SnapshotSpan lineExtent, List <BlockStructureData> list)
 {
     foreach (var spanData in coll.Find(lineExtent.Span))
     {
         if (spanData.Span.End == lineExtent.Start.Position)
         {
             continue;
         }
         foreach (var info in spanData.Data)
         {
             var data = CreateBlockStructureData(info, lineExtent.Snapshot);
             if (data != null)
             {
                 list.Add(data.Value);
             }
         }
     }
 }
示例#3
0
        public BracePairResultCollection?GetBracePairs(int position)
        {
            var left  = leftSorted.Find(position);
            var right = rightSorted.Find(position);

            if (left != null && right != null)
            {
                return(new BracePairResultCollection(new BracePairResult(left.Value.Span, left.Value.Data), new BracePairResult(right.Value.Data, right.Value.Span)));
            }
            if (left != null)
            {
                return(new BracePairResultCollection(new BracePairResult(left.Value.Span, left.Value.Data), null));
            }
            if (right != null)
            {
                return(new BracePairResultCollection(new BracePairResult(right.Value.Data, right.Value.Span), null));
            }
            return(null);
        }
示例#4
0
        public IEnumerable <ITagSpan <ITextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (documentViewer is null)
            {
                yield break;
            }
            if (documentViewer.TextView.IsClosed)
            {
                yield break;
            }
            Debug.Assert(!(documentViewerReferenceEnablerProviders is null));
            Debug.Assert(!(documentViewerReferenceEnablers is null));

            // It's not common for both references to be non-null but it does happen if it's VB and the reference
            // is at eg. a Get keyword. For that reason, check for span refs first or we won't see the definition
            // highlight because it's hidden behind another span reference.
            if (!(currentSpanReference is null))
            {
                if (spans.Count == 0)
                {
                    yield break;
                }
                var snapshot = spans[0].Snapshot;
                var theRef   = currentSpanReference.Value;
                foreach (var span in spans)
                {
                    foreach (var spanData in spanReferenceCollection.Find(span.Span))
                    {
                        if (spanData.Span.End > snapshot.Length)
                        {
                            continue;
                        }
                        if (!IsEnabled(spanData.Data.Id))
                        {
                            continue;
                        }
                        if (spanData.Data.Reference is null)
                        {
                            continue;
                        }
                        if (!object.Equals(spanData.Data.Reference, theRef.Data.Reference))
                        {
                            continue;
                        }
                        yield return(new TagSpan <ITextMarkerTag>(new SnapshotSpan(snapshot, spanData.Span), HighlightedReferenceTag));
                    }
                }
            }

            if (!(currentReference is null))
            {
                if (spans.Count == 0)
                {
                    yield break;
                }
                var snapshot = spans[0].Snapshot;
                var theRef   = currentReference.Value;
                foreach (var span in spans)
                {
                    foreach (var spanData in documentViewer.Content.ReferenceCollection.Find(span.Span))
                    {
                        Debug.Assert(spanData.Span.End <= snapshot.Length);
                        if (spanData.Span.End > snapshot.Length)
                        {
                            continue;
                        }
                        if (spanData.Data.IsHidden || spanData.Data.NoFollow)
                        {
                            continue;
                        }
                        var tag = TryGetTextMarkerTag(spanData);
                        if (tag is null)
                        {
                            continue;
                        }
                        if (!SpanDataReferenceInfoExtensions.CompareReferences(spanData.Data, theRef.Data))
                        {
                            continue;
                        }
                        yield return(new TagSpan <ITextMarkerTag>(new SnapshotSpan(snapshot, spanData.Span), tag));
                    }
                }
            }
        }