PowerShell / PowerShell/PSScriptAnalyzer

Intellisense for "settings" files

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

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

Consider - 2.0 Up-for-Grabs
Ngôn ngữ chính
C#
Star
2.2k
Fork
414
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

Mô tả

User Story

As a writer of PSScriptAnalyzer settings files
I want intellisense (autocompletion, hover information, validation)
so that I can have a modern editing experience.

Discussion

Intellisense is an expected part of the modern editing experience. It not only improves programmer efficiency and code correctness, but also discoverability and new user satisfaction (vs. frustration).

Settings in a shell scripting context are generally set either as command options (e.g. PackageManagement\Set-PackageSource -Trusted) or as a data file (e.g. Format.ps1xml). PSScriptAnalyzer uses the data file approach, which is reasonable considering both the use case as well as the extent of possible settings.

PowerShell data files (.psd1) do not have an associated schema specification, and therefore do not support content-specific intellisense. Unfortunately, it does not appear that much progress is being made on this issue from a PowerShell-language standpoint (see PowerShell #4016).

The lack of intellisense for PowerShell script analysis settings stands in contrast to other fundamental PowerShell settings files. E.g. Types.ps1xml and Format.ps1xml files get intellisense because they have schemas. They are able to have schemas because they use a data language (XML) that has an associated schema language (XSD).

The documented format of PSScriptAnalyzer settings files is expressible as a hash table containing only booleans, strings, and arrays of strings. This simple structure does not require the full expressivity of the .psd1 format (e.g. imperative script blocks). Moreover, this structure both resembles and is expressible as JSON, which does have an associated schema language (JSON Schema) that is supported by intellisense in modern editors (e.g. VS Code). Furthermore, PowerShell has built-in cmdlets for JSON (e.g. ConvertFrom-Json).

Proposal

  1. Formalize the schema of PSScriptAnalyzer settings using JSON Schema.
  2. Accept JSON as a valid file format for PSScriptAnalyzer\Invoke-Formatter -Settings and PSScriptAnalyzer\Invoke-ScriptAnalyzer -Settings.

These two changes would enable editors to provide intellisense for the vast majority of PSScriptAnalyzer settings files.

(The only aspect of PSScriptAnalyzer settings files for which these changes would not enable intellisense is custom rules. As such, that should necessarily be a separate and subsequent feature request.)

An alternative would be to extend the PowerShellEditorServices intellisense feature to provide the requested intellisense. Doing so might be required for custom rule intellisense and documentation, but would likely be more work than is required for built-in rule intellisense. This is because is built-in rules are known at compile time, and so a static JSON schema may published for them.

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

Bắt đầu bằng cách theo dõi cách xử lý -Settings trong Invoke-Formatter và Invoke-ScriptAnalyzer rồi so sánh với định dạng cài đặt đã được tài liệu hóa. Hoàn thành có nghĩa là schema cài đặt được chuẩn hóa và JSON được cả hai lệnh chấp nhận, với tính năng kiểm tra hợp lệ của trình soạn thảo và intellisense được bật cho các cài đặt tích hợp sẵn; các quy tắc tùy chỉnh vẫn nằm ngoài phạm vi.

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

Đánh giá

Công nghệ
json
Lĩnh vực
developer-experience, tooling
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
25/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.