diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs index cd061a5a1ec5c..01af453625d64 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SuggestionModeCompletionProviderTests.cs @@ -718,6 +718,17 @@ class C { await VerifyNotBuilderAsync(markup); } + [WorkItem(15443, "https://github.com/dotnet/roslyn/issues/15443")] + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] + public async Task NotBuilderWhenDelegateInferredRightOfDotInInvocation() + { + var markup = @" +class C { + Action a = Task.$$ +}"; + await VerifyNotBuilderAsync(markup); + } + private async Task VerifyNotBuilderAsync(string markup) { await VerifyWorkerAsync(markup, isBuilder: false); diff --git a/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs index 3d64d0ebddfb0..890389b9ffbc2 100644 --- a/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs @@ -152,10 +152,19 @@ private bool IsLambdaExpression(SemanticModel semanticModel, int position, Synta position = token.Parent.SpanStart; } + // In the following situation, the type inferrer will infer Task to support target type preselection + // Action a = Task.$$ + // We need to explicitly exclude invocation/member access from suggestion mode + var previousToken = token.GetPreviousTokenIfTouchingWord(position); + if (previousToken.IsKind(SyntaxKind.DotToken) && + previousToken.Parent.IsKind(SyntaxKind.SimpleMemberAccessExpression)) + { + return false; + } + // If we're an argument to a function with multiple overloads, // open the builder if any overload takes a delegate at our argument position var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken); - return inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType()); }