Skip to content

Commit 763dbf8

Browse files
Razmo99JustinGrote
authored andcommitted
Added test case for simple function parameter rename, added clause for is target is within a parameter block within a function to solve
1 parent 1714312 commit 763dbf8

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

Diff for: src/PowerShellEditorServices/Services/PowerShell/Refactoring/IterativeVariableVisitor.cs

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public static Ast GetVariableTopAssignment(int StartLineNumber, int StartColumnN
8282
}
8383

8484
Ast TargetParent = GetAstParentScope(node);
85+
86+
// Is the Variable sitting within a ParameterBlockAst that is within a Function Definition
87+
// If so we don't need to look further as this is most likley the AssignmentStatement we are looking for
88+
Ast paramParent = Utilities.GetAstParentOfType(node, typeof(ParamBlockAst));
89+
if (TargetParent is FunctionDefinitionAst && null != paramParent)
90+
{
91+
return node;
92+
}
93+
8594
// Find all variables and parameter assignments with the same name before
8695
// The node found above
8796
List<VariableExpressionAst> VariableAssignments = ScriptAst.FindAll(ast =>

Diff for: test/PowerShellEditorServices.Test.Shared/Refactoring/Variables/RefactorVariablesData.cs

+7
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,12 @@ internal static class RenameVariableData
170170
Line = 3,
171171
RenameTo = "Renamed"
172172
};
173+
public static readonly RenameSymbolParams VariableSimpleFunctionParameter = new()
174+
{
175+
FileName = "VariableSimpleFunctionParameter.ps1",
176+
Column = 9,
177+
Line = 6,
178+
RenameTo = "Renamed"
179+
};
173180
}
174181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$x = 1..10
2+
3+
function testing_files {
4+
5+
param (
6+
$x
7+
)
8+
write-host "Printing $x"
9+
}
10+
11+
foreach ($number in $x) {
12+
testing_files $number
13+
14+
function testing_files {
15+
write-host "------------------"
16+
}
17+
}
18+
testing_files "99"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$x = 1..10
2+
3+
function testing_files {
4+
5+
param (
6+
[Alias("x")]$Renamed
7+
)
8+
write-host "Printing $Renamed"
9+
}
10+
11+
foreach ($number in $x) {
12+
testing_files $number
13+
14+
function testing_files {
15+
write-host "------------------"
16+
}
17+
}
18+
testing_files "99"

0 commit comments

Comments
 (0)