Example #1
0
            public void BackgroundCompleted()
            {
                Create("dog", "cat", "fish", "dog");
                _asyncTaggerSource.SetBackgroundFunc(span => TestUtils.GetDogTags(span));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();

                // The background request is now complete and it's posted to the UI thread.  Create a
                // new request on a new snapshot.  This will supercede the existing request
                _textBuffer.Replace(new Span(0, 0), "big ");
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.IsSome());
                var tokenSource = _asyncTagger.AsyncBackgroundRequestData.Value.CancellationTokenSource;

                // The background will try to post twice (once for progress and the other for complete)
                for (var i = 0; i < 2; i++)
                {
                    TestableSynchronizationContext.RunOne();
                    Assert.True(_asyncTagger.AsyncBackgroundRequestData.IsSome());
                    Assert.Equal(tokenSource, _asyncTagger.AsyncBackgroundRequestData.Value.CancellationTokenSource);
                }

                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();
                TestableSynchronizationContext.RunAll();
            }
Example #2
0
            public void PrioritizeVisibleLines()
            {
                CreateWithView("dog", "cat", "dog", "bear");
                _mockFactory.SetVisibleLineRange(_mockTextView, _textBuffer.GetLineRange(2));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();

                // The visible lines will finish first and post.  Let only this one go through
                TestableSynchronizationContext.RunOne();
                var tags = _asyncTagger.GetTags(_textBuffer.GetExtent());

                Assert.Equal(
                    new[] { _textBuffer.GetLineSpan(2, 3) },
                    tags.Select(x => x.Span));
                WaitForBackgroundToComplete();
            }