Esempio n. 1
0
        private static IEnumerable <Span> MapUpToSnapshotRecursive(
            SnapshotSpan start,
            IProjectionSnapshot target
            )
        {
            foreach (var source in target.SourceSnapshots)
            {
                if (source == start.Snapshot)
                {
                    foreach (var result in target.MapFromSourceSnapshot(start))
                    {
                        yield return(result);
                    }
                }
                else if (source is IProjectionSnapshot sourceProjection)
                {
                    foreach (var span in MapUpToSnapshotRecursive(start, sourceProjection))
                    {
                        foreach (
                            var result in target.MapFromSourceSnapshot(
                                new SnapshotSpan(source, span)
                                )
                            )
                        {
                            yield return(result);
                        }
                    }
                }
            }

            yield break;
        }
 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]));
                     }
                 }
             }
         }
     }
 }
        private bool TryGetCurrentLanguageBufferExtent(IProjectionSnapshot projectionSnapshot, out Span result)
        {
            if (projectionSnapshot.SpanCount == 0)
            {
                result = default(Span);
                return(false);
            }

            // the last source snapshot is always a projection of a language buffer:
            var snapshot = projectionSnapshot.GetSourceSpan(projectionSnapshot.SpanCount - 1).Snapshot;

            if (snapshot.TextBuffer != _currentLanguageBuffer)
            {
                result = default(Span);
                return(false);
            }

            SnapshotPoint start = new SnapshotPoint(snapshot, 0);
            SnapshotPoint end   = new SnapshotPoint(snapshot, snapshot.Length);

            // projection of the previous version of current language buffer snapshot:
            var surfaceSpans = projectionSnapshot.MapFromSourceSnapshot(new SnapshotSpan(start, end));

            // the language buffer might be projected to multiple surface lines:
            Debug.Assert(surfaceSpans.Count > 0);
            result = new Span(surfaceSpans[0].Start, surfaceSpans.Last().End);
            return(true);
        }
        public static SnapshotPoint?MapUpToSnapshotNoTrack(ITextSnapshot targetSnapshot, SnapshotPoint anchor, PositionAffinity affinity)
        {
            if (anchor.Snapshot == targetSnapshot)
            {
                return(anchor);
            }
            else
            {
                IProjectionSnapshot targetAsProjection = targetSnapshot as IProjectionSnapshot;
                if (targetAsProjection != null)
                {
                    var sourceSnapshots = targetAsProjection.SourceSnapshots;
                    for (int s = 0; s < sourceSnapshots.Count; ++s)
                    {
                        SnapshotPoint?downPoint = MapUpToSnapshotNoTrack(sourceSnapshots[s], anchor, affinity);
                        if (downPoint.HasValue)
                        {
                            SnapshotPoint?result = targetAsProjection.MapFromSourceSnapshot(downPoint.Value, affinity);
                            if (result.HasValue)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 5
0
        public async Task <DataTipInfo> GetDebugInfoAsync(SnapshotPoint snapshotPoint, CancellationToken cancellationToken)
        {
            var analysisDocument = snapshotPoint.Snapshot.AsText().GetOpenDocumentInCurrentContextWithChanges();

            IProjectionSnapshot projectionSnapshot = null;

            if (analysisDocument == null)
            {
                projectionSnapshot = snapshotPoint.Snapshot as IProjectionSnapshot;
                if (projectionSnapshot != null)
                {
                    snapshotPoint    = projectionSnapshot.MapToSourceSnapshot(snapshotPoint.Position);
                    analysisDocument = snapshotPoint.Snapshot.AsText().GetOpenDocumentInCurrentContextWithChanges();
                }
            }

            if (analysisDocument == null)
            {
                return(default(DataTipInfo));
            }
            var debugInfoService = analysisDocument.GetLanguageService <Microsoft.CodeAnalysis.Editor.Implementation.Debugging.ILanguageDebugInfoService> ();

            if (debugInfoService == null)
            {
                return(default(DataTipInfo));
            }

            var tipInfo = await debugInfoService.GetDataTipInfoAsync(analysisDocument, snapshotPoint.Position, cancellationToken).ConfigureAwait(false);

            var text = tipInfo.Text;

            if (text == null && !tipInfo.IsDefault)
            {
                text = snapshotPoint.Snapshot.GetText(tipInfo.Span.Start, tipInfo.Span.Length);
            }

            var semanticModel = await analysisDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var root = await semanticModel.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var syntaxNode = root.FindNode(tipInfo.Span);
            DebugDataTipInfo debugDataTipInfo;

            if (syntaxNode == null)
            {
                debugDataTipInfo = new DebugDataTipInfo(tipInfo.Span, text);
            }
            else
            {
                debugDataTipInfo = GetInfo(root, semanticModel, syntaxNode, text, cancellationToken);
            }

            if (projectionSnapshot != null)
            {
                var originalSpan = projectionSnapshot.MapFromSourceSnapshot(new SnapshotSpan(snapshotPoint.Snapshot, debugDataTipInfo.Span.Start, debugDataTipInfo.Span.Length)).FirstOrDefault();
                if (originalSpan == default)
                {
                    return(default);
            private bool TryGetCurrentLanguageBufferExtent(IProjectionSnapshot projectionSnapshot, out Span result)
            {
                if (projectionSnapshot.SpanCount == 0)
                {
                    result = default(Span);
                    return false;
                }

                // the last source snapshot is always a projection of a language buffer:
                var snapshot = projectionSnapshot.GetSourceSpan(projectionSnapshot.SpanCount - 1).Snapshot;
                if (snapshot.TextBuffer != CurrentLanguageBuffer)
                {
                    result = default(Span);
                    return false;
                }

                SnapshotPoint start = new SnapshotPoint(snapshot, 0);
                SnapshotPoint end = new SnapshotPoint(snapshot, snapshot.Length);

                // projection of the previous version of current language buffer snapshot:
                var surfaceSpans = projectionSnapshot.MapFromSourceSnapshot(new SnapshotSpan(start, end));

                // the language buffer might be projected to multiple surface lines:
                Debug.Assert(surfaceSpans.Count > 0);
                result = new Span(surfaceSpans[0].Start, surfaceSpans.Last().End);
                return true;
            }
Esempio n. 7
0
        // Do a depth first search through the projection graph to find the first mapping
        private static IEnumerable<Span> MapUpToSnapshotRecursive(SnapshotSpan start, IProjectionSnapshot target)
        {
            foreach (var source in target.SourceSnapshots)
            {
                if (source == start.Snapshot)
                {
                    foreach (var result in target.MapFromSourceSnapshot(start))
                    {
                        yield return result;
                    }
                }
                else if (source is IProjectionSnapshot)
                {
                    var sourceProjection = source as IProjectionSnapshot;
                    foreach (var span in MapUpToSnapshotRecursive(start, sourceProjection))
                    {
                        foreach (var result in target.MapFromSourceSnapshot(new SnapshotSpan(source, span)))
                        {
                            yield return result;
                        }
                    }
                }
            }

            yield break;
        }