public IEnumerable <ITagSpan <GLSLHighlightTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (_currentToken.HasValue)
            {
                UpdateTrackedSpans(spans);

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

                if (spans.Count > 0 && wordSpans.Count > 0)
                {
                    // If the requested snapshot isn't the same as the one our words are on, translate our spans to the expected snapshot
                    if (spans.First().Snapshot != wordSpans.First().Snapshot)
                    {
                        wordSpans    = new NormalizedSnapshotSpanCollection(wordSpans.Select(s => s.TranslateTo(spans.First().Snapshot, SpanTrackingMode.EdgeExclusive)));
                        currentToken = currentToken.TranslateTo(spans.First().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.
                    yield return(new TagSpan <GLSLHighlightTag>(currentToken, new GLSLHighlightTag()));

                    foreach (var span in wordSpans)
                    {
                        yield return(new TagSpan <GLSLHighlightTag>(span, new GLSLHighlightTag()));
                    }
                }
            }
        }
Exemple #2
0
            public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                if (_highlightedSpans?.Any() ?? false)
                {
                    if (spans.First().Snapshot != _highlightedSpans.First().Snapshot)
                    {
                        _highlightedSpans = new NormalizedSnapshotSpanCollection(
                            from span in _highlightedSpans
                            select span.TranslateTo(spans.First().Snapshot, SpanTrackingMode.EdgeExclusive)
                            );
                    }

                    foreach (var span in NormalizedSnapshotSpanCollection.Overlap(spans, _highlightedSpans))
                    {
                        yield return(new TagSpan <FrameNameReferenceTag>(span, FrameNameReferenceTag.Instance));
                    }
                }

                if (_definitionSpans?.Any() ?? false)
                {
                    if (spans.First().Snapshot != _definitionSpans.First().Snapshot)
                    {
                        _definitionSpans = new NormalizedSnapshotSpanCollection(
                            from span in _definitionSpans
                            select span.TranslateTo(spans.First().Snapshot, SpanTrackingMode.EdgeExclusive)
                            );
                    }

                    foreach (var span in NormalizedSnapshotSpanCollection.Overlap(spans, _definitionSpans))
                    {
                        yield return(new TagSpan <FrameNameDefinitionTag>(span, FrameNameDefinitionTag.Instance));
                    }
                }
            }
Exemple #3
0
            public IEnumerable <ITagSpan <IClassificationTag> > GetAllTags(NormalizedSnapshotSpanCollection spans, CancellationToken cancellationToken)
            {
                this.AssertIsForeground();
                if (spans.Count == 0)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                var firstSpan = spans.First();
                var snapshot  = firstSpan.Snapshot;

                Debug.Assert(snapshot.TextBuffer == _subjectBuffer);

                // We want to classify from the start of the first requested span to the end of the
                // last requested span.
                var spanToTag = new SnapshotSpan(snapshot,
                                                 Span.FromBounds(spans.First().Start, spans.Last().End));

                // We don't need to actually classify if what we're being asked for is a subspan
                // of the last classification we performed.
                var cachedTaggedSpan = this.CachedTaggedSpan;
                var canReuseCache    =
                    cachedTaggedSpan?.Snapshot == snapshot &&
                    cachedTaggedSpan.Value.Contains(spanToTag);

                if (!canReuseCache)
                {
                    // Our cache is not there, or is out of date.  We need to compute the up to date
                    // results.

                    var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document == null)
                    {
                        return(Array.Empty <ITagSpan <IClassificationTag> >());
                    }

                    _classificationService = _classificationService ?? document.Project.LanguageServices.GetService <IEditorClassificationService>();

                    var context = new TaggerContext <IClassificationTag>(document, snapshot, cancellationToken: cancellationToken);

                    var task = SemanticClassificationUtilities.ProduceTagsAsync(
                        context, new DocumentSnapshotSpan(document, spanToTag),
                        _classificationService, _owner._typeMap);
                    task.Wait(cancellationToken);

                    CachedTaggedSpan = spanToTag;
                    CachedTags       = new TagSpanIntervalTree <IClassificationTag>(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans);
                }

                if (this.CachedTags == null)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                return(this.CachedTags.GetIntersectingTagSpans(spans));
            }
            public IEnumerable <ITagSpan <IClassificationTag> > GetAllTags(NormalizedSnapshotSpanCollection spans, CancellationToken cancellationToken)
            {
                this.AssertIsForeground();
                if (spans.Count == 0)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                var firstSpan = spans.First();
                var snapshot  = firstSpan.Snapshot;

                Debug.Assert(snapshot.TextBuffer == _subjectBuffer);

                var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();

                if (document == null)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                // We want to classify from the start of the first requested span to the end of the
                // last requested span.
                var spanToTag = new SnapshotSpan(snapshot, Span.FromBounds(spans.First().Start, spans.Last().End));

                GetCachedInfo(out var cachedTaggedSpan, out var cachedTags);

                // We don't need to actually classify if what we're being asked for is a subspan
                // of the last classification we performed.
                var canReuseCache =
                    cachedTaggedSpan?.Snapshot == snapshot &&
                    cachedTaggedSpan.Value.Contains(spanToTag);

                if (!canReuseCache)
                {
                    // Our cache is not there, or is out of date.  We need to compute the up to date results.
                    var context = new TaggerContext <IClassificationTag>(document, snapshot);
                    this.ThreadingContext.JoinableTaskFactory.Run(
                        () => ProduceTagsAsync(context, new DocumentSnapshotSpan(document, spanToTag), _owner._typeMap, cancellationToken));

                    cachedTaggedSpan = spanToTag;
                    cachedTags       = new TagSpanIntervalTree <IClassificationTag>(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans);

                    lock (_gate)
                    {
                        _cachedTaggedSpan = cachedTaggedSpan;
                        _cachedTags       = cachedTags;
                    }
                }

                return(cachedTags == null
                    ? Array.Empty <ITagSpan <IClassificationTag> >()
                    : cachedTags.GetIntersectingTagSpans(spans));
            }
        public IEnumerable <ITagSpan <ITextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            AssertIsForeground();

            var service = _trackingServiceOpt;

            if (service == null)
            {
                yield break;
            }

            var snapshot = spans.First().Snapshot;

            foreach (var asSpan in service.GetSpans(snapshot.AsText()))
            {
                if (asSpan.IsLeaf)
                {
                    continue;
                }

                var snapshotSpan = new SnapshotSpan(snapshot, Span.FromBounds(asSpan.Span.Start, asSpan.Span.End));

                if (spans.OverlapsWith(snapshotSpan))
                {
                    yield return(new TagSpan <ITextMarkerTag>(snapshotSpan, ActiveStatementTag.Instance));
                }
            }
        }
Exemple #6
0
        public IEnumerable <ITagSpan <T> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (_renameService.ActiveSession == null)
            {
                yield break;
            }

            var renameSpans = _currentSpans;

            if (renameSpans != null)
            {
                var snapshot = spans.First().Snapshot;
                foreach (var renameSpan in renameSpans)
                {
                    var span = renameSpan.TrackingSpan.GetSpan(snapshot);
                    if (spans.OverlapsWith(span))
                    {
                        TagSpan <T> tagSpan;
                        if (TryCreateTagSpan(span, renameSpan.Type, out tagSpan))
                        {
                            yield return(tagSpan);
                        }
                    }
                }
            }
        }
            internal static NormalizedSnapshotSpanCollection CoalesceSpans(NormalizedSnapshotSpanCollection normalizedSpans)
            {
                var snapshot = normalizedSpans.First().Snapshot;

                // Coalesce the spans if there are a lot of them.
                if (normalizedSpans.Count > CoalesceDifferenceCount)
                {
                    // Spans are normalized.  So to find the whole span we just go from the
                    // start of the first span to the end of the last span.
                    normalizedSpans = new NormalizedSnapshotSpanCollection(snapshot.GetSpanFromBounds(
                                                                               normalizedSpans.First().Start,
                                                                               normalizedSpans.Last().End));
                }

                return(normalizedSpans);
            }
            public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                ITextBuffer buffer = spans.First().Snapshot.TextBuffer;
                SyntaxTree  syntax = buffer.GetSyntaxTree();

                return
                    // find intersecting nodes
                    (from node in syntax.Root.DescendantsAndSelf()
                     where spans.IntersectsWith(node.Span)
                     let type = node.GetType()

                                // find analyzers for node
                                from analyzer in _analyzers
                                from @interface in analyzer.GetType().GetInterfaces()
                                where @interface.IsGenericType &&
                                @interface.GetGenericTypeDefinition() == typeof(ISyntaxNodeAnalyzer <>)
                                let analyzerNodeType = @interface.GetGenericArguments().Single()
                                                       where analyzerNodeType.IsAssignableFrom(type)

                                                       // analyze node
                                                       from diagnostic in typeof(ISyntaxNodeAnalyzer <>)
                                                       .MakeGenericType(analyzerNodeType)
                                                       .GetMethod("Analyze")
                                                       .Invoke(analyzer, new [] { node }) as IEnumerable <ITagSpan <IErrorTag> >
                                                       select diagnostic
                    );
            }
Exemple #9
0
            private IEnumerable <ITagSpan <TTag> > GetTagsWorker(
                NormalizedSnapshotSpanCollection requestedSpans,
                bool accurate,
                CancellationToken cancellationToken)
            {
                if (requestedSpans.Count == 0)
                {
                    return(SpecializedCollections.EmptyEnumerable <ITagSpan <TTag> >());
                }

                var buffer = requestedSpans.First().Snapshot.TextBuffer;
                var tags   = accurate
                    ? _tagSource.GetAccurateTagIntervalTreeForBuffer(buffer, cancellationToken)
                    : _tagSource.GetTagIntervalTreeForBuffer(buffer);

                if (tags == null)
                {
                    return(SpecializedCollections.EmptyEnumerable <ITagSpan <TTag> >());
                }

                var result = GetIntersectingTagSpans(requestedSpans, tags);

                DebugVerifyTags(requestedSpans, result);

                return(result);
            }
Exemple #10
0
        IEnumerable <ITagSpan <AlertTag> > ITagger <AlertTag> .GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0 || PackageSecurityPackage.Vulnurabilities == null)
            {
                yield break;
            }

            SnapshotSpan span = spans.First();

            ITextSnapshotLine line = span.Snapshot.GetLineFromPosition(span.Start.Position);
            string            text = line.Extent.GetText();

            Match match = _regex.Match(text);

            if (match.Success)
            {
                string name    = match.Groups["name"].Value;
                string version = match.Groups["version"].Value;

                Vulnerability vul = PackageSecurityPackage.Vulnurabilities.CheckPackage(name, version);

                if (vul.Severity != VulnerabilityLevel.None)
                {
                    yield return(new TagSpan <AlertTag>(line.Extent, new AlertTag(vul)));
                }
            }
        }
Exemple #11
0
            public IEnumerable <ITagSpan <IOutliningRegionTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                ITextBuffer             buffer = spans.First().Snapshot.TextBuffer;
                SyntaxTree              syntax = buffer.GetSyntaxTree();
                RobotsTxtDocumentSyntax root   = syntax.Root as RobotsTxtDocumentSyntax;

                return
                    (from record in root.Records
                     where record.Lines.Count() >= 2
                     where spans.IntersectsWith(record.Span)
                     let first = record.Lines.First()
                                 where first.NameToken.Value.Equals("User-agent", StringComparison.InvariantCultureIgnoreCase)
                                 let last = record.Lines.Last()
                                            let collapsibleSpan = new SnapshotSpan(
                         first.Span.End,
                         (last.TrailingTrivia.LastOrDefault() ?? last.ValueToken).Span.Span.End
                         )
                                                                  select new TagSpan <IOutliningRegionTag>(
                         collapsibleSpan,
                         new OutliningRegionTag(
                             collapsedForm: "...",
                             collapsedHintForm: collapsibleSpan.GetText().Trim()
                             )
                         )
                    );
            }
Exemple #12
0
        public virtual IEnumerable <ITagSpan <ParamStorageTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            UpdateStcSpans();

            // Note that the spans argument can contain spans that are sub-spans of lines or intersect multiple lines.
            if (_stcLocs != null)
            {
                for (int i = 0; i + 1 < _stcLocs.Length; i += 2)
                {
                    // need to compare manually as info is on different snapshots
                    int  pos        = _stcLocs[i + 1];
                    bool intersects = false;
                    foreach (var span in spans)
                    {
                        if (span.Start.Position <= pos && pos <= span.End.Position)
                        {
                            intersects = true;
                        }
                    }

                    if (intersects)
                    {
                        var          point = new SnapshotPoint(spans.First().Snapshot, pos);
                        SnapshotSpan span  = new SnapshotSpan(point, 1);
                        yield return(new TagSpan <ParamStorageTag>(span, new ParamStorageTag(_stcLocs[i])));
                    }
                }
            }
        }
Exemple #13
0
        private void NotifyTagChanged(ITextSnapshot snapshot)
        {
            IMappingSpan t = tagsChanged.Dequeue();
            NormalizedSnapshotSpanCollection sp = t.GetSpans(snapshot);

            if (TagsChanged != null)
            {
                TagsChanged.Invoke(this, new SnapshotSpanEventArgs(sp.First()));
            }
        }
Exemple #14
0
            public IEnumerable <ITagSpan <CssClassReferenceTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                var actual = _highlightedSpans;

                if (actual?.Any() ?? false)
                {
                    if (spans.First().Snapshot != actual.First().Snapshot)
                    {
                        actual = new NormalizedSnapshotSpanCollection(
                            from span in actual
                            select span.TranslateTo(spans.First().Snapshot, SpanTrackingMode.EdgeExclusive)
                            );
                    }

                    foreach (var span in NormalizedSnapshotSpanCollection.Overlap(spans, actual))
                    {
                        yield return(new TagSpan <CssClassReferenceTag>(span, CssClassReferenceTag.Instance));
                    }
                }
            }
            public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                if (!_textView.Properties.TryGetProperty(PropertyName, out List <Span> allSpans))
                {
                    return(null);
                }

                return(allSpans
                       .Where(s => spans.Any(ss => ss.IntersectsWith(s)))
                       .Select(s => new TagSpan <TextMarkerTag>(new SnapshotSpan(spans.First().Snapshot, s), ProjectionSpanTag.Instance)));
            }
Exemple #16
0
        /// <inheritdoc/>
        public IEnumerable <ITagSpan <TTag> >?GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans[0].IsEmpty)
            {
                return(null);
            }

            bool isFullParse = spans.First().Start == 0 && spans.Last().End == spans[0].Snapshot.Length;

            return(GetTags(spans, isFullParse));
        }
Exemple #17
0
        public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            this.BackgroundCompilation.CheckCompilationVersion();
            var compilationSnapshot = this.BackgroundCompilation.CompilationSnapshot;

            if (compilationSnapshot.Compilation == null)
            {
                yield break;
            }
            ImmutableArray <Diagnostic> diagnostics = compilationSnapshot.Compilation.GetDiagnostics();
            ITextSnapshot textSnapshot = compilationSnapshot.Text;

            if (textSnapshot == null || spans.Count == 0 || spans.First().Snapshot.Version != textSnapshot.Version)
            {
                yield break;
            }
            if (diagnostics != null)
            {
                foreach (var diagnostic in diagnostics)
                {
                    if (diagnostic.Severity == DiagnosticSeverity.Hidden)
                    {
                        continue;
                    }
                    SnapshotSpan diagnosticSpan = new SnapshotSpan(textSnapshot, Span.FromBounds(diagnostic.Location.SourceSpan.Start, diagnostic.Location.SourceSpan.End));
                    if (spans.IntersectsWith(diagnosticSpan))
                    {
                        string errorType = PredefinedErrorTypeNames.HintedSuggestion;
                        switch (diagnostic.Severity)
                        {
                        case DiagnosticSeverity.Hidden:
                            break;

                        case DiagnosticSeverity.Info:
                            errorType = PredefinedErrorTypeNames.HintedSuggestion;
                            break;

                        case DiagnosticSeverity.Warning:
                            errorType = PredefinedErrorTypeNames.Warning;
                            break;

                        case DiagnosticSeverity.Error:
                            errorType = PredefinedErrorTypeNames.SyntaxError;
                            break;

                        default:
                            break;
                        }
                        yield return(new TagSpan <IErrorTag>(diagnosticSpan, new ErrorTag(errorType, diagnostic.GetMessage())));
                    }
                }
            }
        }
        private async Task <CommentSelectionResult> ToggleBlockCommentsAsync(Document document, CommentSelectionInfo commentInfo,
                                                                             ITextStructureNavigator navigator, NormalizedSnapshotSpanCollection selectedSpans, CancellationToken cancellationToken)
        {
            var firstLineAroundSelection = selectedSpans.First().Start.GetContainingLine().Start;
            var lastLineAroundSelection  = selectedSpans.Last().End.GetContainingLine().End;
            var linesContainingSelection = TextSpan.FromBounds(firstLineAroundSelection, lastLineAroundSelection);
            var blockCommentedSpans      = await GetBlockCommentsInDocumentAsync(
                document, selectedSpans.First().Snapshot, linesContainingSelection, commentInfo, cancellationToken).ConfigureAwait(false);

            var blockCommentSelections = selectedSpans.SelectAsArray(span => new BlockCommentSelectionHelper(blockCommentedSpans, span));

            var returnOperation = Operation.Uncomment;

            var textChanges = ArrayBuilder <TextChange> .GetInstance();

            var trackingSpans = ArrayBuilder <CommentTrackingSpan> .GetInstance();

            // Try to uncomment until an already uncommented span is found.
            foreach (var blockCommentSelection in blockCommentSelections)
            {
                // If any selection does not have comments to remove, then the operation should be comment.
                if (!TryUncommentBlockComment(blockCommentedSpans, blockCommentSelection, textChanges, trackingSpans, commentInfo))
                {
                    returnOperation = Operation.Comment;
                    break;
                }
            }

            if (returnOperation == Operation.Comment)
            {
                textChanges.Clear();
                trackingSpans.Clear();
                foreach (var blockCommentSelection in blockCommentSelections)
                {
                    BlockCommentSpan(blockCommentSelection, navigator, textChanges, trackingSpans, commentInfo);
                }
            }

            return(new CommentSelectionResult(textChanges.ToArrayAndFree(), trackingSpans.ToArrayAndFree(), returnOperation));
        }
        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;
        }
        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);
        }
        public IEnumerable <ITagSpan <IOutliningRegionTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0 || _doc == null || !MarkdownEditorPackage.Options.EnableOutlining)
            {
                yield break;
            }

            var descendants = _doc.Descendants();
            var snapshot    = spans.First().Snapshot;

            // Code blocks
            var codeBlocks = descendants.OfType <FencedCodeBlock>();

            foreach (var block in codeBlocks)
            {
                if (block.IsOpen || block.Lines.Count == 0)
                {
                    continue;
                }

                string text    = $"{block.Info.ToUpperInvariant()} Code Block".Trim();
                string tooltip = new string(block.Lines.ToString().Take(800).ToArray());

                var span = new SnapshotSpan(snapshot, block.ToSimpleSpan());
                var tag  = new OutliningRegionTag(false, false, text, tooltip);

                yield return(new TagSpan <IOutliningRegionTag>(span, tag));
            }

            // HTML Blocks
            var htmlBlocks = descendants.OfType <HtmlBlock>();

            foreach (var block in htmlBlocks)
            {
                // This prevents outlining for single line comments
                if (block.Lines.Count == 1)
                {
                    continue;
                }

                string text    = "HTML Block";
                string tooltip = new string(block.Lines.ToString().Take(800).ToArray());

                var span = new SnapshotSpan(snapshot, block.ToSimpleSpan());
                var tag  = new OutliningRegionTag(false, false, text, tooltip);

                yield return(new TagSpan <IOutliningRegionTag>(span, tag));
            }
        }
            public IEnumerable <ITagSpan <TTag> > GetTags(NormalizedSnapshotSpanCollection requestedSpans)
            {
                this.AssertIsForeground();
                if (requestedSpans.Count == 0)
                {
                    return(SpecializedCollections.EmptyEnumerable <ITagSpan <TTag> >());
                }

                var buffer = requestedSpans.First().Snapshot.TextBuffer;
                var tags   = this.TryGetTagIntervalTreeForBuffer(buffer);

                return(tags == null
                    ? SpecializedCollections.EmptyEnumerable <ITagSpan <TTag> >()
                    : tags.GetIntersectingTagSpans(requestedSpans));
            }
            public IEnumerable <ITagSpan <TTag> > GetTags(NormalizedSnapshotSpanCollection requestedSpans)
            {
                _dataSource.ThreadingContext.ThrowIfNotOnUIThread();
                if (requestedSpans.Count == 0)
                {
                    return(SpecializedCollections.EmptyEnumerable <ITagSpan <TTag> >());
                }

                var buffer = requestedSpans.First().Snapshot.TextBuffer;
                var tags   = this.TryGetTagIntervalTreeForBuffer(buffer);

                return(tags == null
                    ? SpecializedCollections.EmptyEnumerable <ITagSpan <TTag> >()
                    : tags.GetIntersectingTagSpans(requestedSpans));
            }
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            var textSnapshot = spans.First().Snapshot;

            foreach (var tag in _aggregator.GetTags(spans))
            {
                if (tag.Tag is GLSLClassifierTag)
                {
                    foreach (var span in tag.Span.GetSpans(textSnapshot))
                    {
                        // Ensure that we translate our span to the expected snapshot
                        var translatedSpan = span.Translated(textSnapshot);
                        yield return(new TagSpan <ClassificationTag>(translatedSpan, new ClassificationTag(_glslTypes[tag.Tag.TokenType])));
                    }
                }
            }
        }
        public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            this.BackgroundCompilation.CheckCompilationVersion();
            var compilationSnapshot = this.BackgroundCompilation.CompilationSnapshot;
            var symbolTokens        = compilationSnapshot?.SymbolTokens;

            if (symbolTokens == null)
            {
                return(ImmutableArray <ITagSpan <IClassificationTag> > .Empty);
            }
            ITextSnapshot textSnapshot = compilationSnapshot.Text;

            if (textSnapshot == null || spans.Count == 0 || spans.First().Snapshot.Version != textSnapshot.Version)
            {
                return(ImmutableArray <ITagSpan <IClassificationTag> > .Empty);
            }
            return(symbolTokens.Select(t => new TagSpan <IClassificationTag>(new SnapshotSpan(textSnapshot, new Span(t.Key.Span.Start, t.Key.Span.Length)), t.Value)));
        }
            internal void EnqueueChanges(NormalizedSnapshotSpanCollection changedSpans)
            {
                AssertIsForeground();
                if (changedSpans.Count == 0)
                {
                    return;
                }

                var snapshot = changedSpans.First().Snapshot;

                var version      = snapshot.Version.VersionNumber;
                var currentSpans = _snapshotVersionToSpansMap.GetOrAdd(version, s_addFunction);
                var allSpans     = NormalizedSnapshotSpanCollection.Union(currentSpans, changedSpans);

                _snapshotVersionToSpansMap[version] = allSpans;

                EnqueueNotificationRequest(TaggerDelay.NearImmediate);
            }
Exemple #27
0
        internal async override Task<CommentSelectionResult> CollectEditsAsync(Document document, ICommentSelectionService service,
            ITextBuffer subjectBuffer, NormalizedSnapshotSpanCollection selectedSpans, ValueTuple command, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.CommandHandler_ToggleLineComment, KeyValueLogMessage.Create(LogType.UserAction, m =>
            {
                m[LanguageNameString] = document.Project.Language;
                m[LengthString] = subjectBuffer.CurrentSnapshot.Length;
            }), cancellationToken))
            {
                var commentInfo = await service.GetInfoAsync(document, selectedSpans.First().Span.ToTextSpan(), cancellationToken).ConfigureAwait(false);
                if (commentInfo.SupportsSingleLineComment)
                {
                    return ToggleLineComment(commentInfo, selectedSpans);
                }

                return s_emptyCommentSelectionResult;
            }
        }
            public IEnumerable <ITagSpan <IClassificationTag> > GetAllTags(NormalizedSnapshotSpanCollection spans, CancellationToken cancellationToken)
            {
                this.AssertIsForeground();
                if (spans.Count == 0)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                var firstSpan = spans.First();
                var snapshot  = firstSpan.Snapshot;

                Debug.Assert(snapshot.TextBuffer == _subjectBuffer);

                var cachedSnapshot = this.CachedSnapshot;

                if (snapshot != cachedSnapshot)
                {
                    // Our cache is not there, or is out of date.  We need to compute the up to date
                    // results.

                    var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document == null)
                    {
                        return(Array.Empty <ITagSpan <IClassificationTag> >());
                    }

                    _classificationService = _classificationService ?? document.Project.LanguageServices.GetService <IEditorClassificationService>();

                    var context   = new TaggerContext <IClassificationTag>(document, snapshot, cancellationToken: cancellationToken);
                    var spanToTag = new DocumentSnapshotSpan(document, snapshot.GetFullSpan());
                    var task      = SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, _classificationService, _owner._typeMap);
                    task.Wait(cancellationToken);

                    CachedSnapshot = snapshot;
                    CachedTags     = new TagSpanIntervalTree <IClassificationTag>(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans);
                }

                if (this.CachedTags == null)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                return(this.CachedTags.GetIntersectingTagSpans(spans));
            }
        public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (m_failures != null && m_failures.Count > 0)
            {
                var first = m_failures.First();
                if (spans.Count > 0 && spans.First().Snapshot.Version != first.Span.Snapshot.Version)
                {
                    Update(false);
                }

                foreach (var f in m_failures)
                {
                    if (spans.IntersectsWith(f.Span))
                    {
                        yield return(new TagSpan <IErrorTag>(f.Span, new ErrorTag(PredefinedErrorTypeNames.Warning, f.FailureText.m_description)));
                    }
                }
            }
        }
        public IEnumerable <ITagSpan <ITextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            var snapshot = spans.First().Snapshot;

            foreach (ActiveStatementTextSpan asSpan in _trackingService.GetSpans(snapshot.AsText()))
            {
                if ((asSpan.Flags & ActiveStatementFlags.LeafFrame) != 0)
                {
                    continue;
                }

                var snapshotSpan = new SnapshotSpan(snapshot, Span.FromBounds(asSpan.Span.Start, asSpan.Span.End));

                if (spans.OverlapsWith(snapshotSpan))
                {
                    yield return(new TagSpan <ITextMarkerTag>(snapshotSpan, ActiveStatementTag.Instance));
                }
            }
        }
Exemple #31
0
        public IEnumerable <ITagSpan <PlayGlyphTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            var textSnapshot = (spans.Any()) ? spans.First().Snapshot : null;

            if (!features.Any() && textSnapshot != null && !tokenParser.LastParseFailed())
            {
                tokenParser.ForceParse(textSnapshot);
            }

            var tagSPans = new List <ITagSpan <PlayGlyphTag> >();

            foreach (var line in textSnapshot.Lines)
            {
                var spanLine = line.LineNumber + 1;

                AddFeatureTagSpan(spanLine, textSnapshot, line, tagSPans);
                AddScenarioTagSpan(spanLine, textSnapshot, line, tagSPans);
            }
            return(tagSPans);
        }
        internal static NormalizedSnapshotSpanCollection CoalesceSpans(NormalizedSnapshotSpanCollection normalizedSpans)
        {
            var snapshot = normalizedSpans.First().Snapshot;

            // Coalesce the spans if there are a lot of them.
            if (normalizedSpans.Count > CoalesceDifferenceCount)
            {
                // Spans are normalized.  So to find the whole span we just go from the
                // start of the first span to the end of the last span.
                normalizedSpans = new NormalizedSnapshotSpanCollection(snapshot.GetSpanFromBounds(
                    normalizedSpans.First().Start,
                    normalizedSpans.Last().End));
            }

            return normalizedSpans;
        }