internal IDisposable CreateBlock(string blockName)
        {
            // Unit tests case
            if (_performanceMarkerBlockProviders == null || _performanceMarkerBlockProviders.Count == 0)
            {
                return(new Block());
            }

            // Optimize for the most common case
            if (_performanceMarkerBlockProviders.Count == 1)
            {
                IDisposable block = _performanceMarkerBlockProviders[0].Value?.CreateBlock(blockName);
                if (block != null)
                {
                    return(block);
                }
            }

            var providedBlocks = new FrugalList <IDisposable>();

            for (int i = 0; i < _performanceMarkerBlockProviders.Count; i++)
            {
                providedBlocks.Add(_performanceMarkerBlockProviders[i].Value?.CreateBlock(blockName));
            }

            return(new Block(providedBlocks));
        }
Exemplo n.º 2
0
        private static void SplitMapDownToFirstMatchNoTrack(FrugalList <SnapshotSpan> unmappedSpans, Predicate <ITextBuffer> match, IList <SnapshotSpan> mappedSpans, bool mapByContentType)
        {
            ITextSnapshot matchingSnapshot = null;

            while (unmappedSpans.Count > 0)
            {
                SnapshotSpan span = unmappedSpans[unmappedSpans.Count - 1];
                unmappedSpans.RemoveAt(unmappedSpans.Count - 1);

                if (span.Snapshot == matchingSnapshot)
                {
                    mappedSpans.Add(span);
                }
                else if (match(span.Snapshot.TextBuffer))
                {
                    mappedSpans.Add(span);
                    matchingSnapshot = span.Snapshot;
                }
                else
                {
                    IProjectionSnapshot spanSnapshotAsProjection = span.Snapshot as IProjectionSnapshot;
                    if (spanSnapshotAsProjection != null &&
                        (!mapByContentType || span.Snapshot.TextBuffer.ContentType.IsOfType("projection")))
                    {
                        unmappedSpans.AddRange(spanSnapshotAsProjection.MapToSourceSnapshots(span));
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static void MapUpToSnapshotNoTrack(ITextSnapshot targetSnapshot, SnapshotSpan anchor, IList <SnapshotSpan> mappedSpans)
 {
     if (anchor.Snapshot == targetSnapshot)
     {
         mappedSpans.Add(anchor);
     }
     else
     {
         IProjectionSnapshot targetAsProjection = targetSnapshot as IProjectionSnapshot;
         if (targetAsProjection != null)
         {
             var sourceSnapshots = targetAsProjection.SourceSnapshots;
             for (int s = 0; s < sourceSnapshots.Count; ++s)
             {
                 FrugalList <SnapshotSpan> downSpans = new FrugalList <SnapshotSpan>();
                 MapUpToSnapshotNoTrack(sourceSnapshots[s], anchor, downSpans);
                 for (int ds = 0; ds < downSpans.Count; ++ds)
                 {
                     var upSpans = targetAsProjection.MapFromSourceSnapshot(downSpans[ds]);
                     for (int us = 0; us < upSpans.Count; ++us)
                     {
                         mappedSpans.Add(new SnapshotSpan(targetSnapshot, upSpans[us]));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        public NormalizedSnapshotSpanCollection GetSpans(ITextSnapshot targetSnapshot)
        {
            if (targetSnapshot == null)
            {
                throw new ArgumentNullException("targetSnapshot");
            }
            if (_unmappable)
            {
                return(NormalizedSnapshotSpanCollection.Empty);
            }

            NormalizedSnapshotSpanCollection results = this.GetSpans(targetSnapshot.TextBuffer);

            if ((results.Count > 0) && (results[0].Snapshot != targetSnapshot))
            {
                FrugalList <SnapshotSpan> translatedSpans = new FrugalList <SnapshotSpan>();
                foreach (SnapshotSpan s in results)
                {
                    translatedSpans.Add(s.TranslateTo(targetSnapshot, _trackingMode));
                }

                results = new NormalizedSnapshotSpanCollection(translatedSpans);
            }

            return(results);
        }
Exemplo n.º 5
0
        internal static NormalizedSnapshotSpanCollection MapDownToBufferNoTrack(SnapshotSpan sourceSpan, ITextBuffer targetBuffer, bool mapByContentType = false)
        {
            FrugalList <SnapshotSpan> mappedSpans = new FrugalList <SnapshotSpan>();

            MapDownToFirstMatchNoTrack(sourceSpan, (ITextBuffer b) => { return(b == targetBuffer); }, mappedSpans, mapByContentType);

            return(new NormalizedSnapshotSpanCollection(mappedSpans));
        }
Exemplo n.º 6
0
        private void MapUpToBufferNoTrack(Predicate <ITextBuffer> match, FrugalList <SnapshotSpan> mappedSpans)
        {
            ITextSnapshot targetSnapshot = MappingHelper.FindCorrespondingSnapshot(_root, match);

            if (targetSnapshot != null)
            {
                //Map _anchor up to targetSnapshot (they should be concurrent snapshots)
                MapUpToSnapshotNoTrack(targetSnapshot, mappedSpans);
            }
        }
Exemplo n.º 7
0
        internal static void MapDownToBufferNoTrack(SnapshotSpan sourceSpan, ITextBuffer targetBuffer, IList <SnapshotSpan> mappedSpans, bool mapByContentType = false)
        {
            // Most of the time, the sourceSpan will map to the targetBuffer as a single span, rather than being split.
            // Since this method is called a lot, we'll assume first that we'll get a single span and don't need to
            // allocate a stack to keep track of unmapped spans. If that fails we'll fall back on the more expensive approach.
            // Scroll around for a while and this saves a bunch of allocations.
            SnapshotSpan mappedSpan = sourceSpan;

            while (true)
            {
                if (mappedSpan.Snapshot.TextBuffer == targetBuffer)
                {
                    mappedSpans.Add(mappedSpan);
                    return;
                }
                else
                {
                    IProjectionSnapshot mappedSpanProjectionSnapshot = mappedSpan.Snapshot as IProjectionSnapshot;
                    if (mappedSpanProjectionSnapshot != null &&
                        (!mapByContentType || mappedSpanProjectionSnapshot.ContentType.IsOfType("projection")))
                    {
                        var mappedDownSpans = mappedSpanProjectionSnapshot.MapToSourceSnapshots(mappedSpan);
                        if (mappedDownSpans.Count == 1)
                        {
                            mappedSpan = mappedDownSpans[0];
                            continue;
                        }
                        else if (mappedDownSpans.Count == 0)
                        {
                            return;
                        }
                        else
                        {
                            // the projection mapping resulted in more than one span
                            FrugalList <SnapshotSpan> unmappedSpans = new FrugalList <SnapshotSpan>(mappedDownSpans);
                            SplitMapDownToBufferNoTrack(unmappedSpans, targetBuffer, mappedSpans, mapByContentType);
                            return;
                        }
                    }
                    else
                    {
                        // either it's a projection buffer we can't look through, or it's
                        // an ordinary buffer that didn't match
                        return;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public NormalizedSnapshotSpanCollection GetSpans(Predicate <ITextBuffer> match)
        {
            if (_unmappable)
            {
                return(NormalizedSnapshotSpanCollection.Empty);
            }

            //Try mapping down first.
            FrugalList <SnapshotSpan> mappedSpans = new FrugalList <SnapshotSpan>();

            MappingHelper.MapDownToFirstMatchNoTrack(_anchor, match, mappedSpans);
            if (mappedSpans.Count == 0)
            {
                //Unable to map down ... try mapping up.
                this.MapUpToBufferNoTrack(match, mappedSpans);
            }

            return(new NormalizedSnapshotSpanCollection(mappedSpans));
        }
Exemplo n.º 9
0
        private static void SplitMapDownToBufferNoTrack(FrugalList <SnapshotSpan> unmappedSpans, ITextBuffer targetBuffer, IList <SnapshotSpan> mappedSpans, bool mapByContentType)
        {
            while (unmappedSpans.Count > 0)
            {
                SnapshotSpan span = unmappedSpans[unmappedSpans.Count - 1];
                unmappedSpans.RemoveAt(unmappedSpans.Count - 1);

                if (span.Snapshot.TextBuffer == targetBuffer)
                {
                    mappedSpans.Add(span);
                }
                else
                {
                    IProjectionSnapshot spanSnapshotAsProjection = span.Snapshot as IProjectionSnapshot;
                    if (spanSnapshotAsProjection != null &&
                        (!mapByContentType || span.Snapshot.TextBuffer.ContentType.IsOfType("projection")))
                    {
                        unmappedSpans.AddRange(spanSnapshotAsProjection.MapToSourceSnapshots(span));
                    }
                }
            }
        }
Exemplo n.º 10
0
        public NormalizedSnapshotSpanCollection GetSpans(ITextBuffer targetBuffer)
        {
            if (targetBuffer == null)
            {
                throw new ArgumentNullException("targetBuffer");
            }

            if (_unmappable)
            {
                return(NormalizedSnapshotSpanCollection.Empty);
            }

            if (targetBuffer.Properties.ContainsProperty("IdentityMapping"))
            {
                // text buffer properties uses the hybrid dictionary, which requires TWO lookups to determine that
                // a key is not present. Since this test usually fails, do it the hard way (the second lookup shows up
                // in scrolling profiles).
                ITextBuffer doppelganger = (ITextBuffer)targetBuffer.Properties["IdentityMapping"];
                if (doppelganger == _anchor.Snapshot.TextBuffer)
                {
                    // We are mapping up from a doppelganger buffer; the coordinates will be the same. We
                    // just need to figure out the right snapshot.
                    ITextSnapshot targetSnapshot = MappingHelper.FindCorrespondingSnapshot(_root, targetBuffer);
                    return(new NormalizedSnapshotSpanCollection(new SnapshotSpan(targetSnapshot, _anchor.Span)));
                }
            }

            //Try mapping down first.
            FrugalList <SnapshotSpan> mappedSpans = new FrugalList <SnapshotSpan>();

            MappingHelper.MapDownToBufferNoTrack(_anchor, targetBuffer, mappedSpans);
            if (mappedSpans.Count == 0)
            {
                //Unable to map down ... try mapping up.
                this.MapUpToBufferNoTrack(targetBuffer, mappedSpans);
            }

            return(new NormalizedSnapshotSpanCollection(mappedSpans));
        }
 public Block(FrugalList <IDisposable> markers)
 {
     _markers = markers;
 }
Exemplo n.º 12
0
 public FrugalEnumerator(FrugalList <T> list)
 {
     this.list     = list;
     this.position = -1;
 }
Exemplo n.º 13
0
 /// <summary>
 /// For unit testing.
 /// </summary>
 public GuardedOperations(params IExtensionErrorHandler[] extensionErrorHandler)
 {
     _errorHandlers = new FrugalList <IExtensionErrorHandler>(extensionErrorHandler);
     _perfTrackers  = new FrugalList <IExtensionPerformanceTracker>();
 }
Exemplo n.º 14
0
 private void MapUpToSnapshotNoTrack(ITextSnapshot targetSnapshot, FrugalList <SnapshotSpan> mappedSpans)
 {
     MappingSpanSnapshot.MapUpToSnapshotNoTrack(targetSnapshot, _anchor, mappedSpans);
 }
Exemplo n.º 15
0
 /// <summary>
 /// For unit testing.
 /// </summary>
 public GuardedOperations(IExtensionErrorHandler extensionErrorHandler)
 {
     _errorHandlers = new List <IExtensionErrorHandler>();
     _errorHandlers.Add(extensionErrorHandler);
     _perfTrackers = new FrugalList <IExtensionPerformanceTracker>();
 }