public static IElisionBuffer CreateElisionBufferWithoutIndentation(
            this IProjectionBufferFactoryService factoryService,
            IEditorOptions editorOptions,
            IContentType contentType,
            IEnumerable<SnapshotSpan> exposedSpans)
        {
            var spans = new NormalizedSnapshotSpanCollection(exposedSpans);

            if (spans.Count > 0)
            {
                // BUG(6335): We have to make sure that the spans refer to the current snapshot of
                // the buffer.
                var buffer = spans.First().Snapshot.TextBuffer;
                var currentSnapshot = buffer.CurrentSnapshot;
                spans = new NormalizedSnapshotSpanCollection(
                    spans.Select(s => s.TranslateTo(currentSnapshot, SpanTrackingMode.EdgeExclusive)));
            }

            contentType = contentType ?? factoryService.ProjectionContentType;
            var elisionBuffer = factoryService.CreateElisionBuffer(
                null, spans, ElisionBufferOptions.None, contentType);

            if (spans.Count > 0)
            {
                var snapshot = spans.First().Snapshot;
                var buffer = snapshot.TextBuffer;

                // We need to figure out the shorted indentation level of the exposed lines.  We'll
                // then remove that indentation from all lines.
                var indentationColumn = DetermineIndentationColumn(editorOptions, spans);

                var spansToElide = new List<Span>();

                foreach (var span in spans)
                {
                    var startLineNumber = snapshot.GetLineNumberFromPosition(span.Start);
                    var endLineNumber = snapshot.GetLineNumberFromPosition(span.End);

                    for (var lineNumber = startLineNumber; lineNumber <= endLineNumber; lineNumber++)
                    {
                        var line = snapshot.GetLineFromLineNumber(lineNumber);
                        var lineOffsetOfColumn = line.GetLineOffsetFromColumn(indentationColumn, editorOptions);
                        spansToElide.Add(Span.FromBounds(line.Start, line.Start + lineOffsetOfColumn));
                    }
                }

                elisionBuffer.ElideSpans(new NormalizedSpanCollection(spansToElide));
            }

            return elisionBuffer;
        }
        // Produces tags on the snapshot that the tag consumer asked for.
        public virtual IEnumerable <ITagSpan <IntraTextAdornmentTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans == null || spans.Count == 0)
            {
                yield break;
            }

            // Translate the request to the snapshot that this tagger is current with.

            var requestedSnapshot = spans[0].Snapshot;

            var translatedSpans = new NormalizedSnapshotSpanCollection(spans.Select(span => span.TranslateTo(snapshot, SpanTrackingMode.EdgeExclusive)));

            // Grab the adornments.
            foreach (var tagSpan in GetAdornmentTagsOnSnapshot(translatedSpans))
            {
                // Translate each adornment to the snapshot that the tagger was asked about.
                var span = tagSpan.Span.TranslateTo(requestedSnapshot, SpanTrackingMode.EdgeExclusive);

                var tag = new IntraTextAdornmentTag(tagSpan.Tag.Adornment, tagSpan.Tag.RemovalCallback, tagSpan.Tag.Affinity);
                yield return(new TagSpan <IntraTextAdornmentTag>(span, tag));
            }
        }
        // Produces tags on the snapshot that the tag consumer asked for.
        public virtual IEnumerable <ITagSpan <IntraTextAdornmentTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans == null || spans.Count == 0)
            {
                yield break;
            }

            // Translate the request to the snapshot that this tagger is current with.

            ITextSnapshot requestedSnapshot = spans[0].Snapshot;
            var           translatedSpans   = new NormalizedSnapshotSpanCollection(spans.Select(span => span.TranslateTo(this.snapshot, SpanTrackingMode.EdgeExclusive)));
            // Grab the adornments.
            var tags = GetAdornmentTagsOnSnapshot(translatedSpans).GetEnumerator();

            while (tags.MoveNext())
            {
                var                   current = tags.Current;
                SnapshotSpan          span    = current.Span.TranslateTo(requestedSnapshot, SpanTrackingMode.EdgeExclusive);
                IntraTextAdornmentTag tag     = new IntraTextAdornmentTag(current.Tag.Adornment, current.Tag.RemovalCallback, current.Tag.Affinity);

                yield return(new TagSpan <IntraTextAdornmentTag>(span, tag));
            }
        }
        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))));
            }
        }
Exemple #5
0
        public IEnumerable <ITagSpan <HighlightWordTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (CurrentWord == null)
            {
                yield break;
            }
            SnapshotSpan currentWord = CurrentWord.Value;
            NormalizedSnapshotSpanCollection wordSpans = WordSpans;

            if (spans.Count == 0 || 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);
            }
            foreach (SnapshotSpan span in NormalizedSnapshotSpanCollection.Overlap(spans, wordSpans))
            {
                yield return(new TagSpan <HighlightWordTag>(span, new HighlightWordTag()));
            }
        }
        public static IProjectionBuffer CreateProjectionBufferWithoutIndentation(
            this IProjectionBufferFactoryService factoryService,
            IEditorOptions editorOptions,
            IContentType?contentType,
            IEnumerable <SnapshotSpan> exposedSpans
            )
        {
            var spans = new NormalizedSnapshotSpanCollection(exposedSpans);

            if (spans.Count > 0)
            {
                // BUG(6335): We have to make sure that the spans refer to the current snapshot of
                // the buffer.
                var buffer          = spans.First().Snapshot.TextBuffer;
                var currentSnapshot = buffer.CurrentSnapshot;
                spans = new NormalizedSnapshotSpanCollection(
                    spans.Select(
                        s => s.TranslateTo(currentSnapshot, SpanTrackingMode.EdgeExclusive)
                        )
                    );
            }

            contentType ??= factoryService.ProjectionContentType;
            var projectionBuffer = factoryService.CreateProjectionBuffer(
                projectionEditResolver: null,
                sourceSpans: Array.Empty <object>(),
                options: ProjectionBufferOptions.None,
                contentType: contentType
                );

            if (spans.Count > 0)
            {
                var finalSpans = new List <object>();

                // We need to figure out the shorted indentation level of the exposed lines.  We'll
                // then remove that indentation from all lines.
                var indentationColumn = DetermineIndentationColumn(editorOptions, spans);

                foreach (var span in spans)
                {
                    var snapshot        = span.Snapshot;
                    var startLineNumber = snapshot.GetLineNumberFromPosition(span.Start);
                    var endLineNumber   = snapshot.GetLineNumberFromPosition(span.End);

                    for (
                        var lineNumber = startLineNumber;
                        lineNumber <= endLineNumber;
                        lineNumber++
                        )
                    {
                        // Compute the span clamped to this line
                        var line           = snapshot.GetLineFromLineNumber(lineNumber);
                        var finalSpanStart = Math.Max(line.Start, span.Start);
                        var finalSpanEnd   = Math.Min(line.EndIncludingLineBreak, span.End);

                        // We'll only offset if our span doesn't already start at the start of the line. See the similar exclusion in
                        // DetermineIndentationColumn that this matches.
                        if (line.Start == finalSpanStart)
                        {
                            finalSpanStart += line.GetLineOffsetFromColumn(
                                indentationColumn,
                                editorOptions
                                );

                            // Paranoia: what if the indentation reversed our ordering?
                            if (finalSpanStart > finalSpanEnd)
                            {
                                finalSpanStart = finalSpanEnd;
                            }
                        }

                        // We don't expect edits to happen while this projection buffer is active. We'll choose EdgeExclusive so
                        // if they do we don't end up in any cases where there is overlapping source spans.
                        finalSpans.Add(
                            snapshot.CreateTrackingSpan(
                                Span.FromBounds(finalSpanStart, finalSpanEnd),
                                SpanTrackingMode.EdgeExclusive
                                )
                            );
                    }
                }

                projectionBuffer.InsertSpans(0, finalSpans);
            }

            return(projectionBuffer);
        }
 internal SnapshotMultipleSpanSourceCodeReader(NormalizedSnapshotSpanCollection spans)
 {
     _spans = spans;
     _readers = spans.Select(s => new SnapshotSpanSourceCodeReader(s)).ToArray();
     _index = 0;
 }
 public void AddSpans(NormalizedSnapshotSpanCollection snapshotSpanCollection)
 {
     // TODO: custom tracking spans!
     var newTrackingSpans = snapshotSpanCollection.Select(ss => ss.Snapshot.CreateTrackingSpan(ss, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward));
     AddSpans(newTrackingSpans);
 }
Exemple #9
0
 public IEnumerable <ClassifiedSpan> GetClassifiedSpans(NormalizedSnapshotSpanCollection spans)
 {
     return(spans
            .Select(s => TextSpan.FromBounds(s.Start, s.End))
            .SelectMany(s => Classifier.GetClassifiedSpans(SemanticModel, s, Workspace)));
 }
Exemple #10
0
 internal SnapshotMultipleSpanSourceCodeReader(NormalizedSnapshotSpanCollection spans)
 {
     _spans   = spans;
     _readers = spans.Select(s => new SnapshotSpanSourceCodeReader(s)).ToArray();
     _index   = 0;
 }
            /// <summary>
            /// Get the text of the given spans.
            /// If there are multiple spans, then return the concatenation of the text of each span plus a newline character,
            /// otherwise, simply return the text of the only span.
            /// </summary>
            private string GetText(NormalizedSnapshotSpanCollection spans)
            {
                Debug.Assert(spans.Count > 0);

                if (spans.Count > 1)
                {
                    var builder = new StringBuilder();
                    builder.Append(string.Join(EditorOperations.Options.GetNewLineCharacter(), spans.Select((span) => span.GetText()).ToArray()));

                    // Append one last newline character
                    builder.Append(EditorOperations.Options.GetNewLineCharacter());
                    return builder.ToString();
                }
                else
                {
                    return spans[0].GetText();
                }
            }