How to add a run button in visual studio code?

Viewed 15502

i am a newcomer to this site and i'm not english so excuse me if this post isn't as good as you expected. Let's get to the point: to give you an example of what i mean with "run button", take the python one for example. Once you install python extension in visual studio code, you can press a button in the right top of the screen, and then vsc automatically executes a command in a shell running python on the active .py file. Given this example, I'd like to know how to make a button for vsc that automatically creates a new terminal, executes a command which i would insert in the making of the button and nothing else, of course the terminal shall not disappear after giving the desired output. Just to give you some more info, i'm on ubuntu, if that helps anyhow. Feel free to tell me whether i should edit this question in anyway.

4 Answers

Install the Task Runner extension. Now, every task you add to tasks.json will be displayed as a button, in the 'Task runner' panel (which is normally on the same tab as the file explorer).

Here's a decent tasks.json template:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "COMMAND NAME",
            "type": "shell",
            "command": "YOUR COMMAND HERE",
            "presentation": {"echo": true, "reveal": "always", "focus": false, "panel": "shared", "showReuseMessage": false, "clear": true},
        },
        // More tasks here, if you need them.
    ]
}

Put this file in your project directory, in a directory called .vscode. Open the project directory with "File" -> "Open Folder".

I know you did not ask for debugging, but you can use the debugger launch mechanism on arbitrary programs. You can define launch.json to implement any number of launch configurations. The currently selected configuration will display a button you can click on.

https://code.visualstudio.com/docs/editor/debugging

you can add the Code Runner extension. This will show a run button on top of the editor panel

Install Code Runner extension in VS Code

enter image description here

Related