PowerShell / PowerShell/PowerShellEditorServices

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

Đang mở
#2,120 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Area-psEditor Issue-Bug
Ngôn ngữ chính
C#
Star
767
Fork
266
Merge trung bình
3 ngày 16 giờ
Pull request đã merge (30 ngày)
1

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện vấn đề bằng cách sử dụng Find-Ast -AtCursor từ PowerShell Integrated Console, với con trỏ nằm bên trong $Foo trong một khối param(...). Theo dõi cách lệnh xử lý vị trí con trỏ và xác minh rằng kết quả là System.Management.Automation.Language.ParameterAst thay vì NamedBlockAst.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell, vscode
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.