Preserve splat sigils during variable rename#2325
Conversation
|
@andyleejordan small fix, should be an easy approve. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a refactoring bug in PowerShell Editor Services' Rename Symbol feature. Previously, renaming a variable rewrote splatted references (e.g. @SplatProcessss in Start-Process @SplatProcessss) using the $ sigil instead of @, producing invalid PowerShell. The fix selects the correct sigil based on whether the VariableExpressionAst is splatted, and adds regression coverage.
Changes:
- In
RenameService.GetRenameVariableEdit, emit@NewNamefor splatted variable references and keep$NewNamefor normal references, using the existingVariableExpressionAst.Splattedflag. - Add a before/after fixture pair (
VariableSplattedReference.ps1/VariableSplattedReferenceRenamed.ps1) exercising a hashtable assignment plus aStart-Process @...splat invocation. - Register the new fixture in the shared variable rename test cases so it is verified end-to-end.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/PowerShellEditorServices/Services/TextDocument/RenameService.cs |
Picks @ vs $ sigil based on var.Splatted, following the existing char + NewName concatenation pattern. |
test/.../Refactoring/Variables/VariableSplattedReference.ps1 |
New input fixture containing a splat assignment and splat invocation. |
test/.../Refactoring/Variables/VariableSplattedReferenceRenamed.ps1 |
Expected output fixture after renaming to Renamed, preserving the @ sigil on the invocation. |
test/.../Refactoring/Variables/_RefactorVariableTestCases.cs |
Registers the new fixture (Line 1, Column 1) so the rename round-trip is asserted. |
The change is minimal, follows the existing conditional-sigil concatenation style already used for $ and -, and is correctly covered by the new fixtures (the harness renames $SplatProcessss to the default Renamed and compares against the Renamed.ps1 fixture). I found no correctness, naming, or coverage issues.
Rename Symbol was rewriting splatted variable references from
@nameto$namewhen renaming a variable, producing invalid refactoring output for splat invocations. This updates variable rename handling so splat references keep their@sigil.Rename behavior
RenameServiceto emit@NewNameforVariableExpressionAstnodes marked as splatted, while preserving existing$NewNamebehavior for normal variable references.Regression coverage
Start-Process @SplatProcessss.Result
Renaming
SplatProcesssstoSplatProcessnow yields: