Skip to content

Commit ba07a82

Browse files
committed
Add Test case and more info
1 parent fb82b77 commit ba07a82

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ The focus of the rename support is on quick updates to variables or functions wi
152152
❌ Scoped variables (e.g. $SCRIPT:test) are not currently supported
153153
❌ Renaming a variable inside of a scriptblock that is used in unscoped operations like `Foreach-Parallel` or `Start-Job` and the variable is not defined within the scriptblock is not supported and can have unexpected results.
154154
❌ Scriptblocks part of an assignment are considered isolated scopes. For example `$a = 5; $x = {$a}; & $x` does not consider the two $a to be related, even though in execution this reference matches.
155+
❌ Scriptblocks that are part of a parameter are assumed to not be executing in a different runspace. For example, the renaming behavior will treat `ForEach-Object -Parallel {$x}` the same as `Foreach-Object {$x}` for purposes of finding scope definitions. To avoid unexpected renaming, define/redefine all your variables in the scriptblock using a param block.
156+
❌ A lot of the logic relies on the position of items, so for example, defining a variable in a `begin` block and placing it after a `process` block, while technically correct in PowerShell, will not rename as expected.
157+
❌ Similarly, defining a function, and having the function rely on a variable that is assigned outside the function and after the function definition, will not find the outer variable reference.
155158

156159
📄📄 Filing a Rename Issue
157160

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$x = 1
2+
function test {
3+
begin {
4+
$x = 5
5+
}
6+
process {
7+
$x
8+
}
9+
end {
10+
$x
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$x = 1
2+
function test {
3+
begin {
4+
$Renamed = 5
5+
}
6+
process {
7+
$Renamed
8+
}
9+
end {
10+
$Renamed
11+
}
12+
}

test/PowerShellEditorServices.Test.Shared/Refactoring/Variables/_RefactorVariableTestCases.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class RefactorVariableTestCases
1515
new ("VariableCommandParameter.ps1", Line: 10, Column: 10),
1616
new ("VariableCommandParameterSplatted.ps1", Line: 3, Column: 19 ),
1717
new ("VariableCommandParameterSplatted.ps1", Line: 21, Column: 12),
18+
new ("VariableDefinedInParamBlock.ps1", Line: 10, Column: 9),
1819
new ("VariableDotNotationFromInnerFunction.ps1", Line: 1, Column: 1),
1920
new ("VariableDotNotationFromInnerFunction.ps1", Line: 11, Column: 26),
2021
new ("VariableInForeachDuplicateAssignment.ps1", Line: 6, Column: 18),

0 commit comments

Comments
 (0)