Example #1
0
        LocationsResult GetLocations(IDocumentTab?tab, VirtualSnapshotPoint?position)
        {
            var allLocations = new List <DbgCodeLocation>();
            var textView     = GetTextView(tab);

            if (textView is null)
            {
                return(new LocationsResult(dbgManager, null, allLocations));
            }
            Debug.Assert(!(tab is null));
            var pos = position ?? textView.Caret.Position.VirtualBufferPosition;

            if (pos.Position.Snapshot != textView.TextSnapshot)
            {
                throw new ArgumentException();
            }
            DbgTextViewBreakpointLocationResult?res = null;

            foreach (var loc in dbgTextViewCodeLocationService.Value.CreateLocation(tab, textView, pos))
            {
                UpdateResult(allLocations, textView, ref res, loc, useIfSameSpan: false);
            }
            SnapshotSpan span;

            if (!(res is null))
            {
                var resSpan  = res.Value.Span.SnapshotSpan;
                var newStart = Min(pos.Position, resSpan.Start);
                var newEnd   = Max(pos.Position, resSpan.End);
                span = new SnapshotSpan(newStart, newEnd);
            }
        void ToggleEnableBookmark(IDocumentTab?tab, VirtualSnapshotPoint?position)
        {
            var  info = GetToggleEnableBookmarkInfo(tab, position);
            bool newIsEnabled;

            switch (info.kind)
            {
            case ToggleEnableBookmarkKind.Enable:
                newIsEnabled = true;
                break;

            case ToggleEnableBookmarkKind.Disable:
                newIsEnabled = false;
                break;

            case ToggleEnableBookmarkKind.None:
            default:
                return;
            }
            bookmarksService.Value.Modify(info.bookmarks.Select(a => {
                var newSettings       = a.Settings;
                newSettings.IsEnabled = newIsEnabled;
                return(new BookmarkAndSettings(a, newSettings));
            }).ToArray());
        }
 Bookmark[] GetBookmarks(IDocumentTab?tab, VirtualSnapshotPoint?position)
 {
     using (var info = GetLocation(tab, position)) {
         if (info.locRes is TextViewBookmarkLocationResult locRes)
         {
             return(GetBookmarks(locRes));
         }
         return(Array.Empty <Bookmark>());
     }
 }
Example #4
0
        public static void AddMark(
            this Mock <IMarkMap> map,
            ITextBuffer buffer,
            char mark,
            SnapshotPoint?point = null)
        {
            VirtualSnapshotPoint?virtualPoint = null;

            if (point.HasValue)
            {
                virtualPoint = new VirtualSnapshotPoint(point.Value);
            }
            AddMark(map, buffer, mark, virtualPoint);
        }
Example #5
0
 public static void AddMark(
     this Mock <IMarkMap> map,
     ITextBuffer buffer,
     char mark,
     VirtualSnapshotPoint?point = null)
 {
     if (point.HasValue)
     {
         map.Setup(x => x.GetMark(buffer, mark)).Returns(FSharpOption.Create(point.Value));
     }
     else
     {
         map.Setup(x => x.GetMark(buffer, mark)).Returns(FSharpOption <VirtualSnapshotPoint> .None);
     }
 }
        private void MoveCaretToPreviousTabStop()
        {
            var caretStartingPosition = Caret.Position.VirtualBufferPosition;
            var caretStartingColumn   = CaretColumn;

            Caret.MoveToPreviousCaretPosition();
            var lastCaretColumn = -1;

            while (CaretColumn % IndentSize != (IndentSize - 1) && CaretCharIsASpace)
            {
                if (CaretColumn >= lastCaretColumn && lastCaretColumn != -1)
                {
                    break;                     // Prevent infinite loop on first char of first line or in box selection
                }
                lastCaretColumn = CaretColumn;
                Caret.MoveToPreviousCaretPosition();
            }

            if (Caret.Position.BufferPosition.Position != 0)
            {             // Do this for all cases except the first char of the document
                Caret.MoveToNextCaretPosition();
            }

            VirtualSnapshotPoint?caretNewPosition = Caret.Position.VirtualBufferPosition;
            int movedBy = caretStartingColumn - CaretColumn;

            if (movedBy % IndentSize != 0)
            {
                // We moved less than a full tab stop length. Only allow this if the cursor started in the middle of a full tab
                for (int i = 0; i < IndentSize; i++)
                {
                    if (Caret.Position.BufferPosition.Add(i).GetChar() != ' ')
                    {
                        caretNewPosition = null;
                        Caret.MoveTo(caretStartingPosition);                         // Do not align on non-exact tab stops
                        break;
                    }
                }
                if (caretNewPosition != null)
                {
                    Caret.MoveTo(caretNewPosition.Value);                     // Go back to original new position
                }
            }

            Caret.EnsureVisible();
        }
Example #7
0
        LocationsResult GetLocations(IDocumentTab?tab, VirtualSnapshotPoint?position)
        {
            var allLocations = new List <DbgCodeLocation>();
            var textView     = GetTextView(tab);

            if (textView is null)
            {
                return(new LocationsResult(dbgManager, null, allLocations));
            }
            Debug2.Assert(tab is not null);
            var pos = position ?? textView.Caret.Position.VirtualBufferPosition;

            if (pos.Position.Snapshot != textView.TextSnapshot)
            {
                throw new ArgumentException();
            }
            DbgTextViewBreakpointLocationResult?res = null;

            foreach (var loc in dbgTextViewCodeLocationService.Value.CreateLocation(tab, textView, pos))
            {
                UpdateResult(allLocations, textView, ref res, loc, useIfSameSpan: false);
            }
            SnapshotSpan span;

            if (res is not null)
            {
                var resSpan  = res.Value.Span.SnapshotSpan;
                var newStart = Min(pos.Position, resSpan.Start);
                var newEnd   = Max(pos.Position, resSpan.End);
                span = new SnapshotSpan(newStart, newEnd);
            }
            else
            {
                span = new SnapshotSpan(pos.Position, new SnapshotPoint(pos.Position.Snapshot, pos.Position.Snapshot.Length));
            }
            // This one has higher priority since it already exists (eg. could be a stack frame BP location)
            UpdateResult(allLocations, textView, ref res, breakpointMarker.Value.GetLocations(textView, span), useIfSameSpan: true);
            return(new LocationsResult(dbgManager, res, allLocations));
        }
        LocationsResult GetLocation(IDocumentTab?tab, VirtualSnapshotPoint?position)
        {
            var allLocations = new List <BookmarkLocation>();
            var textView     = GetTextView(tab);

            if (textView is null)
            {
                return(new LocationsResult(bookmarksService, null, allLocations));
            }
            Debug2.Assert(tab is not null);
            var pos = position ?? textView.Caret.Position.VirtualBufferPosition;

            if (pos.Position.Snapshot != textView.TextSnapshot)
            {
                throw new ArgumentException();
            }
            TextViewBookmarkLocationResult?res = null;

            foreach (var lz in textViewBookmarkLocationProviders)
            {
                var result = lz.Value.CreateLocation(tab, textView, pos);
                if (result?.Location is null)
                {
                    continue;
                }
                allLocations.Add(result.Value.Location);
                if (result.Value.Span.Snapshot != textView.TextSnapshot)
                {
                    continue;
                }
                if (res is null || result.Value.Span.Start < res.Value.Span.Start)
                {
                    res = result;
                }
            }
            return(new LocationsResult(bookmarksService, res, allLocations));
        }
Example #9
0
        ToggleCreateBreakpointInfoResult GetToggleCreateBreakpointInfo(IDocumentTab tab, VirtualSnapshotPoint?position)
        {
            using (var info = GetLocations(tab, position)) {
                var locRes = info.locRes;
                var bps    = locRes == null?Array.Empty <DbgCodeBreakpoint>() : GetBreakpoints(locRes.Value);

                if (bps.Length != 0)
                {
                    if (bps.All(a => a.IsEnabled))
                    {
                        return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.Delete, bps, Array.Empty <DbgCodeLocation>()));
                    }
                    return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.Enable, bps, Array.Empty <DbgCodeLocation>()));
                }
                else
                {
                    if (locRes == null || locRes.Value.Locations.Length == 0)
                    {
                        return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.None, Array.Empty <DbgCodeBreakpoint>(), Array.Empty <DbgCodeLocation>()));
                    }
                    return(new ToggleCreateBreakpointInfoResult(dbgManager, ToggleCreateBreakpointKind.Add, Array.Empty <DbgCodeBreakpoint>(), locRes.Value.Locations.Select(a => a.Clone()).ToArray()));
                }
            }
        }
        ToggleCreateBreakpointInfoResult GetToggleCreateBookmarkInfo(IDocumentTab?tab, VirtualSnapshotPoint?position)
        {
            using (var info = GetLocation(tab, position)) {
                var locRes = info.locRes;
                var bms    = locRes is null?Array.Empty <Bookmark>() : GetBookmarks(locRes.Value);

                if (bms.Length != 0)
                {
                    return(new ToggleCreateBreakpointInfoResult(bookmarksService, ToggleCreateBookmarkKind.Delete, bms, null));
                }
                else
                {
                    if (locRes is null || locRes.Value.Location is null)
                    {
                        return(new ToggleCreateBreakpointInfoResult(bookmarksService, ToggleCreateBookmarkKind.None, Array.Empty <Bookmark>(), null));
                    }
                    return(new ToggleCreateBreakpointInfoResult(bookmarksService, ToggleCreateBookmarkKind.Add, Array.Empty <Bookmark>(), info.TakeOwnership(locRes.Value.Location)));
                }
            }
        }