diff --git a/src/Features/Core/Portable/IntroduceParameter/AbstractIntroduceParameterCodeRefactoringProvider.cs b/src/Features/Core/Portable/IntroduceParameter/AbstractIntroduceParameterCodeRefactoringProvider.cs index 461fbe1605a56..7ccd98283bdb5 100644 --- a/src/Features/Core/Portable/IntroduceParameter/AbstractIntroduceParameterCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/IntroduceParameter/AbstractIntroduceParameterCodeRefactoringProvider.cs @@ -148,6 +148,7 @@ private static bool IsValidExpression(SyntaxNode expression, ISyntaxFactsService using var actionsBuilder = TemporaryArray.Empty; using var actionsBuilderAllOccurrences = TemporaryArray.Empty; var syntaxFacts = document.GetRequiredLanguageService(); + var methodCallSites = await FindCallSitesAsync(document, methodSymbol, cancellationToken).ConfigureAwait(false); if (!containsClassExpression) { @@ -157,10 +158,14 @@ private static bool IsValidExpression(SyntaxNode expression, ISyntaxFactsService if (methodSymbol.MethodKind is not MethodKind.Constructor) { - actionsBuilder.Add(CreateNewCodeAction( - FeaturesResources.into_extracted_method_to_invoke_at_call_sites, allOccurrences: false, IntroduceParameterCodeActionKind.Trampoline)); - actionsBuilderAllOccurrences.Add(CreateNewCodeAction( - FeaturesResources.into_extracted_method_to_invoke_at_call_sites, allOccurrences: true, IntroduceParameterCodeActionKind.Trampoline)); + var containsObjectCreationReferences = methodCallSites.Values.Flatten().OfType().Any(); + if (!containsObjectCreationReferences) + { + actionsBuilder.Add(CreateNewCodeAction( + FeaturesResources.into_extracted_method_to_invoke_at_call_sites, allOccurrences: false, IntroduceParameterCodeActionKind.Trampoline)); + actionsBuilderAllOccurrences.Add(CreateNewCodeAction( + FeaturesResources.into_extracted_method_to_invoke_at_call_sites, allOccurrences: true, IntroduceParameterCodeActionKind.Trampoline)); + } if (methodSymbol.MethodKind is not MethodKind.LocalFunction) { @@ -178,7 +183,7 @@ CodeAction CreateNewCodeAction(string actionName, bool allOccurrences, Introduce { return CodeAction.Create( actionName, - cancellationToken => IntroduceParameterAsync(document, expression, methodSymbol, containingMethod, allOccurrences, selectedCodeAction, fallbackOptions, cancellationToken), + cancellationToken => IntroduceParameterAsync(document, expression, methodSymbol, containingMethod, methodCallSites, allOccurrences, selectedCodeAction, fallbackOptions, cancellationToken), actionName); } } @@ -229,11 +234,9 @@ CodeAction CreateNewCodeAction(string actionName, bool allOccurrences, Introduce /// Introduces a new parameter and refactors all the call sites based on the selected code action. /// private async Task IntroduceParameterAsync(Document originalDocument, TExpressionSyntax expression, - IMethodSymbol methodSymbol, SyntaxNode containingMethod, bool allOccurrences, IntroduceParameterCodeActionKind selectedCodeAction, + IMethodSymbol methodSymbol, SyntaxNode containingMethod, Dictionary> methodCallSites, bool allOccurrences, IntroduceParameterCodeActionKind selectedCodeAction, CodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { - var methodCallSites = await FindCallSitesAsync(originalDocument, methodSymbol, cancellationToken).ConfigureAwait(false); - var modifiedSolution = originalDocument.Project.Solution; var rewriter = new IntroduceParameterDocumentRewriter(this, originalDocument, expression, methodSymbol, containingMethod, selectedCodeAction, fallbackOptions, allOccurrences);