Convert Figma logo to code with AI

formulahendry logovscode-code-runner

Code Runner for Visual Studio Code

2,283
306
2,283
709

Top Related Projects

169,070

Visual Studio Code

60,364

:atom: The hackable text editor

VS Code in the browser

13,084

The developer platform for on-demand cloud development environments to create software faster and more securely.

Quick Overview

VS Code Code Runner is a popular extension for Visual Studio Code that allows users to run code snippets or files in various programming languages directly from the editor. It supports over 40 languages and provides a quick and convenient way to execute code without leaving the IDE.

Pros

  • Supports a wide range of programming languages (40+)
  • Easy to use with keyboard shortcuts and context menu options
  • Customizable execution commands for each language
  • Ability to run code in an integrated terminal or output window

Cons

  • May require additional setup for some languages
  • Limited debugging capabilities compared to full-fledged language-specific extensions
  • Potential security risks if running untrusted code
  • Performance may vary depending on the complexity of the code being run

Getting Started

  1. Install the Code Runner extension from the VS Code marketplace.
  2. Open a file with code in a supported language.
  3. Use the keyboard shortcut Ctrl+Alt+N (or Cmd+Alt+N on macOS) to run the code.
  4. Alternatively, right-click in the editor and select "Run Code" from the context menu.

To customize the extension:

  1. Open VS Code settings (File > Preferences > Settings).
  2. Search for "code-runner" to find and modify extension-specific settings.
  3. You can customize execution commands, output behavior, and more.

Example custom setting in settings.json:

{
  "code-runner.executorMap": {
    "javascript": "node",
    "python": "python3 -u"
  },
  "code-runner.runInTerminal": true
}

This configuration sets custom execution commands for JavaScript and Python, and ensures the code runs in the integrated terminal.

Competitor Comparisons

169,070

Visual Studio Code

Pros of vscode

  • Full-featured IDE with extensive functionality beyond code running
  • Large ecosystem of extensions and themes
  • Integrated debugging, version control, and terminal

Cons of vscode

  • Heavier resource usage compared to lightweight extensions
  • Steeper learning curve for new users
  • May include features not needed by all developers

Code Comparison

vscode-code-runner:

{
  "code-runner.executorMap": {
    "javascript": "node",
    "python": "python",
    "ruby": "ruby"
  }
}

vscode:

{
  "launch": {
    "configurations": [
      {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${file}"
      }
    ]
  }
}

The code-runner extension focuses on quick execution of code snippets, while vscode provides more comprehensive debugging and launch configurations.

vscode-code-runner is a lightweight extension specifically designed for running code snippets in various languages. It offers a simple and straightforward way to execute code without the need for complex configurations.

vscode, on the other hand, is a complete integrated development environment with a wide range of features beyond code execution. It provides a more robust development experience but may require more setup and configuration for specific tasks.

60,364

:atom: The hackable text editor

Pros of Atom

  • Full-featured text editor with extensive customization options
  • Large ecosystem of packages and themes
  • Built-in package manager for easy extension installation

Cons of Atom

  • Heavier resource usage compared to lightweight extensions
  • Slower startup time and performance on larger projects
  • Less frequent updates and maintenance

Code Comparison

While a direct code comparison isn't relevant due to the different scopes of these projects, we can look at how they might be used:

Atom (configuring a custom keymap):

'atom-text-editor':
  'ctrl-alt-c': 'custom:run-code'

Code Runner (configuring a custom language):

"code-runner.executorMap": {
  "python": "python -u"
}

Atom is a full-featured text editor with its own ecosystem, while Code Runner is a lightweight extension for VS Code focused on running code snippets. Atom offers more extensive customization but at the cost of increased resource usage and slower performance. Code Runner provides a simpler, more focused solution for running code within VS Code, benefiting from VS Code's performance optimizations and frequent updates.

VS Code in the browser

Pros of code-server

  • Full VS Code environment accessible through a web browser
  • Supports remote development and collaboration
  • Can be self-hosted for enhanced security and control

Cons of code-server

  • Requires more setup and resources compared to a simple extension
  • May have higher latency due to running in a browser

Code comparison

code-server (server.ts):

import { Server } from "./node/server"

const server = new Server({
  host: args["host"],
  port: args["port"],
  socket: args["socket"],
})

server.listen()

vscode-code-runner (extension.ts):

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('code-runner.run', () => {
        codeRunner.run();
    });
    context.subscriptions.push(disposable);
}

code-server provides a full server implementation for running VS Code in a browser, while vscode-code-runner is a lightweight extension for running code snippets within VS Code. The code-server approach offers more flexibility and remote capabilities, but requires more setup. vscode-code-runner is simpler to use for quick code execution within a local VS Code instance.

13,084

The developer platform for on-demand cloud development environments to create software faster and more securely.

Pros of Gitpod

  • Provides a full cloud-based development environment, not just code execution
  • Supports collaboration features and workspace sharing
  • Offers pre-configured environments for various tech stacks

Cons of Gitpod

  • Requires more setup and configuration compared to the simplicity of Code Runner
  • May have a steeper learning curve for users new to cloud development environments
  • Potentially higher resource usage and costs for extensive projects

Code Comparison

Gitpod configuration (.gitpod.yml):

tasks:
  - init: npm install
    command: npm start
ports:
  - port: 3000
    onOpen: open-preview

Code Runner configuration (settings.json):

"code-runner.executorMap": {
  "javascript": "node",
  "python": "python -u"
},
"code-runner.runInTerminal": true

Gitpod focuses on defining a complete development environment, while Code Runner primarily configures execution commands for different languages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Code Runner

Join the chat at https://gitter.im/formulahendry/vscode-code-runner Downloads Rating Actions Status

Run code snippet or code file for multiple languages: C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Visual Basic .NET, Clojure, Haxe, Objective-C, Rust, Racket, Scheme, AutoHotkey, AutoIt, Kotlin, Dart, Free Pascal, Haskell, Nim, D, Lisp, Kit, V, SCSS, Sass, CUDA, Less, Fortran, Ring, Standard ML, Zig, Mojo, Erlang, SPWN, Pkl, Gleam, and custom command

Book for VS Code

《Visual Studio Code 权威指南》:带你深入浅出 VS Code!

Book

WeChat Official Account

VS Code 的热门文章、使用技巧、插件推荐、插件开发攻略等,请关注“玩转VS Code”公众号!

WeChat

Donation

If you like this extension, you could become a backer or sponsor via Patreon, donate via PayPal, or scan below QR code to donate via Alipay. Any amount is welcome. It will encourage me to make this extension better and better!

Alipay

Features

  • Run code file of current active Text Editor
  • Run code file through context menu of file explorer
  • Run selected code snippet in Text Editor
  • Run code per Shebang
  • Run code per filename glob
  • Run custom command
  • Stop code running
  • View output in Output Window
  • Set default language to run
  • Select language to run
  • Support REPL by running code in Integrated Terminal

Usages

  • To run code:
    • use shortcut Ctrl+Alt+N
    • or press F1 and then select/type Run Code,
    • or right click the Text Editor and then click Run Code in editor context menu
    • or click Run Code button in editor title menu
    • or click Run Code button in context menu of file explorer
  • To stop the running code:
    • use shortcut Ctrl+Alt+M
    • or press F1 and then select/type Stop Code Run
    • or click Stop Code Run button in editor title menu
    • or right click the Output Channel and then click Stop Code Run in context menu

Usage

  • To select language to run, use shortcut Ctrl+Alt+J, or press F1 and then select/type Run By Language, then type or select the language to run: e.g php, javascript, bat, shellscript...

Usage

  • To run custom command, then use shortcut Ctrl+Alt+K, or press F1 and then select/type Run Custom Command

Configuration

Make sure the executor PATH of each language is set in the environment variable. You could also add entry into code-runner.executorMap to set the executor PATH. e.g. To set the executor PATH for ruby, php and html:

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

Supported customized parameters

  • $workspaceRoot: The path of the folder opened in VS Code
  • $dir: The directory of the code file being run
  • $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
  • $fullFileName: The full name of the code file being run
  • $fileName: The base name of the code file being run, that is the file without the directory
  • $fileNameWithoutExt: The base name of the code file being run without its extension
  • $driveLetter: The drive letter of the code file being run (Windows only)
  • $pythonPath: The path of Python interpreter (set by Python: Select Interpreter command)

Please take care of the back slash and the space in file path of the executor

  • Back slash: please use \\
  • If there ares spaces in file path, please use \" to surround your file path

You could set the executor per filename glob:

{
    "code-runner.executorMapByGlob": {
        "pom.xml": "cd $dir && mvn clean package",
        "*.test.js": "tap",
        "*.js": "node"
    }
}

Besides, you could set the default language to run:

{
    "code-runner.defaultLanguage": "javascript"
}

For the default language: It should be set with language id defined in VS Code. The languages you could set are java, c, cpp, javascript, php, python, perl, ruby, go, lua, groovy, powershell, bat, shellscript, fsharp, csharp, vbscript, typescript, coffeescript, swift, r, clojure, haxe, objective-c, rust, racket, ahk, autoit, kotlin, dart, pascal, haskell, nim, d, lisp

Also, you could set the executor per file extension:

{
    "code-runner.executorMapByFileExtension": {
        ".vbs": "cscript //Nologo"
    }
}

To set the custom command to run:

{
    "code-runner.customCommand": "echo Hello"
}

To set the the working directory:

{
    "code-runner.cwd": "path/to/working/directory"
}

To set whether to clear previous output before each run (default is false):

{
    "code-runner.clearPreviousOutput": false
}

To set whether to save all files before running (default is false):

{
    "code-runner.saveAllFilesBeforeRun": false
}

To set whether to save the current file before running (default is false):

{
    "code-runner.saveFileBeforeRun": false
}

To set whether to show extra execution message like [Running] ... and [Done] ... (default is true):

{
    "code-runner.showExecutionMessage": true
}

[REPL support] To set whether to run code in Integrated Terminal (only support to run whole file in Integrated Terminal, neither untitled file nor code snippet) (default is false):

{
    "code-runner.runInTerminal": false
}

To set whether to preserve focus on code editor after code run is triggered (default is true, the code editor will keep focus; when it is false, Terminal or Output Channel will take focus):

{
    "code-runner.preserveFocus": true
}

code-runner.ignoreSelection: Whether to ignore selection to always run entire file. (Default is false)

code-runner.showRunIconInEditorTitleMenu: Whether to show 'Run Code' icon in editor title menu. (Default is true)

code-runner.showRunCommandInEditorContextMenu: Whether to show 'Run Code' command in editor context menu. (Default is true)

code-runner.showRunCommandInExplorerContextMenu: Whether to show 'Run Code' command in explorer context menu. (Default is true)

code-runner.showStopIconInEditorTitleMenu: Whether to show 'Stop Code Run' icon in editor title menu when code is running. (Default is true)

code-runner.terminalRoot: For Windows system, replaces the Windows style drive letter in the command with a Unix style root when using a custom shell as the terminal, like Bash or Cgywin. Example: Setting this to /mnt/ will replace C:\path with /mnt/c/path (Default is "")

code-runner.temporaryFileName: Temporary file name used in running selected code snippet. When it is set as empty, the file name will be random. (Default is "tempCodeRunnerFile")

code-runner.respectShebang: Whether to respect Shebang to run code. (Default is true)

About CWD Setting (current working directory)

  1. By default, use the code-runner.cwd setting
  2. If code-runner.cwd is not set and code-runner.fileDirectoryAsCwd is true, use the directory of the file to be executed
  3. If code-runner.cwd is not set and code-runner.fileDirectoryAsCwd is false, use the path of root folder that is open in VS Code
  4. If no folder is open, use the os temp folder

Note

  • For Objective-C, it is only supported on macOS
  • To run C# script, you need to install scriptcs
  • To run TypeScript, you need to install ts-node
  • To run Clojure, you need to install Leiningen and lein-exec

Telemetry data

By default, telemetry data collection is turned on to understand user behavior to improve this extension. To disable it, update the settings.json as below:

{
    "code-runner.enableAppInsights": false
}

Change Log

See Change Log here

Issues

Submit the issues if you find any bug or have any suggestion.

Contribution

Fork the repo and submit pull requests.