You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I rename a variable in one place, I want to ensure all references to that variable are renamed that are in the same scope. Basically, I want to ensure when a rename a variable that anything that might be depending on that name is renamed as well in the same script. Here's an example:
Reacted by Brian Ojeda, Matt McNabb, Dominique Clijsters, Matthew Pearon, regs01, Przemysław Kłys, Jeff Lewis, Vladimir, dlebu, Jakub Čábera and 51 more
I think you can do this already by 1) selecting the variable, 2) use the command editor.action.selectHighlights (default key mapping is Ctrl+Shift+L), then 3) type the replacement name.
Reacted by Skyler Brill Sedat, Aaron Steele, Simona Chiosa and soulflyman
Bill Stewart (@Bill-Stewart) You're somewhat correct. Adam Bertram (@adbertram) is referring to the Rename Symbol (F2) command. It will smartly update the symbol (e.g. variable, class, functions, etc.) versus a blind change of all occurrence of a word.
Example:
# get some objects to work with
$something = (Get-Something);
$anotherthing = (Get-AnotherThing);
# set some value from the first object
$someValue1 = $something.SomeValue;
$someValue2 = $something.SomeValue;
# set another one from the other object
$somevalue3 = $anotherthing.SomeValue;
Basic Explanations:
With Symbol Rename, the editor will understand that both occurrence SomeValue from $something.SomeValue are the same but the one from $anotherthing.SomeValue is not. So the Symbol Rename command of SomeValue property on the $something object will only make two changes even though there are at least 3 occurrence of "somevalue" (actually there are 6).
Reacted by Adam Bertram, Dominique Clijsters, Heinrich Ulbricht, Christian Seidlitz, Leonardo Comerci and Ariel Silverman
Well, I interpreted the OP's request as variables rather than object members. I wouldn't mind this if performance is good. (As noted, we can already change variables pretty easily.)
Plus one on the request from Adam Bertram (@adbertram). The key here is that the token rename should be scope-aware in PowerShell. We've been doing this in ISESteroids for a while:
Reacted by Brian Ojeda, Igor and Christian Seidlitz
Because of PowerShell's dynamic scoping that is hard to get right i.e. infer scripter intent. In the example above, I'd argue that renaming $Var1 on line 2 shouldn't rename the variable on line 5. Line 2 should be considered a "new" $Var1 variable because of PowerShell's "copy on write" behavior.
Now if line 2 was $script:Var1 = ... then it would be obvious that line 5 should be renamed.
However, with dynamic scopes you don't know until runtime which scope a variable is defined in if it isn't defined in the local scope. That makes it hard to ensure correctness with this feature request IMO.
Keith Hill (@rkeithhill) you're right about the intention of the example above. Sounds like it's difficult to implement - still would be really nice to have. Wonder how it's achieved in ISE Steroids?
The question isn't whether it's possible (it is), it's whether the change we make is correct in terms of how PowerShell's variable scoping works. Right now our symbol renaming is primitive but once we start doing it the "right" way, it will adhere as well as it can to PowerShell's scoping rules.
On Tue, Dec 6, 2016 at 8:54 AM, David Wilson ***@***.***> wrote:
The question isn't whether it's possible (it is), it's whether the change
we make is correct in terms of how PowerShell's variable scoping works.
Right now our symbol renaming is primitive but once we start doing it the
"right" way, it will adhere as well as it can to PowerShell's scoping rules.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#261 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEG3-nH5Z8DLHCGTTs5RFqVOrV2DkBxZks5rFXcWgaJpZM4JtI2E>
.
Open VSCode, hit F1, and type "VSIX" and hit enter
Browse for the vsix file
Reload VSCode
Open a .ps1 file on disk (unsaved/untitled currently unsupported) and hit F2. You'll get a popup asking you to opt in, then you can try out renaming functions/providers/symbols
Capture.mp4
Reacted by Michael Klement, Ajay Mehta, Cristi Paraschiv, Olav Rønnestad Birkeland, Jon Ege Ronnenberg and nicolasr75
Reacted by Trysten, Gilbert Sanchez and Cristi Paraschiv
Awesome! It even takes splatting into account (though it is erroneously adding a $ before the parameter name).
Regarding the creation of an alias attribute when renaming a parameter, I don't think it should be enabled by default. I'd imagine most people will primarily use it in the initial development phase where breaking changes are not a concern so it just gets in the way.
MartinGC94 that's a fair point, it'll be a toggleable setting either way.
We are building a test suite of supported scenarios, I'm currently refactoring it to be LSP-only so that it will be portable to neovim and whatnot. Once that's done I may recruit you if you have some time to help us refine the AST visitors to help with more edge cases we pick up.
Stéphane BARIZIEN (@sba923) I'm currently doing a pretty major rewrite/refactor on another branch, the vsix I provided should be fine but I should have a better version by net week.
Justin Grote (@JustinGrote) I have been using your extension Build 2025-03-01 today for some hours within a single .ps1 and it worked without any issues. Thanks! vscode: 1.102.2, linux
Jon Ege Ronnenberg (@dotnetCarpenter) glad to hear it! The current status is that I realized there is some overlap in AST code between this and our "Find All References" provider, and I would like to unify the logic between the two so that they consistently find references in the same manner. That's going to take some work and I have some tasks I want to finish ahead of it, but it's still very high on my personal VSCode "to-do" list
Reacted by Olav Rønnestad Birkeland and Christoph Wolf
Jon Ege Ronnenberg (@dotnetCarpenter) in this case it's a string (powershell implicitly makes it 'Invoke-CustomFunction'), not a function name, so the symbols don't match in the AST as it isn't a valid reference. We can look at possiblying doing this for export-modulemember but it is still working "as designed"
Ahh, I see. It would be nice if there was a special case for function references after Export-ModuleMember -Function … for modules that export a lot of functions IMHO.
Activity
Bill-Stewart commentedon Sep 21, 2016
I think you can do this already by 1) selecting the variable, 2) use the command
editor.action.selectHighlights(default key mapping is Ctrl+Shift+L), then 3) type the replacement name.sgtoj commentedon Sep 23, 2016
Bill Stewart (@Bill-Stewart) You're somewhat correct. Adam Bertram (@adbertram) is referring to the Rename Symbol (F2) command. It will smartly update the symbol (e.g. variable, class, functions, etc.) versus a blind change of all occurrence of a word.
Example:
Basic Explanations:
With Symbol Rename, the editor will understand that both occurrence
SomeValuefrom$something.SomeValueare the same but the one from$anotherthing.SomeValueis not. So the Symbol Rename command ofSomeValueproperty on the$somethingobject will only make two changes even though there are at least 3 occurrence of "somevalue" (actually there are 6).Bill-Stewart commentedon Sep 23, 2016
Well, I interpreted the OP's request as variables rather than object members. I wouldn't mind this if performance is good. (As noted, we can already change variables pretty easily.)
mattmcnabb commentedon Dec 5, 2016
Plus one on the request from Adam Bertram (@adbertram). The key here is that the token rename should be scope-aware in PowerShell. We've been doing this in ISESteroids for a while:
rkeithhill commentedon Dec 5, 2016
Because of PowerShell's dynamic scoping that is hard to get right i.e. infer scripter intent. In the example above, I'd argue that renaming
$Var1on line 2 shouldn't rename the variable on line 5. Line 2 should be considered a "new" $Var1 variable because of PowerShell's "copy on write" behavior.Now if line 2 was
$script:Var1 = ...then it would be obvious that line 5 should be renamed.However, with dynamic scopes you don't know until runtime which scope a variable is defined in if it isn't defined in the local scope. That makes it hard to ensure correctness with this feature request IMO.
mattmcnabb commentedon Dec 6, 2016
Keith Hill (@rkeithhill) you're right about the intention of the example above. Sounds like it's difficult to implement - still would be really nice to have. Wonder how it's achieved in ISE Steroids?
adbertram commentedon Dec 6, 2016
daviwil commentedon Dec 6, 2016
The question isn't whether it's possible (it is), it's whether the change we make is correct in terms of how PowerShell's variable scoping works. Right now our symbol renaming is primitive but once we start doing it the "right" way, it will adhere as well as it can to PowerShell's scoping rules.
adbertram commentedon Dec 6, 2016
daviwil commentedon Dec 6, 2016
Nope ;) You will get a new release with some other shiny features, though.
clijsters commentedon Mar 21, 2017
Would be a great feature!
ajansveld commentedon Aug 16, 2017
Already a fan of vscode but this would really take it to the next level.
johntiger1 commentedon Dec 6, 2017
Also would like this feature
30 remaining items
Omzig commentedon Mar 21, 2024
can we bump this somehow and get vscode to F2 (rename) a powershell symbol?
SeidChr commentedon Mar 21, 2024
*bump
JustinGrote commentedon Sep 12, 2024
EDIT: New Build 2025-03-01
Progress is happening! Here is a new alpha preview build of the functionality if you want to try it out.
powershell-2025.99.0-renameAlpha.zip
.zipto.vsixOpen a .ps1 file on disk (unsaved/untitled currently unsupported) and hit F2. You'll get a popup asking you to opt in, then you can try out renaming functions/providers/symbols
Capture.mp4
MartinGC94 commentedon Sep 12, 2024
Awesome! It even takes splatting into account (though it is erroneously adding a
$before the parameter name).Regarding the creation of an alias attribute when renaming a parameter, I don't think it should be enabled by default. I'd imagine most people will primarily use it in the initial development phase where breaking changes are not a concern so it just gets in the way.
JustinGrote commentedon Sep 12, 2024
MartinGC94 that's a fair point, it'll be a toggleable setting either way.
We are building a test suite of supported scenarios, I'm currently refactoring it to be LSP-only so that it will be portable to neovim and whatnot. Once that's done I may recruit you if you have some time to help us refine the AST visitors to help with more edge cases we pick up.
sba923 commentedon Sep 20, 2024
F2 gets me nothing but
Unable to write to User Settings because powershell.renameSymbol.acceptRenameDisclaimer is not a registered configuration.JustinGrote commentedon Sep 20, 2024
Stéphane BARIZIEN (@sba923) I'm currently doing a pretty major rewrite/refactor on another branch, the vsix I provided should be fine but I should have a better version by net week.
JustinGrote commentedon Mar 2, 2025
I'm working on this again, just rebased it with the latest changes. See the previous post for the newest build
dotnetCarpenter commentedon Jul 29, 2025
Justin Grote (@JustinGrote) I have been using your extension Build 2025-03-01 today for some hours within a single .ps1 and it worked without any issues. Thanks! vscode: 1.102.2, linux
JustinGrote commentedon Jul 29, 2025
Jon Ege Ronnenberg (@dotnetCarpenter) glad to hear it! The current status is that I realized there is some overlap in AST code between this and our "Find All References" provider, and I would like to unify the logic between the two so that they consistently find references in the same manner. That's going to take some work and I have some tasks I want to finish ahead of it, but it's still very high on my personal VSCode "to-do" list
dotnetCarpenter commentedon Jul 30, 2025
Justin Grote (@JustinGrote) I found a single case where your rename extension does not seem to work.
Steps to reproduce
Invoke-CustomFunctionExport-ModuleMember -Function Invoke-CustomFunctiondoes not change name.JustinGrote commentedon Jul 31, 2025
Jon Ege Ronnenberg (@dotnetCarpenter) in this case it's a string (powershell implicitly makes it 'Invoke-CustomFunction'), not a function name, so the symbols don't match in the AST as it isn't a valid reference. We can look at possiblying doing this for export-modulemember but it is still working "as designed"
dotnetCarpenter commentedon Aug 1, 2025
Ahh, I see. It would be nice if there was a special case for function references after
Export-ModuleMember -Function …for modules that export a lot of functions IMHO.