Exemple #1
0
        // Step 8: You must implement the GetTags method. This method takes a collection of SnapshotSpan objects
        // and returns an enumeration of tag spans.
        //
        // In C#, implement this method as a yield iterator, which enables lazy evaluation (that is, evaluation
        // of the set only when individual items are accessed) of the tags. In Visual Basic, add the tags to a list and return the list.
        //
        // Here the method returns a TagSpan<T> object that has a "blue" TextMarkerTag, which provides a blue background.
        public IEnumerable <ITagSpan <HighlightWordTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (CurrentWord == null)
            {
                yield break;
            }

            // Hold on to a "snapshot" of the word spans and current word, so that we maintain the same
            // collection throughout
            SnapshotSpan currentWord = CurrentWord.Value;
            NormalizedSnapshotSpanCollection wordSpans = WordSpans;

            if (spans.Count == 0 || wordSpans.Count == 0)
            {
                yield break;
            }

            // If the requested snapshot isn't the same as the one our words are on, translate our spans to the expected snapshot 
            if (spans[0].Snapshot != wordSpans[0].Snapshot)
            {
                wordSpans = new NormalizedSnapshotSpanCollection(
                    wordSpans.Select(span => span.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive)));

                currentWord = currentWord.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive);
            }

            // First, yield back the word the cursor is under (if it overlaps) 
            // Note that we'll yield back the same word again in the wordspans collection; 
            // the duplication here is expected. 
            if (spans.OverlapsWith(new NormalizedSnapshotSpanCollection(currentWord)))
            {
                yield return(new TagSpan <HighlightWordTag>(currentWord, new HighlightWordTag()));
            }

            // Second, yield all the other words in the file 
            foreach (SnapshotSpan span in NormalizedSnapshotSpanCollection.Overlap(spans, wordSpans))
            {
                yield return(new TagSpan <HighlightWordTag>(span, new HighlightWordTag()));
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets all the tags that intersect the specified spans.
        /// </summary>
        /// <param name="spans">The spans to visit.</param>
        public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            EmmetCommandTarget filter;
            bool hasTags = _view.Properties.TryGetProperty("EmmetCommandTarget", out filter);

            if (!hasTags || !filter.HasActiveTabStops)
            {
                yield break;
            }

            Span[] expansionSpans = filter.GetTabStopsToHighlight();
            foreach (Span span in expansionSpans)
            {
                SnapshotSpan snapshotSpan;
                try
                {
                    if (span.Length is 0)
                    {
                        snapshotSpan = new SnapshotSpan(_buffer.CurrentSnapshot, new Span(span.Start, 1));
                    }
                    else
                    {
                        snapshotSpan = new SnapshotSpan(_buffer.CurrentSnapshot, span);
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    // Sometimes happens when quickly pressing Undo etc.
                    continue;
                }

                if (!string.IsNullOrWhiteSpace(snapshotSpan.GetText()) && spans.OverlapsWith(snapshotSpan))
                {
                    yield return(new TagSpan <TextMarkerTag>(
                                     snapshotSpan, new TextMarkerTag("MarkerFormatDefinition/HighlightedReference")));
                }
            }
        }
Exemple #3
0
        public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (this.currentWord == null)
            {
                yield break;
            }

            var currentWord = this.currentWord.Value;
            var wordSpans   = this.wordSpans;

            if (spans.Count == 0 || this.wordSpans.Count == 0)
            {
                yield break;
            }

            if (spans[0].Snapshot != wordSpans[0].Snapshot)
            {
                wordSpans = new NormalizedSnapshotSpanCollection(
                    wordSpans.Select(span => span.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive)));

                currentWord = currentWord.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive);
            }

            if (spans.OverlapsWith(new NormalizedSnapshotSpanCollection(currentWord)))
            {
                yield return(new TagSpan <ReferenceHighlightWordTag>(currentWord, new ReferenceHighlightWordTag()));
            }

            foreach (SnapshotSpan span in NormalizedSnapshotSpanCollection.Overlap(spans, wordSpans))
            {
                yield return(new TagSpan <ReferenceHighlightWordTag>(span, new ReferenceHighlightWordTag()));
            }

            if (navigationWordSpans != null)
            {
                yield return(new TagSpan <DefinitionHighlightWordTag>(navigationWordSpans.Value, new DefinitionHighlightWordTag()));
            }
        }
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (CurrentWord == null)
            {
                yield break;
            }

            // Hold on to a "snapshot" of the word spans and current word, so that the same collection is maintained throughout
            SnapshotSpan currentWord = CurrentWord.Value;
            NormalizedSnapshotSpanCollection wordSpans = WordSpans;

            if (spans.Count == 0 || WordSpans.Count == 0)
            {
                yield break;
            }

            // If the requested snapshot isn't the same as the one the words are on, translate the spans to the expected snapshot
            if (spans[0].Snapshot != wordSpans[0].Snapshot)
            {
                wordSpans = new NormalizedSnapshotSpanCollection(wordSpans.Select(span => span.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive)));

                currentWord = currentWord.TranslateTo(spans[0].Snapshot, SpanTrackingMode.EdgeExclusive);
            }

            // First, yield back the word the cursor is under (if it overlaps)
            // Note that this will yield back the same word again in the wordspans collection; the duplication here is expected.
            if (spans.OverlapsWith(new NormalizedSnapshotSpanCollection(currentWord)))
            {
                yield return(new TagSpan <ClassificationTag>(currentWord, new ClassificationTag(TypeService.GetClassificationType(Constants.FONT_FORMAT_NAME))));
            }

            // Second, yield all the other words in the file
            foreach (SnapshotSpan span in NormalizedSnapshotSpanCollection.Overlap(spans, wordSpans))
            {
                yield return(new TagSpan <ClassificationTag>(span, new ClassificationTag(TypeService.GetClassificationType(Constants.FONT_FORMAT_NAME))));
            }
        }