Skip to content

Commit dbd5dfc

Browse files
authored
fix: preserve splat sigil during rename
1 parent 4ff28dc commit dbd5dfc

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/PowerShellEditorServices/Services/TextDocument/RenameService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private TextEdit GetRenameVariableEdit(Ast ast)
472472
? throw new HandlerErrorException($"${NewName} is not a valid variable name.")
473473
: new TextEdit
474474
{
475-
NewText = '$' + NewName,
475+
NewText = (var.Splatted ? '@' : '$') + NewName,
476476
Range = new ScriptExtentAdapter(var.Extent)
477477
},
478478
StringConstantExpressionAst stringAst => !IsValidVariableName(NewName)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$SplatProcessss = @{
2+
FilePath = 'C:\Windows\system32\cmd.exe'
3+
}
4+
5+
Start-Process @SplatProcessss
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$Renamed = @{
2+
FilePath = 'C:\Windows\system32\cmd.exe'
3+
}
4+
5+
Start-Process @Renamed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static class RefactorVariableTestCases
3232
new ("VariableRedefinition.ps1", Line: 1, Column: 1),
3333
new ("VariableScriptWithParamBlock.ps1", Line: 1, Column: 30),
3434
new ("VariableSimpleFunctionParameter.ps1", Line: 6, Column: 9),
35+
new ("VariableSplattedReference.ps1", Line: 1, Column: 1),
3536
new ("VariableusedInWhileLoop.ps1", Line: 2, Column: 5),
3637
new ("VariableWithinCommandAstScriptBlock.ps1", Line: 3, Column: 75),
3738
new ("VariableWithinForeachObject.ps1", Line: 2, Column: 1),

0 commit comments

Comments
 (0)