Ejemplo n.º 1
0
        public async Task LargeNumberOfSpans()
        {
            using (var workspace = TestWorkspace.CreateCSharp(@"class Program
{
    void M()
    {
        int z = 0;
        z = z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z;
    }
}"))
            {
                List <ITagSpan <TestTag> > tagProducer(SnapshotSpan span, CancellationToken cancellationToken)
                {
                    return(new List <ITagSpan <TestTag> >()
                    {
                        new TagSpan <TestTag>(span, new TestTag())
                    });
                }

                var asyncListener = new TaggerOperationListener();

                WpfTestCase.RequireWpfFact($"{nameof(AsynchronousTaggerTests)}.{nameof(LargeNumberOfSpans)} creates asynchronous taggers");

                var notificationService = workspace.GetService <IForegroundNotificationService>();

                var eventSource    = CreateEventSource();
                var taggerProvider = new TestTaggerProvider(
                    tagProducer,
                    eventSource,
                    workspace,
                    asyncListener,
                    notificationService);

                var document   = workspace.Documents.First();
                var textBuffer = document.TextBuffer;
                var snapshot   = textBuffer.CurrentSnapshot;
                var tagger     = taggerProvider.CreateTagger <TestTag>(textBuffer);

                using (IDisposable disposable = (IDisposable)tagger)
                {
                    var spans         = Enumerable.Range(0, 101).Select(i => new Span(i * 4, 1));
                    var snapshotSpans = new NormalizedSnapshotSpanCollection(snapshot, spans);

                    eventSource.SendUpdateEvent();

                    await asyncListener.CreateWaitTask();

                    var tags = tagger.GetTags(snapshotSpans);

                    Assert.Equal(1, tags.Count());
                }
            }
        }
Ejemplo n.º 2
0
 public OptionViewModelTests()
 {
     WpfTestCase.RequireWpfFact("Tests create WPF ViewModels and updates previews with them");
 }
Ejemplo n.º 3
0
        public async Task TestPreviewDiagnosticTaggerInPreviewPane()
        {
            using (var workspace = TestWorkspace.CreateCSharp("class { }", exportProvider: EditorServicesUtil.ExportProvider))
            {
                // set up listener to wait until diagnostic finish running
                var diagnosticService = workspace.ExportProvider.GetExportedValue <IDiagnosticService>() as DiagnosticService;

                // no easy way to setup waiter. kind of hacky way to setup waiter
                var source     = new CancellationTokenSource();
                var taskSource = new TaskCompletionSource <DiagnosticsUpdatedArgs>();
                diagnosticService.DiagnosticsUpdated += (s, a) =>
                {
                    source.Cancel();

                    source = new CancellationTokenSource();
                    var cancellationToken = source.Token;
                    Task.Delay(2000, cancellationToken).ContinueWith(t => taskSource.TrySetResult(a), CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);
                };

                var hostDocument = workspace.Projects.First().Documents.First();

                // make a change to remove squiggle
                var oldDocument = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                var oldText     = oldDocument.GetTextAsync().Result;

                var newDocument = oldDocument.WithText(oldText.WithChanges(new TextChange(new TextSpan(0, oldText.Length), "class C { }")));

                // create a diff view
                WpfTestCase.RequireWpfFact($"{nameof(TestPreviewDiagnosticTaggerInPreviewPane)} creates a {nameof(DifferenceViewerPreview)}");

                var previewFactoryService = workspace.ExportProvider.GetExportedValue <IPreviewFactoryService>();
                using (var diffView = (DifferenceViewerPreview)(await previewFactoryService.CreateChangedDocumentPreviewViewAsync(oldDocument, newDocument, CancellationToken.None)))
                {
                    var foregroundService = workspace.GetService <IForegroundNotificationService>();

                    var listenerProvider = new AsynchronousOperationListenerProvider();

                    // set up tagger for both buffers
                    var leftBuffer   = diffView.Viewer.LeftView.BufferGraph.GetTextBuffers(t => t.ContentType.IsOfType(ContentTypeNames.CSharpContentType)).First();
                    var leftProvider = new DiagnosticsSquiggleTaggerProvider(diagnosticService, foregroundService, listenerProvider);
                    var leftTagger   = leftProvider.CreateTagger <IErrorTag>(leftBuffer);
                    using (var leftDisposable = leftTagger as IDisposable)
                    {
                        var rightBuffer   = diffView.Viewer.RightView.BufferGraph.GetTextBuffers(t => t.ContentType.IsOfType(ContentTypeNames.CSharpContentType)).First();
                        var rightProvider = new DiagnosticsSquiggleTaggerProvider(diagnosticService, foregroundService, listenerProvider);
                        var rightTagger   = rightProvider.CreateTagger <IErrorTag>(rightBuffer);
                        using (var rightDisposable = rightTagger as IDisposable)
                        {
                            // wait up to 20 seconds for diagnostics
                            taskSource.Task.Wait(20000);
                            if (!taskSource.Task.IsCompleted)
                            {
                                // something is wrong
                                FatalError.Report(new System.Exception("not finished after 20 seconds"));
                            }

                            // wait taggers
                            await listenerProvider.GetWaiter(FeatureAttribute.ErrorSquiggles).CreateWaitTask();

                            // check left buffer
                            var leftSnapshot = leftBuffer.CurrentSnapshot;
                            var leftSpans    = leftTagger.GetTags(leftSnapshot.GetSnapshotSpanCollection()).ToList();
                            Assert.Equal(1, leftSpans.Count);

                            // check right buffer
                            var rightSnapshot = rightBuffer.CurrentSnapshot;
                            var rightSpans    = rightTagger.GetTags(rightSnapshot.GetSnapshotSpanCollection()).ToList();
                            Assert.Equal(0, rightSpans.Count);
                        }
                    }
                }
            }
        }