PowerShell / PowerShell/PSScriptAnalyzer

Intellisense for "settings" files

オープン
#1,254 コメント 1 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Consider - 2.0 Up-for-Grabs
主要言語
C#
スター
2.2k
フォーク
414
平均マージ
13時間 1分
マージ済み PR(30日)
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

  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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず Invoke-Formatter と Invoke-ScriptAnalyzer における -Settings の処理を追跡し、文書化された設定形式と比較します。設定スキーマが正式化され、両方のコマンドで JSON が受け入れられ、組み込み設定に対するエディターの検証と intellisense が有効になれば完了です。カスタム ルールは対象外とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
json
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。