PowerShell / PowerShell/PowerShell
The Parser is handing out Internal objects like candy and (may be) poisoning children
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 55.5k
- Fork
- 8.5k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 88
Mô tả
Trying to write a ScriptAnalyzer rule, and needed to generate an Extent for the DiagnosticRecord which is slightly modified from the ones found in the AST object that are passed to me ...
Imagine my surprise when I tried to cast the .Extent on one of these AST objects to a System.Management.Automation.Language.ScriptExtent and got an exception saying PowerShell doesn't know how to convert a System.Management.Automation.Language.InternalScriptExtent to that.
So then I tried to just make one:
[System.Management.Automation.Language.ScriptExtent]::new(
$FunctionAst.Extent.StartScriptPosition,
$FunctionAst.Extent.EndScriptPosition)
Did you know that InternalScriptExtent.StartScriptPosition and EndScriptPosition are also internal classes? Of course! So now I get a giant wall of red which is best summarized as:
Cannot convert "InternalScriptPosition" to type "ScriptPosition"
All I wanted to do was increment the line numbers, so I had to write this:
# Because we can't just modify $comment.Extent:
# $comment.Extent.StartScriptPosition.LineNumber += $Extent.StartLineNumber -1
# We have to create a whole new ScriptExtent object:
$Extent = [System.Management.Automation.Language.ScriptExtent]::new(
[System.Management.Automation.Language.ScriptPosition]::new(
$FunctionAst.Extent.StartScriptPosition.File,
($FunctionAst.Extent.StartScriptPosition.LineNumber + $comment.Extent.StartScriptPosition.LineNumber - 1),
$FunctionAst.Extent.StartScriptPosition.ColumnNumber,
$comment.Extent.StartScriptPosition.Line,
$FunctionAst.Extent.StartScriptPosition.GetFullScript()),
[System.Management.Automation.Language.ScriptPosition]::new(
$FunctionAst.Extent.EndScriptPosition.File,
($FunctionAst.Extent.EndScriptPosition.LineNumber + $comment.Extent.EndScriptPosition.LineNumber - 1),
$FunctionAst.Extent.EndScriptPosition.ColumnNumber,
$comment.Extent.EndScriptPosition.Line,
$FunctionAst.Extent.EndScriptPosition.GetFullScript())
)
But I found the output of this has the StartOffset and EndOffset always equal to zero -- and they are not settable in any way, because they're ReadOnly and not exposed to the constructors.
- Feature request: add a cast operator to the ScriptExtents please
- Feature request: add a cast operator to the ScriptPositions please
- Feature request: make all of the numbers on the public objects settable
- Bug: stop returning Internal objects from public APIs (in this case,
Parser.Parse)
cc @daxian-dbw
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách lần theo Parser.Parse và các kiểu công khai ScriptExtent và ScriptPosition, so sánh chúng với các đối tượng InternalScriptExtent và InternalScriptPosition được mô tả trong báo cáo. Làm rõ thay đổi nào trong bốn thay đổi được yêu cầu nằm trong phạm vi, sau đó bổ sung coverage tập trung cho hành vi API công khai đã chọn, bao gồm việc giữ nguyên các offset khi phù hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp, powershell
- Lĩnh vực
- backend-api-design, cli, compilers
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- 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
- 30/100