PowerShell / PowerShell/PowerShellEditorServices

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

Offen
#2,120 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Area-psEditor Issue-Bug
Vorherrschende Sprache
C#
Sterne
767
Forks
266
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Problem mit Find-Ast -AtCursor aus der PowerShell Integrated Console, wobei sich der Cursor innerhalb von $Foo in einem param(...)-Block befindet. Verfolge die Verarbeitung der Cursorposition durch den Befehl und überprüfe, dass das Ergebnis System.Management.Automation.Language.ParameterAst statt NamedBlockAst ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell, vscode
Bereich
developer-experience, tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.