Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Introduce Parameter Crash #72191

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private static bool IsValidExpression(SyntaxNode expression, ISyntaxFactsService
using var actionsBuilder = TemporaryArray<CodeAction>.Empty;
using var actionsBuilderAllOccurrences = TemporaryArray<CodeAction>.Empty;
var syntaxFacts = document.GetRequiredLanguageService<ISyntaxFactsService>();
var methodCallSites = await FindCallSitesAsync(document, methodSymbol, cancellationToken).ConfigureAwait(false);

if (!containsClassExpression)
{
Expand All @@ -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<TObjectCreationExpressionSyntax>().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)
{
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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.
/// </summary>
private async Task<Solution> IntroduceParameterAsync(Document originalDocument, TExpressionSyntax expression,
IMethodSymbol methodSymbol, SyntaxNode containingMethod, bool allOccurrences, IntroduceParameterCodeActionKind selectedCodeAction,
IMethodSymbol methodSymbol, SyntaxNode containingMethod, Dictionary<Document, List<TExpressionSyntax>> 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);
Expand Down
Loading