以下の内容はhttps://tech.guitarrapc.com/entry/2015/11/19/030028より取得しました。


VS Code での PowerShell サポートが強化されました

Microsoft Connect (); // 2015 Developer Event Set for November 18-19が現在開催されています。

https://channel9.msdn.com/

この中でVisual Studio Code (VS Code) の機能強化が発表され、PowerShellのデバッグ、インテリセンスサポートが追加されました。

今回はその紹介。

Visual Studio Code

Visual Studio Codeは、Microsoftが提供しているElectronベースの軽量なエディタです。

https://blog.shibayan.jp/entry/20150430/1430328999

それまであった、Visual Studioと違い、エディター としてかなり軽量かつ、マルチプラットフォームなためMacで利用できてとても便利です。

Language Support

これまでもVS CodeでPowerShellは利用できました。

が、あくまでシンタックスハイライトやブランケットの対応チェック、モジュールのインポート程度で、デバッグやインテリセンスはサポートされていませんでした。

今回のPowerShell機能強化は、まさにこのインテリセンス、静的なリアルタイムコード解析、デバッグ機能の提供となります。

https://blogs.msdn.com/b/powershell/archive/2015/11/17/announcing-windows-powershell-for-visual-studio-code-and-more.aspx

ようは、ISESteoidsとほぼ同等の機能がついたのです。もはやPowerShell ISE is Dead!

https://tech.guitarrapc.com/entry/2014/03/28/070501

元々 PowerShell ISEは、Integrated Scripting Environmentであって、IDEというより高機能エディタにすぎなかったので、VS Codeでさくっと書ける部分が増えるとうれしいものがあります。

インテリセンス

PowerShell ISEやVisual Studio tools for PowerShellであったインテリセンスですね!

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/5025.IntelliSense.gif

現在はWindows 10上で、PowerShell v5相当のインテリセンスサポートです。

定義への移動

VSやPowerShell ISE + ISE Steroidを使ってて、PowerShell ISE標準に戻れないのが、定義への移動です。これもVS Codeで利用可能になっています。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/6837.Definition.gif

なにがうれしいって、ドットソースで取りこんだ別ファイルにも移動できることです。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/0804.References.gif

シンボル表示

また、定義された関数などのシンボルも検索、移動できます。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/1830.Symbols.gif

静的コード解析

さらにPSScriptAnalyzerを利用して、コード解析も行うので定義したルールと異なる記述も明示されます。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/5187.ScriptAnalyzer.gif

デバッグ

もちろん、デバッグ実行もサポートされてます。ブレークポイントも貼れる。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/5850.Debugging1.gif

PowerShell ISEではデバッグ中の変数の状態が見えなかったですね? PowerShell ISE + ISE Steroidではできましたが、VS Codeも可能です。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/4405.Debugging2.gif

REPL

デバッグ画面の下にコマンドを入れれば、REPLもできます。

https://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74/8838.Debugging3.gif

将来のサポート

さらに将来、以下をサポート予定です。

  • WorkflowやDSC Configuation、クラス構文のサポート
  • リモートデバッグのサポート
  • より良いインタラクティブコンソールのサポート
  • いくつかのシンタックスルールの早期改善
  • PowerShell Galleryとの連携、統合によるモジュールのインストール
  • PowerShell 3.0とv4サポート

Extension インストール方法

PowerShell Extensionは、VS Codeで以下の操作で追加可能です。

  1. F1キーを押して入力ペイン表示
  2. ext installと入力すると言語サポートが表示される
  3. PowerShellと入力して、クリックするとインストールされる
  4. 後はVS Codeを再起動すればok

Extensionへのリンク置いておきますね!

Visual Studio Market Place - PowerShell

Market Place

Visual Studioファミリーの拡張やサブスクリプションが置かれた、Visual Studio Market Placeがプレビューリリースされました。ここにも置かれてるのでぜひぜひー

https://marketplace.visualstudio.com/#VSCode

デバッグの launch.json

デバッグするためには、現在のフォルダ配下にlaunch.jsonの定義が必要です。

F5を押すと、lanuch.jsonがなければ、Codeが勝手に作成してくれるので、以下を入力しましょう。

{
    "version": "0.1.0",
    "configurations": [
        {
            "name": "PowerShell",
            "type": "PowerShell",
            "program": "Debug対象のファイル名.ps1"
        }
    ]
}

このサンプルは、%UserProfile%\.vscode\extensions\ms-vscode.PowerShell\examples\.vscode\launch.jsonにあるのでそれを見てもokです。

まとめ

おや?

One last thing: Fans of PowerShell ISE, stay tuned for another great announcement next month!

来月PowerShell ISEでアナウンスがあります。

現状では、PowerShell ISE is dead!! なので、ISESteroidsなどを参考に機能が強化されるかな? 今のままでもRemote Debuggingやクラスベース構文など多くの優位点はあるので、ぜひ頑張ってほしいですね!

おまけ

WPFなど、他環境からVS Code同様のPowerShellでの開発機能を提供するライブラリPowerShellEditorServicesが公開されています。

これもチェックですね。

https://github.com/PowerShell/PowerShellEditorServices




以上の内容はhttps://tech.guitarrapc.com/entry/2015/11/19/030028より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14