Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
980 views
in Technique[技术] by (71.8m points)

visual studio code - How can I run a VSCode command as a task

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 commented on Dec 20, 2018 that:

You can now have commands in tasks.json and points to the following docs:

https://code.visualstudio.com/docs/editor/variables-reference#_settings-command-variables-and-input-variables

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So for instance you could do this:

    {
      "label": "run copyLinesDown command",
      //  "type": "shell",
      
      "command": "${command:editor.action.copyLinesDownAction}",

      // "command": "${command:extension.gist.open}"  // etc

      // "runOptions": {
      //   "runOn": "folderOpen"
      // }
    },

That is a task in tasks.json. When you run that task, the current line in the active editor will be copied down.

So I presume if you used

    "command": "${command:extension.liveServer.goOnline}",

in a task like the above that extension command should be run. (Check the spelling, is it extention or extension?)

See specifically command variables.

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"
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...