如何将 VSCode 命令作为任务运行 [英] How can I run a VSCode command as a task
问题描述
Github 上的 VSCode 有一个标题为 Running commands as tasks #11396
的问题.它涉及在 VSCode 中将 VSCode 命令作为内部任务运行.
VSCode on Github has an issue titled Running commands as tasks #11396
. It involves running a VSCode command as an internal task in VSCode.
alexr00 在 2018 年 12 月 20 日评论
:
alexr00 commented on Dec 20, 2018 that
:
您现在可以在 tasks.json 中使用命令
并指向以下文档:
我已经通读了这些文档,但仍然无法弄清楚如何做我想做的事.对于初学者,我想创建一个简单的任务来运行 liveserver 扩展启动代码:extension.liveServer.goOnline
I've read through these docs and I am still unable to figure out how to do what I want. For starters, I'd like to create a simple task that runs the liveserver extention start code: extention.liveServer.goOnline
有人对尝试什么或去哪里有任何想法吗?
Anyone have any thoughts on what to try or where to look?
推荐答案
例如你可以这样做:
{
"label": "run copyLinesDown command",
// "type": "shell",
"command": "${command:editor.action.copyLinesDownAction}",
// "command": "${command:extension.gist.open}" // etc
// "runOptions": {
// "runOn": "folderOpen"
// }
},
这是tasks.json
中的一个任务.当您运行该任务时,活动编辑器中的当前行将被复制.
That is a task in tasks.json
. When you run that task, the current line in the active editor will be copied down.
所以我猜你是否使用过
"command": "${command:extension.liveServer.goOnline}",
在像上面这样的任务中,应该运行扩展命令.(检查拼写,是 extension
还是 extension
?)
in a task like the above that extension command should be run. (Check the spelling, is it extention
or extension
?)
具体参见命令变量.
然后您可以使用(在 keybindings.json 中)为该任务分配一个键绑定:
And then you can assign a keybinding to that task with (in keybindings.json):
{
"key": "ctrl+h", // binding of your choice
"command": "workbench.action.tasks.runTask",
"args": "run copyLinesDown command"
}
这篇关于如何将 VSCode 命令作为任务运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!