Skip to content

Preserve splat sigils during variable rename#2325

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/rename-service-settings
Open

Preserve splat sigils during variable rename#2325
Copilot wants to merge 2 commits into
mainfrom
copilot/rename-service-settings

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Rename Symbol was rewriting splatted variable references from @name to $name when renaming a variable, producing invalid refactoring output for splat invocations. This updates variable rename handling so splat references keep their @ sigil.

  • Rename behavior

    • Update RenameService to emit @NewName for VariableExpressionAst nodes marked as splatted, while preserving existing $NewName behavior for normal variable references.
  • Regression coverage

    • Add a focused refactoring fixture covering a hashtable assignment plus Start-Process @SplatProcessss.
    • Register the fixture in the shared variable rename test cases so the end-to-end rename output is verified.
  • Result

    • Renaming a splat variable now updates both the assignment and the invocation correctly.
$SplatProcessss = @{
    FilePath = 'C:\Windows\system32\cmd.exe'
}

Start-Process @SplatProcessss

Renaming SplatProcessss to SplatProcess now yields:

$SplatProcess = @{
    FilePath = 'C:\Windows\system32\cmd.exe'
}

Start-Process @SplatProcess

Copilot AI changed the title [WIP] Fix splatting variable change in service settings Preserve splat sigils during variable rename Jun 23, 2026
Copilot AI requested a review from JustinGrote June 23, 2026 15:56
@JustinGrote JustinGrote marked this pull request as ready for review June 23, 2026 16:01
@JustinGrote

Copy link
Copy Markdown
Collaborator

@andyleejordan small fix, should be an easy approve.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @NewName for splatted variable references and keep $NewName for normal references, using the existing VariableExpressionAst.Splatted flag.
  • Add a before/after fixture pair (VariableSplattedReference.ps1 / VariableSplattedReferenceRenamed.ps1) exercising a hashtable assignment plus a Start-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants