Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks done
mklement0 opened this issue Dec 23, 2023 · 0 comments
Open
6 tasks done

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

mklement0 opened this issue Dec 23, 2023 · 0 comments
Labels

Comments

@mklement0
Copy link

mklement0 commented Dec 23, 2023

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with PowerShell Editor Services itself and does not reproduce in a standalone PowerShell instance, and is not an issue with my editor.
  • I have verified that I am using the latest version of PowerShell Editor Services.
  • If this is a security issue, I have read the security issue reporting guidance.

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

  • 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:
param(
  [string] $Foo
)
  • 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

image

Logs

No response

@mklement0 mklement0 added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Dec 23, 2023
@mklement0 mklement0 changed the title Find-Module -AtCursor doesn't work in Find-Module -AtCursor doesn't work inside param(...) blocks. Dec 23, 2023
@SydneyhSmith SydneyhSmith changed the title Find-Module -AtCursor doesn't work inside param(...) blocks. Find-Ast -AtCursor doesn't work inside param(...) blocks. Feb 22, 2024
@SydneyhSmith SydneyhSmith added Area-psEditor and removed Needs: Triage Maintainer attention needed! labels Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants