Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 356
Scott VanKirk Avatar asked Aug 13 '19 02:08

Scott VanKirk


People also ask

How do I run a VS Code task?

Tip: You can run your task through Quick Open (Ctrl+P) by typing 'task', Space and the command name. In this case, 'task lint'.


Video Answer


1 Answers

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"
    }
like image 194
Mark Avatar answered Oct 12 '22 16:10

Mark