Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
976 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...