Use Visual Studio Code and the Code Runner extension

2018-04-08 | Toni Pohl

Visual Studio Code (currently, Version 1.22 is available) is a very cool developer tool providing a modern and fast code editor with a bunch of extensions. With extensions as Code-Runner, it’s easy to run a code file or active text directly from the VS Code text editor. Check out this quick description how to configure and use Code Runner.

If you are new to VS Code, at a glance: To install the latest version of VS Code, get the download for Windows, Linux or macOS. To run a command, launch the Command Palette with F1 or Ctrl + Shift + P, run Quick Open by pressing Ctrl + P, etc. See all keyboard shortcuts at Windows, macOS and Linux.

As described in the Code-Runner marketplace description, the configuration must know, where to find the runtime executor. To set the executor path for the most common programming languages on your computer, check File / Preferences / Settings and open the Workspace Settings tab as shown here (see more at User and Workspace Settings). Paste the path to each programming language in here (see below) and press Ctrl + S to save the new settings.

image

Of course, the programming languages must be installed on your computer. When working with command line tools, it’s also a good idea to add them to the environment PATH to make them available in every directory. Adapt the executor map as needed for your environment. Here’s the sample from Code-Runner (usually you do not need to modify):

{
     "code-runner.executorMap": {
         "javascript": "node",
         "php": "C:\\php\\php.exe",
         "python": "python",
         "perl": "perl",
         "ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
         "go": "go run",
         "html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
         "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
         "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
     }
}

Press Ctrl + Alt + N (or click the Play Button on the top right corner or press F1 and then select/type Run Code) to run a code file with the configured program. As shown below, press Ctrl + Alt + M to stop the code run mode.

image

So, Visual Studio Code and extensions as Code-Runner are great tools for development on all OS platforms. If you are coming from Visual Studio and you are used to run ASP.NET apps with the integrated IIS, there are more extensions available as I wrote some time ago here.

There are so many resources out how to use VS Code, just to name a few:

Happy developing with Visual Studio Code (and extensions)!

Categories: App, Developer, DevOps, English, Microsoft, Open Source, Visual Studio, Tools, TypeScript

Source: http://blog.atwork.at/post/2018/04/08/Run-Code-from-Visual-Studio-Code