タスクの登録
shif+cmd+b を押すと編集中のディレクトリに .vscode/task.json というファイルができる
- 以下のように編集する
cargo run は shift+cmd+b で実行できるようになる
cargo test は別途ショートカットを設定する(後述)
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "cargo",
"subcommand": "test",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
ショートカットの設定
shift+cmd+p でコマンドパレット(コマンドをリストから検索して使えるみたいなやつ)を開く
Preferences: Open Default Keyboard Shorcuts (JSON) で既存のショートカットが見られる
{ "key": "shift+cmd+b", "command": "workbench.action.tasks.build" } というのが登録されているのがわかる
// Here are other available commands: の下にコメントアウトされた workbench.action.tasks.test があるので、これに対応するショートカットを設定してやればよさそう
Preferences: Open Keyboard Shorcuts (JSON) で自分用のショートカットを登録する
{ "key": "shift+cmd+t", "command": "workbench.action.tasks.test" } を追加する
メモ
- task.jsonで設定できるkindはbuildとtestだけなんだろうか
- runとかfmtにもショートカットを設定したいかも