PowerShell / PowerShell/PowerShellEditorServices
`Find-Ast -AtCursor` doesn't work inside `param(...)` blocks.
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 767
- フォーク
- 266
- 平均マージ
- 3日 16時間
- マージ済み PR(30日)
- 1
説明
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
$Fooand press F2
You should see System.Management.Automation.Language.ParameterAst, but currently get System.Management.Automation.Language.NamedBlockAst
Visuals
Logs
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
PowerShell Integrated Console から Find-Ast -AtCursor を使用して、param(...) ブロック内の $Foo にカーソルを置いた状態で問題を再現します。コマンドによるカーソル位置の処理を追跡し、結果が NamedBlockAst ではなく System.Management.Automation.Language.ParameterAst であることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- powershell, vscode
- 領域
- developer-experience, tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100