如何在 Visual Studio Code 中使用简单的 F7 键绑定命令运行两个命令?

如何在 Visual Studio Code 中使用简单的 F7 键绑定命令运行两个命令?

当我按下 时F7,cargo test 会在后台的终端中运行。我无法F7同时运行 cargo test 和打开运行该命令的终端。

这是我尝试过的:

[ {
      "key": "f7",
      "command": "+workbench.action.terminal.toggleTerminal",
      "when": "editorTextFocus && editorLangId == rust",
    },
    {
      "key": "f7",
      "command": "workbench.action.terminal.sendSequence",
      "when": "editorTextFocus && editorLangId == rust",
      "args": { 
        "text": "cargo test\n"
       }
    }
]

答案1

您需要使用runCommands宏,它使用单个组合键依次执行多个命令。例如:

{
    "key": "f7",
    "command": "runCommands",
    "when": "editorTextFocus && editorLangId == rust",
    "args": {
        "commands": [
            {
                "command": "workbench.action.terminal.toggleTerminal"
            },
            {
                "command": "workbench.action.terminal.sendSequence",
                "args": {
                    "text": "cargo test\n"
                }
            }
        ]
    }
}

相关内容