PowerShell / PowerShell/PSScriptAnalyzer
Intellisense for "settings" files
還沒有人認領這個 Issue。
- 主要語言
- C#
- 星號
- 2.2k
- 分支
- 415
- 平均合併
- 13 小時 1 分鐘
- 30 天內合併 PR
- 2
描述
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
- Formalize the schema of PSScriptAnalyzer settings using JSON Schema.
- Accept JSON as a valid file format for
PSScriptAnalyzer\Invoke-Formatter -SettingsandPSScriptAnalyzer\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.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先追蹤 Invoke-Formatter 和 Invoke-ScriptAnalyzer 中對 -Settings 的處理,並將其與已記錄的設定格式進行比較。完成的標準是將設定結構正式化,並讓兩個命令都接受 JSON,同時為內建設定啟用編輯器驗證和 IntelliSense;自訂規則不在範圍內。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- json
- 領域
- developer-experience, tooling
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100