public async Task TestWithMockDiagnosticService_TaggerProviderCreatedBeforeInitialDiagnosticsReported() { // This test produces diagnostics from a mock service so that we are disconnected from // all teh asynchrony of hte actual async analyzer engine. If this fails, then the // issue is almost certainly in the DiagnosticsSquiggleTaggerProvider code. If this // succeed, but other squiggle tests fail, then it is likely an issue with the // diagnostics engine not actually reporting all diagnostics properly. using (var workspace = await TestWorkspace.CreateCSharpAsync(new string[] { "class A { }" }, CSharpParseOptions.Default)) using (var wrapper = new DiagnosticTaggerWrapper(workspace)) { var asyncListener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener)); var diagnosticService = new MockDiagnosticService(workspace); var provider = new DiagnosticsSquiggleTaggerProvider( workspace.Services.GetService <IOptionService>(), diagnosticService, workspace.GetService <IForegroundNotificationService>(), listeners); // Create the tagger before the first diagnostic event has been fired. var tagger = provider.CreateTagger <IErrorTag>(workspace.Documents.First().GetTextBuffer()); // Now product hte first diagnostic and fire the events. var tree = await workspace.CurrentSolution.Projects.Single().Documents.Single().GetSyntaxTreeAsync(); var span = TextSpan.FromBounds(0, 5); diagnosticService.CreateDiagnosticAndFireEvents(Location.Create(tree, span)); using (var disposable = tagger as IDisposable) { await asyncListener.CreateWaitTask(); var snapshot = workspace.Documents.First().GetTextBuffer().CurrentSnapshot; var spans = tagger.GetTags(snapshot.GetSnapshotSpanCollection()).ToList(); Assert.Equal(1, spans.Count); Assert.Equal(span.ToSpan(), spans[0].Span.Span); } } }
public async Task TestWithMockDiagnosticService_TaggerProviderCreatedAfterInitialDiagnosticsReported() { // This test produces diagnostics from a mock service so that we are disconnected from // all the asynchrony of the actual async analyzer engine. If this fails, then the // issue is almost certainly in the DiagnosticsSquiggleTaggerProvider code. If this // succeed, but other squiggle tests fail, then it is likely an issue with the // diagnostics engine not actually reporting all diagnostics properly. using var workspace = TestWorkspace.CreateCSharp(new string[] { "class A { }" }, CSharpParseOptions.Default); using var wrapper = new DiagnosticTaggerWrapper <DiagnosticsSquiggleTaggerProvider>(workspace); var listenerProvider = workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>(); var diagnosticService = new MockDiagnosticService(workspace); var provider = new DiagnosticsSquiggleTaggerProvider( workspace.ExportProvider.GetExportedValue <IThreadingContext>(), diagnosticService, workspace.GetService <IForegroundNotificationService>(), listenerProvider); // Create and fire the diagnostic events before the tagger is even made. var tree = await workspace.CurrentSolution.Projects.Single().Documents.Single().GetRequiredSyntaxTreeAsync(CancellationToken.None); var span = TextSpan.FromBounds(0, 5); diagnosticService.CreateDiagnosticAndFireEvents(Location.Create(tree, span)); var tagger = provider.CreateTagger <IErrorTag>(workspace.Documents.First().GetTextBuffer()); using var disposable = tagger as IDisposable; await listenerProvider.GetWaiter(FeatureAttribute.DiagnosticService).ExpeditedWaitAsync(); await listenerProvider.GetWaiter(FeatureAttribute.ErrorSquiggles).ExpeditedWaitAsync(); var snapshot = workspace.Documents.First().GetTextBuffer().CurrentSnapshot; var spans = tagger.GetTags(snapshot.GetSnapshotSpanCollection()).ToList(); Assert.Equal(1, spans.Count); Assert.Equal(span.ToSpan(), spans[0].Span.Span); }