private static async Task TestAsync(string codeWithMarker) { using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromLinesAsync(codeWithMarker)) { var commentTokens = new TodoCommentTokens(); var provider = new TodoCommentIncrementalAnalyzerProvider(commentTokens); var worker = (TodoCommentIncrementalAnalyzer)provider.CreateIncrementalAnalyzer(workspace); var document = workspace.Documents.First(); var documentId = document.Id; var reasons = new InvocationReasons(PredefinedInvocationReasons.DocumentAdded); worker.AnalyzeSyntaxAsync(workspace.CurrentSolution.GetDocument(documentId), CancellationToken.None).Wait(); var todoLists = worker.GetItems_TestingOnly(documentId); var expectedLists = document.SelectedSpans; Assert.Equal(todoLists.Length, expectedLists.Count); for (int i = 0; i < todoLists.Length; i++) { var todo = todoLists[i]; var span = expectedLists[i]; var line = document.InitialTextSnapshot.GetLineFromPosition(span.Start); var text = document.InitialTextSnapshot.GetText(span.ToSpan()); Assert.Equal(todo.MappedLine, line.LineNumber); Assert.Equal(todo.MappedColumn, span.Start - line.Start); Assert.Equal(todo.Message, text); } } }
private static async Task TestAsync(string codeWithMarker, bool remote) { using var workspace = TestWorkspace.CreateCSharp(codeWithMarker, openDocuments: false); workspace.Options = workspace.Options.WithChangedOption(RemoteHostOptions.RemoteHostTest, remote); var commentTokens = new TodoCommentTokens(); var provider = new TodoCommentIncrementalAnalyzerProvider(commentTokens, Array.Empty <Lazy <IEventListener, EventListenerMetadata> >()); var worker = (TodoCommentIncrementalAnalyzer)provider.CreateIncrementalAnalyzer(workspace); var document = workspace.Documents.First(); var documentId = document.Id; var reasons = new InvocationReasons(PredefinedInvocationReasons.DocumentAdded); await worker.AnalyzeSyntaxAsync(workspace.CurrentSolution.GetDocument(documentId), InvocationReasons.Empty, CancellationToken.None); var todoLists = worker.GetItems_TestingOnly(documentId); var expectedLists = document.SelectedSpans; Assert.Equal(todoLists.Length, expectedLists.Count); for (var i = 0; i < todoLists.Length; i++) { var todo = todoLists[i]; var span = expectedLists[i]; var line = document.InitialTextSnapshot.GetLineFromPosition(span.Start); var text = document.InitialTextSnapshot.GetText(span.ToSpan()); Assert.Equal(todo.MappedLine, line.LineNumber); Assert.Equal(todo.MappedColumn, span.Start - line.Start); Assert.Equal(todo.Message, text); } }