public async Task CrefCompletionSpeculatesOutsideTrivia() { var text = @" /// <see cref=""$$ class C { }"; var exportProvider = MinimalTestExportProvider.CreateExportProvider(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(PickySemanticFactsService))); using (var workspace = await TestWorkspace.CreateAsync(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, exportProvider)) { // This test uses MEF to compose in an ISyntaxFactsService that // asserts it isn't asked to speculate on nodes inside documentation trivia. // This verifies that the provider is asking for a speculative SemanticModel // by walking to the node the documentation is attached to. var provider = new CrefCompletionProvider(); var hostDocument = workspace.DocumentWithCursor; var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); var completionList = await GetCompletionListAsync(provider, document, hostDocument.CursorPosition.Value, CompletionTriggerInfo.CreateInvokeCompletionTriggerInfo()); } }
public async Task CrefCompletionSpeculatesOutsideTrivia() { var text = @" /// <see cref=""$$ class C { }"; using (var workspace = await TestWorkspace.CreateAsync(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text })) { var called = false; var provider = new CrefCompletionProvider(testSpeculativeNodeCallbackOpt: n => { // asserts that we aren't be asked speculate on nodes inside documentation trivia. // This verifies that the provider is asking for a speculative SemanticModel // by walking to the node the documentation is attached to. called = true; var parent = n.GetAncestor<DocumentationCommentTriviaSyntax>(); Assert.Null(parent); }); var hostDocument = workspace.DocumentWithCursor; var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); var service = CreateCompletionService(workspace, ImmutableArray.Create<CompletionProvider>(provider)); var completionList = await GetCompletionListAsync(service, document, hostDocument.CursorPosition.Value, CompletionTrigger.Default); Assert.True(called); } }