Skip to content

Commit fcedf8f

Browse files
committed
SkipChildren doesn't work for nested function situations. More tests fixed
1 parent 66d8782 commit fcedf8f

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

src/PowerShellEditorServices/Services/TextDocument/RenameService.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,8 @@ public AstVisitAction Visit(Ast ast)
240240
if (ShouldRename(ast))
241241
{
242242
Edits.Add(GetRenameFunctionEdit(ast));
243-
return AstVisitAction.Continue;
244-
}
245-
else
246-
{
247-
return AstVisitAction.SkipChildren;
248243
}
244+
return AstVisitAction.Continue;
249245

250246
// TODO: Is there a way we can know we are fully outside where the function might be referenced, and if so, call a AstVisitAction Abort as a perf optimization?
251247
}

test/PowerShellEditorServices.Test.Shared/Refactoring/Functions/FunctionInnerIsNestedRenamed.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function outer {
2-
function bar {
3-
Write-Host "Inside nested foo"
2+
function Renamed {
3+
Write-Host 'Inside nested foo'
44
}
5-
bar
5+
Renamed
66
}
77

88
function foo {

test/PowerShellEditorServices.Test.Shared/Refactoring/Functions/FunctionWithInnerFunction.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function OuterFunction {
22
function NewInnerFunction {
3-
Write-Host "This is the inner function"
3+
Write-Host 'This is the inner function'
44
}
55
NewInnerFunction
66
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function OuterFunction {
2-
function RenamedInnerFunction {
3-
Write-Host "This is the inner function"
2+
function Renamed {
3+
Write-Host 'This is the inner function'
44
}
5-
RenamedInnerFunction
5+
Renamed
66
}
77
OuterFunction

test/PowerShellEditorServices.Test.Shared/Refactoring/Functions/RefactorFunctionTestCases.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public class RefactorFunctionTestCases
1414
new("FunctionCmdlet.ps1", Line: 1, Column: 10 ),
1515
new("FunctionForeach.ps1", Line: 5, Column: 11 ),
1616
new("FunctionForeachObject.ps1", Line: 5, Column: 11 ),
17-
new("FunctionInnerIsNested.ps1", Line: 5, Column: 5 , "bar"),
17+
new("FunctionInnerIsNested.ps1", Line: 5, Column: 5 ),
1818
new("FunctionLoop.ps1", Line: 5, Column: 5 ),
1919
new("FunctionMultipleOccurrences.ps1", Line: 5, Column: 3 ),
2020
new("FunctionNestedRedefinition.ps1", Line: 13, Column: 15 ),
2121
new("FunctionOuterHasNestedFunction.ps1", Line: 2, Column: 15 ),
22-
new("FunctionSameName.ps1", Line: 3, Column: 14 , "RenamedSameNameFunction"),
22+
new("FunctionSameName.ps1", Line: 3, Column: 14 , "RenamedSameNameFunction"),
2323
new("FunctionScriptblock.ps1", Line: 5, Column: 5 ),
2424
new("FunctionsSingle.ps1", Line: 1, Column: 11 ),
25-
new("FunctionWithInnerFunction.ps1", Line: 5, Column: 5 , "RenamedInnerFunction"),
25+
new("FunctionWithInnerFunction.ps1", Line: 5, Column: 5 ),
2626
new("FunctionWithInternalCalls.ps1", Line: 3, Column: 6 ),
2727
];
2828
}

0 commit comments

Comments
 (0)