diff --git a/src/EditorFeatures/CSharpTest/CodeActions/IntroduceParameter/IntroduceParameterTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/IntroduceParameter/IntroduceParameterTests.cs index fc3e13daa81cd..05a41da7fe725 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/IntroduceParameter/IntroduceParameterTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/IntroduceParameter/IntroduceParameterTests.cs @@ -1932,5 +1932,62 @@ public Program(int x) "; await TestInRegularAndScriptAsync(code, expected, 0); } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceParameter)] + public async Task TestIntroduceParameterOnParameter() + { + var code = +@" +using System; + +class Program +{ + public static void Main(string[] args) + { + Console.WriteLine([|args|]); + } +} +"; + + await TestMissingInRegularAndScriptAsync(code); + } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceParameter)] + public async Task TestIntroduceParameterOnExpressionContainingParameter() + { + var code = +@" +public class C +{ + public void M(string s) + { + localFunction(); + + void localFunction() + { + _ = [|s|].ToString(); + } + } +} +"; + + var expected = +@" +public class C +{ + public void M(string s) + { + localFunction(s); + + void localFunction(string s) + { + _ = {|Rename:s|}.ToString(); + } + } +} +"; + + await TestInRegularAndScriptAsync(code, expected, 0); + } } } diff --git a/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceParameterService.cs b/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceParameterService.cs index 581c51d514e80..f874b000e3696 100644 --- a/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceParameterService.cs +++ b/src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceParameterService.cs @@ -97,6 +97,12 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex return; } + var expressionSymbol = semanticModel.GetSymbolInfo(expression, cancellationToken).Symbol; + if (expressionSymbol is IParameterSymbol parameterSymbol && parameterSymbol.ContainingSymbol.Equals(containingSymbol)) + { + return; + } + // Code actions for trampoline and overloads will not be offered if the method is a constructor. // Code actions for overloads will not be offered if the method if the method is a local function. var methodKind = methodSymbol.MethodKind;