Пример #1
0
        public void MoveReference(bool forward)
        {
            // Check these references first because if the caret is at a Get declaration (VB), then there's
            // no code references to it, but there's a 'Get' and 'End Get' in these refs that should be used.
            var spanRefData = SpanDataCollectionUtilities.GetCurrentSpanReference(spanReferenceCollection, TextView);

            if (spanRefData?.Data.Reference != null)
            {
                foreach (var newSpanData in GetReferenceInfosFrom(spanReferenceCollection, spanRefData.Value.Span.Start, forward))
                {
                    if (object.Equals(newSpanData.Data.Reference, spanRefData.Value.Data.Reference))
                    {
                        MoveCaretToSpan(newSpanData.Span);
                        break;
                    }
                }
                return;
            }

            var spanData = GetCurrentReferenceInfo();

            if (spanData != null && !spanData.Value.Data.IsHidden)
            {
                foreach (var newSpanData in GetReferenceInfosFrom(spanData.Value.Span.Start, forward))
                {
                    if (!newSpanData.Data.IsHidden && SpanDataReferenceInfoExtensions.CompareReferences(newSpanData.Data, spanData.Value.Data))
                    {
                        MoveCaretToSpan(newSpanData.Span);
                        break;
                    }
                }
                return;
            }
        }
Пример #2
0
 static bool IsSameReference(SpanData <ReferenceInfo>?a, SpanData <ReferenceInfo>?b)
 {
     if (a is null && b is null)
     {
         return(true);
     }
     if (a is null || b is null)
     {
         return(false);
     }
     return(SpanDataReferenceInfoExtensions.CompareReferences(a.Value.Data, b.Value.Data));
 }
Пример #3
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));
                    }
                }
            }
        }
Пример #4
0
 SpanData <ReferenceInfo>?FindDefinition(SpanData <ReferenceInfo> spanData)
 {
     if (spanData.Data.IsDefinition)
     {
         return(spanData);
     }
     return(currentContent.Content.ReferenceCollection.FirstOrNull(other => other.Data.IsDefinition && SpanDataReferenceInfoExtensions.CompareReferences(other.Data, spanData.Data)));
 }
Пример #5
0
 SpanData <ReferenceInfo>?FindReferenceInfo(SpanData <ReferenceInfo> spanData)
 {
     foreach (var other in currentContent.Content.ReferenceCollection)
     {
         if (other.Data.IsLocal == spanData.Data.IsLocal && other.Data.IsDefinition == spanData.Data.IsDefinition && SpanDataReferenceInfoExtensions.CompareReferences(other.Data, spanData.Data))
         {
             return(other);
         }
     }
     return(null);
 }