Verilog用のVSCode拡張機能が喉から手が出るほどほしい
LanguageServerを利用した(しなくても良い)いい感じの補完機能を持ったVerilogエディタが欲しい。
EmacsのVerilogModeはもう無理。Lispで独自コマンドを作るのは苦痛。
ということで自分用に作ることにしました。
現在公開中です。
https://marketplace.visualstudio.com/items?itemName=Rockdoor.systemverilog
忘れそうなので、Windowsのケースで拡張機能作成のメモを残します。
拡張機能のインストールの仕組み
C:\Users\<username>\.vscode\extensions
上記パスにディレクトリで拡張機能がまとまっています。
VSCode上で拡張機能をインストールすると、このディレクトリにダウンロードされる仕組みのようです。
このディレクトリに自分で作った拡張機能を置くと、VSCodeは拡張機能として認識してくれます。とてもシンプル。
拡張機能の構成
Extensionの作り方は公開されています。
Yaomanとか言う謎のツールでテンプレートを生成して適時変更すれば良い、的なことが書かれていますが、このツールの生成コードは無駄が多く、また、使ってもいないのに妙なコードが混ざっていたらしくSecurity Issueに巻き込まれてしまいましたので使わないほうがいいかもしれません。
event-stream 乗っ取り事件に巻き込まれた図
https://github.com/Rockdoor/systemverilog/issues/8
さて、拡張機能内部のディレクトリ構成は公式ページに書かれているとおりなのですが、ダウンロードされる物や生成物が含まれており、サンプルとして不適切だと感じます。私はのっけからファイルが多くて辟易しました。
私見では、スタート時の最小構成は次のようなもので十分です。
.
├── src
│ ├── extension.ts // the source of the extension entry point
│ └── tsconfig.json // compiler settings
├── out // compilation output (TypeScript only)
├── language-configuration.json // configurations for specific language
├── package.json // extension's manifest
あとは適時package.jsonに構成を追記し、ディレクトリとファイルを追加してく形でよいです。
package.jsonに書かれている内容が要件を満たしていると、たとえ有効な実行コードが存在しなくてもこの時点で拡張機能として認識されます。extension.tsの中身も空でOKです。
package.json、language-configuration.json は以下のようにしておく。
中身を開く
{
"name": "guide",
"displayName": "Guides for building extensions of VSCode",
"description": "Here is a description of this extension",
"version": "0.0.1",
"publisher": "someone",
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
"vscode": "^1.27.2"
},
"main": "./out/extension",
"categories": [
"Programming Languages",
"Snippets"
],
"activationEvents": [
"onLanguage:sv"
],
"scripts": {
"init-setup": "npm install && node ./node_modules/vscode/bin/install",
"vscode:prepublish": "tsc -p src/tsconfig.json",
"postinstall": "node ./node_modules/vscode/bin/install",
"publish": "vsce publish",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"contributes": {
},
"languages": [
{
"id": "sv",
"aliases": [
"SystemVerilog",
"Verilog",
"sv"
],
"extensions": [
"v",
"vh",
"sv",
"svh"
],
"configuration": "./language-configuration.json"
}
],
"dependencies": {
}
}
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
"blockComment": [ "/*", "*/" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["begin", "end"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
],
// symbols that that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""]
]
}
これで、問題なければVSCodeのインストール済み拡張機能の一覧に"Guides for building extensions of VSCode"という項目が出てきており、インストール済み扱いとなります。