Prerequisites
Summary
In Visual Studio Code with the PowerShell extension installed, placing the cursor inside a param(...) block in or next to a parameter (variable) declaration and calling Find-Ast -AtCursor doesn't recognize the cursor location as a System.Management.Automation.Language.ParameterAst instance and instead returns the entire script (System.Management.Automation.Language.NamedBlockAst)
It currently only works in inline parameter declarations of functions.
PowerShell Version
Editor Version
Visual Studio Code 1.85.1
PowerShell Editor Services Version
Steps to Reproduce
- Using the PIC (PowerShell Integrated Console) in Visual Studio code with
psedit $PROFILE, add the following code to $PROFILE (and ensure that profile loading is enabled):
function Rename-Variable {
param($Context)
$variable = Find-Ast -AtCursor
$variable.GetType().Fullname | Write-Verbose -Verbose
}
- Then add F2 as a keybinding, via
keybindings.json:
{
"key": "F2",
"command": "PowerShell.InvokeRegisteredEditorCommand",
"args": {
"commandName": "Rename-Variable"
},
"when": "editorLangId == 'powershell' && editorTextFocus"
}
- Start a new session, and create a PowerShell script file with the following content:
- Place the cursor in the middle of
$Foo and press F2
You should see System.Management.Automation.Language.ParameterAst, but currently get System.Management.Automation.Language.NamedBlockAst
Visuals
Logs
No response
Prerequisites
Summary
In Visual Studio Code with the PowerShell extension installed, placing the cursor inside a
param(...)block in or next to a parameter (variable) declaration and callingFind-Ast -AtCursordoesn't recognize the cursor location as aSystem.Management.Automation.Language.ParameterAstinstance and instead returns the entire script (System.Management.Automation.Language.NamedBlockAst)It currently only works in inline parameter declarations of functions.
PowerShell Version
PowerShell 7.4.0Editor Version
Visual Studio Code 1.85.1PowerShell Editor Services Version
3.13.0Steps to Reproduce
psedit $PROFILE, add the following code to$PROFILE(and ensure that profile loading is enabled):keybindings.json:{ "key": "F2", "command": "PowerShell.InvokeRegisteredEditorCommand", "args": { "commandName": "Rename-Variable" }, "when": "editorLangId == 'powershell' && editorTextFocus" }$Fooand press F2You should see
System.Management.Automation.Language.ParameterAst, but currently getSystem.Management.Automation.Language.NamedBlockAstVisuals
Logs
No response