Example #1
0
        internal Mock <ITextViewLineCollection> CreateTextViewLineCollection(SnapshotLineRange lineRange)
        {
            var mock = _factory.Create <ITextViewLineCollection>();

            mock.SetupGet(x => x.IsValid).Returns(true);
            var firstLineRange = new SnapshotLineRange(lineRange.Snapshot, lineRange.StartLineNumber, 1);
            var firstLine      = CreateTextViewLine(firstLineRange);

            mock.SetupGet(x => x.FirstVisibleLine).Returns(firstLine.Object);

            var lastLineRange = new SnapshotLineRange(lineRange.Snapshot, lineRange.LastLineNumber, 1);
            var lastLine      = CreateTextViewLine(lastLineRange);

            mock.SetupGet(x => x.LastVisibleLine).Returns(lastLine.Object);

            var lineList = new List <ITextViewLine>()
            {
                firstLine.Object, lastLine.Object
            };

            mock.SetupGet(x => x.Count).Returns(lineList.Count);
            mock.Setup(x => x.GetEnumerator()).Returns(lineList.GetEnumerator());
            mock.Setup(x => x.CopyTo(It.IsAny <ITextViewLine[]>(), It.IsAny <int>()))
            .Callback((ITextViewLine[] array, int index) => lineList.CopyTo(array, index));

            return(mock);
        }
Example #2
0
            public void FulfillOutstandingRequests()
            {
                Create("cat", "dog", "fish", "tree");
                _asyncTagger.ChunkCount = 1;
                _asyncTaggerSource.SetBackgroundFunc(
                    span =>
                {
                    var lineRange = SnapshotLineRange.CreateForSpan(span);
                    if (lineRange.LineRange.ContainsLineNumber(0))
                    {
                        return(span.Snapshot.GetLineFromLineNumber(0).Extent);
                    }

                    if (lineRange.LineRange.ContainsLineNumber(1))
                    {
                        return(span.Snapshot.GetLineFromLineNumber(1).Extent);
                    }

                    return(null);
                });

                for (int i = 0; i < _textBuffer.CurrentSnapshot.LineCount; i++)
                {
                    var span = _textBuffer.GetLineSpan(i, i);
                    var col  = new NormalizedSnapshotSpanCollection(span);
                    _asyncTagger.GetTags(col);
                }

                _asyncTaggerSource.Delay = null;
                WaitForBackgroundToComplete();

                var tags = _asyncTagger.GetTags(new NormalizedSnapshotSpanCollection(_textBuffer.GetExtent()));

                Assert.Equal(2, tags.Count());
            }
Example #3
0
            internal void WriteVisibleLines(SnapshotLineRange lineRange)
            {
                var textViewLineRange = new TextViewLineRange(lineRange);

                Interlocked.Exchange(ref _textViewLineRange, textViewLineRange);
                Interlocked.Increment(ref _version);
            }
Example #4
0
 internal BackgroundCacheData(SnapshotLineRange lineRange, ReadOnlyCollection <ITagSpan <TTag> > tagList)
 {
     Snapshot          = lineRange.Snapshot;
     VisitedCollection = new NormalizedLineRangeCollection();
     VisitedCollection.Add(lineRange.LineRange);
     TagList = tagList;
 }
Example #5
0
            public void Lines1()
            {
                Create("a", "b");
                var lineRange = SnapshotLineRange.CreateForLineAndMaxCount(_textBuffer.GetLine(0), 400);

                Assert.Equal(2, lineRange.Count);
            }
Example #6
0
        private IEnumerable <ITagSpan <TTag> > GetTags(SnapshotSpan span)
        {
            var lineRange = SnapshotLineRange.CreateForSpan(span);

            EditorUtilsTrace.TraceInfo("AsyncTagger::GetTags {0} - {1}", lineRange.StartLineNumber, lineRange.LastLineNumber);

            // First try and see if the tagger can provide prompt data.  We want to avoid
            // creating Task<T> instances if possible.
            IEnumerable <ITagSpan <TTag> > tagList = EmptyTagList;

            if (!TryGetTagsPrompt(span, out tagList) &&
                !TryGetTagsFromBackgroundDataCache(span, out tagList))
            {
                // The request couldn't be fully satisfied from the cache or prompt data so
                // we will request the data in the background thread
                GetTagsInBackground(span);

                // Since the request couldn't be fully fulfilled by the cache we augment the returned data
                // with our tracking data
                var trackingTagList = GetTagsFromTrackingDataCache(span.Snapshot);
                tagList = tagList == null
                    ? trackingTagList
                    : tagList.Concat(trackingTagList);
            }

            // Now filter the set of returned ITagSpan values to those which are part of the
            // requested NormalizedSnapshotSpanCollection.  The cache lookups don't dig down and
            // instead return all available tags.  We filter down the collection here to what's
            // necessary.
            return(tagList.Where(tagSpan => tagSpan.Span.IntersectsWith(span)));
        }
Example #7
0
            public void ForExtent()
            {
                Create("cat", "dog");
                var lineRange = SnapshotLineRange.CreateForExtent(_textBuffer.CurrentSnapshot);

                Assert.Equal(2, lineRange.Count);
                Assert.Equal(_textBuffer.CurrentSnapshot.Length, lineRange.ExtentIncludingLineBreak.Length);
            }
Example #8
0
        internal Mock <ITextViewLine> CreateTextViewLine(SnapshotLineRange lineRange)
        {
            var mock = _factory.Create <ITextViewLine>();

            mock.SetupGet(x => x.Start).Returns(lineRange.Start);
            mock.SetupGet(x => x.End).Returns(lineRange.EndIncludingLineBreak);
            return(mock);
        }
 private void RaiseLayoutChanged(SnapshotLineRange visibleRange = null)
 {
     visibleRange = visibleRange ?? _textBuffer.GetLineRange(0, _textBuffer.CurrentSnapshot.LineCount - 1);
     _textView
     .SetupGet(x => x.TextViewLines)
     .Returns(MockObjectFactory.CreateTextViewLineCollection(visibleRange, _factory).Object);
     _textView.Raise(x => x.LayoutChanged += null, null, null);
 }
Example #10
0
 internal static ModeArgument CreateSubstituteArgument(
     SnapshotSpan span,
     SnapshotLineRange range = null,
     SubstituteData data     = null)
 {
     range = range ?? SnapshotLineRangeUtil.CreateForSnapshot(span.Snapshot);
     data  = data ?? new SubstituteData("a", "b", SubstituteFlags.None);
     return(ModeArgument.NewSubstitute(span, range, data));
 }
Example #11
0
        internal Mock <ITextViewLine> CreateTextViewLine(SnapshotLineRange lineRange)
        {
            var mock = _factory.Create <ITextViewLine>();

            mock.SetupGet(x => x.Start).Returns(lineRange.Start);
            mock.SetupGet(x => x.End).Returns(lineRange.End);
            mock.SetupGet(x => x.VisibilityState).Returns(VisibilityState.FullyVisible);
            return(mock);
        }
Example #12
0
            public void ForLine()
            {
                Create("cat", "dog");
                var line      = _textBuffer.CurrentSnapshot.GetLineFromLineNumber(1);
                var lineRange = SnapshotLineRange.CreateForLine(line);

                Assert.Equal(1, lineRange.StartLineNumber);
                Assert.Equal(1, lineRange.Count);
                Assert.Equal("dog", lineRange.GetText());
            }
Example #13
0
        private void RaiseTagsChanged(SnapshotSpan span)
        {
            var lineRange = SnapshotLineRange.CreateForSpan(span);

            EditorUtilsTrace.TraceInfo("AsyncTagger::RaiseTagsChanged {0} - {1}", lineRange.StartLineNumber, lineRange.LastLineNumber);

            if (_tagsChanged != null)
            {
                _tagsChanged(this, new SnapshotSpanEventArgs(span));
            }
        }
Example #14
0
        internal static ModeArgument CreateSubstituteArgument(
            SnapshotSpan span,
            string search,
            string replace,
            SubstituteFlags?flags   = null,
            SnapshotLineRange range = null)
        {
            range = range ?? SnapshotLineRangeUtil.CreateForSnapshot(span.Snapshot);
            var data = new SubstituteData(search, replace, flags ?? SubstituteFlags.None);

            return(ModeArgument.NewSubstitute(span, range, data));
        }
Example #15
0
        /// <summary>
        /// Format the specified line range.  There is no inherent operation to do this
        /// in Visual Studio.  Instead we leverage the FormatSelection command.  Need to be careful
        /// to reset the selection after a format
        /// </summary>
        public override void FormatLines(ITextView textView, SnapshotLineRange range)
        {
            var startedWithSelection = !textView.Selection.IsEmpty;

            textView.Selection.Clear();
            textView.Selection.Select(range.ExtentIncludingLineBreak, false);
            SafeExecuteCommand("Edit.FormatSelection");
            if (!startedWithSelection)
            {
                textView.Selection.Clear();
            }
        }
Example #16
0
            internal void WriteNormal(SnapshotLineRange lineRange)
            {
                bool success;

                do
                {
                    var oldStack = _stack;
                    var newStack = _stack.Push(lineRange);
                    success = oldStack == Interlocked.CompareExchange(ref _stack, newStack, oldStack);
                } while (!success);

                Interlocked.Increment(ref _version);
            }
Example #17
0
        public void FormatLines(ITextView textView, SnapshotLineRange range)
        {
            var startedWithSelection = !textView.Selection.IsEmpty;

            textView.Selection.Clear();
            textView.Selection.Select(range.ExtentIncludingLineBreak, false);

            // FormatBuffer command actually formats the selection
            Dispatch(CodeFormattingCommands.FormatBuffer);
            if (!startedWithSelection)
            {
                textView.Selection.Clear();
            }
        }
Example #18
0
        public void GetCommandStatusVisualLineMode()
        {
            string[] lines      = { "cat", "dog", "fish" };
            var      textBuffer = CreateTextBuffer(lines);

            _vimBuffer.TextBufferImpl = textBuffer;
            _vimBuffer.ModeImpl       = _visualMode.Object;
            _vimBuffer.ModeKindImpl   = ModeKind.VisualLine;

            var span      = new SnapshotLineRange(textBuffer.CurrentSnapshot, 1, 2);
            var selection = new VisualSelection.Line(span, SearchPath.Forward, 0);

            _visualMode.SetupGet(x => x.VisualSelection).Returns(selection);
            Assert.Equal("2", CommandMarginUtil.GetShowCommandText(_vimBuffer));
        }
Example #19
0
        internal Mock <ITextViewLineCollection> CreateTextViewLineCollection(SnapshotLineRange lineRange)
        {
            var mock           = _factory.Create <ITextViewLineCollection>();
            var firstLineRange = new SnapshotLineRange(lineRange.Snapshot, lineRange.StartLineNumber, 1);
            var firstLine      = CreateTextViewLine(firstLineRange);

            mock.SetupGet(x => x.FirstVisibleLine).Returns(firstLine.Object);

            var lastLineRange = new SnapshotLineRange(lineRange.Snapshot, lineRange.LastLineNumber, 1);
            var lastLine      = CreateTextViewLine(lastLineRange);

            mock.SetupGet(x => x.LastVisibleLine).Returns(lastLine.Object);

            return(mock);
        }
Example #20
0
        internal AsyncTaggerType.AsyncBackgroundRequest CreateAsyncBackgroundRequest(
            SnapshotSpan span,
            CancellationTokenSource cancellationTokenSource,
            Task task = null)
        {
            var channel = new AsyncTagger <string, TextMarkerTag> .Channel();

            channel.WriteNormal(SnapshotLineRange.CreateForSpan(span));

            task = task ?? new Task(() => { });
            return(new AsyncTaggerType.AsyncBackgroundRequest(
                       span.Snapshot,
                       channel,
                       task,
                       cancellationTokenSource));
        }
            internal ReadOnlyCollection <ITagSpan <TextMarkerTag> > GetTags(SnapshotSpan span)
            {
                var lineRange = SnapshotLineRange.CreateForSpan(span);

                Debug.WriteLine("WordUnderCaret Version {0}, Lines {1} - {2}", span.Snapshot.Version.VersionNumber, lineRange.StartLineNumber, lineRange.LastLineNumber);

                var tags = new List <ITagSpan <TextMarkerTag> >();

                foreach (var snapshotLine in lineRange.Lines)
                {
                    AddWordsOnLine(tags, snapshotLine);
                    _cancellationToken.ThrowIfCancellationRequested();
                }

                return(tags.ToReadOnlyCollectionShallow());
            }
Example #22
0
        protected override ReadOnlyCollection <ITagSpan <TextMarkerTag> > GetTagsInBackground(string data, SnapshotSpan span, CancellationToken cancellationToken)
        {
            var lineRange = SnapshotLineRange.CreateForSpan(span);
            var list      = new List <ITagSpan <TextMarkerTag> >();

            foreach (var snapshotLine in lineRange.Lines)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var commentSpan = MatchLine(snapshotLine);
                if (commentSpan.HasValue)
                {
                    var tagSpan = new TagSpan <TextMarkerTag>(commentSpan.Value, s_tag);
                    list.Add(tagSpan);
                }
            }

            return(list.ToReadOnlyCollectionShallow());
        }
Example #23
0
            internal ReadOnlyCollection <ITagSpan <TextMarkerTag> > GetTags(SnapshotSpan span)
            {
                var tags      = new List <ITagSpan <TextMarkerTag> >();
                var lineRange = SnapshotLineRange.CreateForSpan(span);

                Debug.WriteLine("Cat Version {0}, Lines {1} - {2}", span.Snapshot.Version.VersionNumber, lineRange.StartLineNumber, lineRange.LastLineNumber);
                foreach (var snapshotLine in lineRange.Lines)
                {
                    AddWordsOnLine(tags, snapshotLine);
                    _cancellationToken.ThrowIfCancellationRequested();
                }

                // Cats need naps
                Debug.WriteLine("Cat Nap Time");
                Thread.Sleep(TimeSpan.FromSeconds(1));
                Debug.WriteLine("Cat Wake Up");

                return(tags.ToReadOnlyCollectionShallow());
            }
Example #24
0
            /// <summary>
            /// Determine tag cache state we have for the given SnapshotSpan
            /// </summary>
            internal TagCacheState GetTagCacheState(SnapshotSpan span)
            {
                // If the requested span doesn't even intersect with the overarching SnapshotSpan
                // of the cached data in the background then a more exhaustive search isn't needed
                // at this time
                var cachedSpan = Span;

                if (!cachedSpan.IntersectsWith(span))
                {
                    return(TagCacheState.None);
                }

                var lineRange = SnapshotLineRange.CreateForSpan(span);
                var unvisited = VisitedCollection.GetUnvisited(lineRange.LineRange);

                return(unvisited.HasValue
                    ? TagCacheState.Partial
                    : TagCacheState.Complete);
            }
Example #25
0
        public static Mock <ITextViewLineCollection> CreateTextViewLineCollection(
            SnapshotLineRange range,
            MockRepository factory = null)
        {
            factory = factory ?? new MockRepository(MockBehavior.Strict);
            var mock = factory.Create <ITextViewLineCollection>();

            for (int i = 0; i < range.Count; i++)
            {
                var number     = range.StartLineNumber + i;
                var line       = range.Snapshot.GetLineFromLineNumber(number);
                var localIndex = i;
                mock.Setup(x => x[localIndex]).Returns(CreateTextViewLine(line, factory).Object);
            }

            mock.SetupGet(x => x.FirstVisibleLine).Returns(CreateTextViewLine(range.StartLine, factory).Object);
            mock.SetupGet(x => x.LastVisibleLine).Returns(CreateTextViewLine(range.LastLine, factory).Object);
            mock.SetupGet(x => x.Count).Returns(range.Count);
            return(mock);
        }
Example #26
0
 void IVimHost.FormatLines(ITextView value, SnapshotLineRange range)
 {
     throw new NotImplementedException();
 }
Example #27
0
 /// <summary>
 /// Format the specified line range.  There is no inherent operation to do this
 /// in Visual Studio.  Instead we leverage the FormatSelection command.  Need to be careful
 /// to reset the selection after a format
 /// </summary>
 public override void FormatLines(ITextView textView, SnapshotLineRange range)
 {
     var startedWithSelection = !textView.Selection.IsEmpty;
     textView.Selection.Clear();
     textView.Selection.Select(range.ExtentIncludingLineBreak, false);
     SafeExecuteCommand("Edit.FormatSelection");
     if (!startedWithSelection)
     {
         textView.Selection.Clear();
     }
 }
Example #28
0
 internal static ModeArgument CreateSubstituteArgument(
     SnapshotSpan span,
     string search,
     string replace,
     SubstituteFlags? flags = null,
     SnapshotLineRange range = null)
 {
     range = range ?? SnapshotLineRangeUtil.CreateForSnapshot(span.Snapshot);
     var data = new SubstituteData(search, replace, flags ?? SubstituteFlags.None);
     return ModeArgument.NewSubsitute(span, range, data);
 }
Example #29
0
 internal static ModeArgument CreateSubstituteArgument(
     SnapshotSpan span,
     SnapshotLineRange range = null,
     SubstituteData data = null)
 {
     range = range ?? SnapshotLineRangeUtil.CreateForSnapshot(span.Snapshot);
     data = data ?? new SubstituteData("a", "b", SubstituteFlags.None);
     return ModeArgument.NewSubsitute(span, range, data);
 }
Example #30
0
        public static Mock<ITextViewLineCollection> CreateTextViewLineCollection(
            SnapshotLineRange range,
            MockRepository factory = null)
        {
            factory = factory ?? new MockRepository(MockBehavior.Strict);
            var mock = factory.Create<ITextViewLineCollection>();
            for (int i = 0; i < range.Count; i++)
            {
                var number = range.StartLineNumber + i;
                var line = range.Snapshot.GetLineFromLineNumber(number);
                var localIndex = i;
                mock.Setup(x => x[localIndex]).Returns(CreateTextViewLine(line, factory).Object);
            }

            mock.SetupGet(x => x.FirstVisibleLine).Returns(CreateTextViewLine(range.StartLine, factory).Object);
            mock.SetupGet(x => x.LastVisibleLine).Returns(CreateTextViewLine(range.LastLine, factory).Object);
            mock.SetupGet(x => x.Count).Returns(range.Count);
            return mock;
        }
Example #31
0
 private void RaiseLayoutChanged(SnapshotLineRange visibleRange = null)
 {
     visibleRange = visibleRange ?? _textBuffer.GetLineRange(0, _textBuffer.CurrentSnapshot.LineCount - 1);
     _textView
         .SetupGet(x => x.TextViewLines)
         .Returns(MockObjectFactory.CreateTextViewLineCollection(visibleRange, _factory).Object);
     _textView.Raise(x => x.LayoutChanged += null, null, null);
 }
Example #32
0
 public override void FormatLines(ITextView textView, SnapshotLineRange range)
 {
 }
Example #33
0
 internal void SetVisibleLineRange(Mock <ITextView> textView, SnapshotLineRange lineRange)
 {
     textView.SetupGet(x => x.InLayout).Returns(false);
     textView.SetupGet(x => x.TextViewLines).Returns(CreateTextViewLineCollection(lineRange).Object);
 }
Example #34
0
 void IVimHost.FormatLines(ITextView textView, SnapshotLineRange range)
 {
     FormatLines(textView, range);
 }
Example #35
0
 public abstract void FormatLines(ITextView textView, SnapshotLineRange range);
Example #36
0
 public abstract void FormatLines(ITextView textView, SnapshotLineRange range);
Example #37
0
 public override void FormatLines(ITextView textView, SnapshotLineRange range)
 {
 }
Example #38
0
 void IVimHost.FormatLines(ITextView textView, SnapshotLineRange range)
 {
     FormatLines(textView, range);
 }
Example #39
0
 void IVimHost.FormatLines(ITextView value, SnapshotLineRange range)
 {
     throw new NotImplementedException();
 }
Example #40
0
 /// <summary>
 /// Tests the given range text will produce the provided range
 /// </summary>
 private void TestRange(string rangeText, SnapshotLineRange range)
 {
     _operations.Setup(x => x.Join(range, JoinKind.RemoveEmptySpaces)).Verifiable();
     RunCommand(rangeText + "j");
     _operations.Verify();
 }