예제 #1
0
        public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            var snapshot = spans[0].Snapshot;

            if (classifications == null || classificationsVersion != snapshot.Version.VersionNumber)
            {
                //TODO: Do this asynchronously
                classificationsVersion = snapshot.Version.VersionNumber;
                classifications        = CreateClassifications(snapshot);
            }

            foreach (var span in spans)
            {
                int index = classifications.GetStartIndex(span.Span.Start);
                if (index < 0)
                {
                    continue;
                }
                for (int i = index; i < classifications.Count; i++)
                {
                    var spanData = classifications[i];
                    if (spanData.Span.Start > span.Span.End)
                    {
                        break;
                    }
                    Debug.Assert(spanData.Span.End <= snapshot.Length);
                    if (spanData.Span.End > snapshot.Length)
                    {
                        break;
                    }
                    foreach (var t in GetTags(new SnapshotSpan(snapshot, spanData.Span), spanData.Data))
                    {
                        yield return(t);
                    }
                }
            }
        }
예제 #2
0
        static IEnumerable <SpanData <TData> > GetReferenceInfosFrom <TData>(SpanDataCollection <TData> referenceCollection, int position, bool forward)
        {
            if (referenceCollection.Count == 0)
            {
                yield break;
            }

            int startIndex = referenceCollection.GetStartIndex(position);

            // If it's between two refs, always prefer the one whose Start == position
            if (startIndex >= 0 && startIndex + 1 < referenceCollection.Count && referenceCollection[startIndex + 1].Span.Start == position)
            {
                startIndex = startIndex + 1;
            }
            if (forward)
            {
                if (startIndex < 0)
                {
                    startIndex = referenceCollection.Count - 1;
                }

                for (int i = 0; i < referenceCollection.Count; i++)
                {
                    int index = (startIndex + i + 1) % referenceCollection.Count;
                    yield return(referenceCollection[index]);
                }
            }
            else
            {
                if (startIndex < 0)
                {
                    startIndex = 0;
                }

                for (int i = 0; i < referenceCollection.Count; i++)
                {
                    int index = (referenceCollection.Count + startIndex - (i + 1)) % referenceCollection.Count;
                    yield return(referenceCollection[index]);
                }
            }
        }