PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
612 stars 207 forks source link

`Find-Ast -AtCursor` doesn't work inside `param(...)` blocks. #2120

Open mklement0 opened 6 months ago

mklement0 commented 6 months ago

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

PowerShell 7.4.0

Editor Version

Visual Studio Code 1.85.1

PowerShell Editor Services Version

3.13.0

Steps to Reproduce

function Rename-Variable {
  param($Context)

  $variable = Find-Ast -AtCursor
  $variable.GetType().Fullname | Write-Verbose -Verbose
}
{
  "key": "F2",
  "command": "PowerShell.InvokeRegisteredEditorCommand",
  "args": {
    "commandName": "Rename-Variable"
  },
  "when": "editorLangId == 'powershell' && editorTextFocus"
}
param(
  [string] $Foo
)

You should see System.Management.Automation.Language.ParameterAst, but currently get System.Management.Automation.Language.NamedBlockAst

Visuals

image

Logs

No response