Beispiel #1
0
        public void OnCustomData(IDocumentViewerCustomDataContext context)
        {
            SpanDataCollection <ReferenceAndId> result;
            var data = context.GetData <SpanReference>(PredefinedCustomDataIds.SpanReference);

            if (data.Length == 0)
            {
                result = SpanDataCollection <ReferenceAndId> .Empty;
            }
            else
            {
                var builder = SpanDataCollectionBuilder <ReferenceAndId> .CreateBuilder(data.Length);

                int prevEnd = 0;
                foreach (var d in data)
                {
                    // The data should already be sorted. We don't support overlaps at the moment.
                    Debug.Assert(prevEnd <= d.Span.Start);
                    if (prevEnd <= d.Span.Start)
                    {
                        builder.Add(new Span(d.Span.Start, d.Span.Length), new ReferenceAndId(d.Reference, d.Id));
                        prevEnd = d.Span.End;
                    }
                }
                result = builder.Create();
            }
            context.AddCustomData(DocumentViewerContentDataIds.SpanReference, result);
        }
Beispiel #2
0
        DocumentViewerOutput()
        {
            this.cachedTextColorsCollection = new CachedTextColorsCollection();
            this.stringBuilder    = new StringBuilder();
            this.referenceBuilder = SpanDataCollectionBuilder <ReferenceInfo> .CreateBuilder();

            this.canBeCached    = true;
            this.customDataDict = new Dictionary <string, object>(StringComparer.Ordinal);
        }
        DocumentViewerOutput()
        {
            state = State.GeneratingContent;
            cachedTextColorsCollection = new CachedTextColorsCollection();
            stringBuilder    = new StringBuilder();
            referenceBuilder = SpanDataCollectionBuilder <ReferenceInfo> .CreateBuilder();

            canBeCached    = true;
            customDataDict = new Dictionary <string, object>(StringComparer.Ordinal);
            indenter       = new Indenter(4, 4, true);
        }
Beispiel #4
0
        public BracePairCollection(CodeBracesRange[] ranges)
        {
            if (ranges == null)
            {
                throw new ArgumentNullException(nameof(ranges));
            }

            if (ranges.Length == 0)
            {
                leftSorted  = SpanDataCollection <Span> .Empty;
                rightSorted = SpanDataCollection <Span> .Empty;
            }
            else
            {
                int prevEnd;
                var builder = SpanDataCollectionBuilder <Span> .CreateBuilder(ranges.Length);

                Array.Sort(ranges, LeftSorter.Instance);
                prevEnd = 0;
                foreach (var p in ranges)
                {
                    if (!p.Flags.IsBraces())
                    {
                        continue;
                    }
                    if (prevEnd <= p.Left.Start)
                    {
                        builder.Add(new Span(p.Left.Start, p.Left.Length), new Span(p.Right.Start, p.Right.Length));
                        prevEnd = p.Left.End;
                    }
                }
                leftSorted = builder.Create();

                builder.Clear();
                Array.Sort(ranges, RightSorter.Instance);
                prevEnd = 0;
                foreach (var p in ranges)
                {
                    if (!p.Flags.IsBraces())
                    {
                        continue;
                    }
                    if (prevEnd <= p.Right.Start)
                    {
                        builder.Add(new Span(p.Right.Start, p.Right.Length), new Span(p.Left.Start, p.Left.Length));
                        prevEnd = p.Right.End;
                    }
                }
                rightSorted = builder.Create();
            }
        }
Beispiel #5
0
        SpanDataCollection <ClassificationTag> CreateClassifications(ITextSnapshot snapshot)
        {
            var builder = SpanDataCollectionBuilder <ClassificationTag> .CreateBuilder();

            var classifier = new XmlClassifier(snapshot);

            for (;;)
            {
                var info = classifier.GetNext();
                if (info == null)
                {
                    break;
                }
                var classificationTag = GetClassificationTag(info.Value.Kind);
                if (classificationTag == null)
                {
                    continue;
                }
                builder.Add(info.Value.Span, classificationTag);
            }

            return(builder.Create());
        }