• Stars
    star
    2,016
  • Rank 22,069 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code Runner for Visual Studio Code

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, and custom command

Sponsors

CodeStream
Eliminate context switching and costly distractions. Create and merge PRs and perform code reviews from inside your IDE while using jump-to-definition, your keybindings, and other IDE favorites. Learn more.

Stepsize
Track and prioritise tech debt and maintenance issues, straight from your IDE. Bookmark code while you work, organise TODOs and share codebase knowledge with your team. Try it out for free today.

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.

More Repositories

1

955.WLB

955 不加班的公司名单 - 工作 955,work–life balance (工作与生活的平衡)
33,386
star
2

944.Life

996.ICU 的反向 repo: 944 工作制 - 工作 944,生活为先
976
star
3

awesome-gpt

A curated list of awesome projects and resources related to GPT, ChatGPT, OpenAI, LLM, and more.
873
star
4

awesome-vscode-cn

中文版 Awesome VS Code
778
star
5

vscode-ycy

超越鼓励师 for VS Code
TypeScript
287
star
6

vscode-auto-rename-tag

Automatically rename paired HTML/XML tag
TypeScript
243
star
7

vscode-mysql

MySQL management tool for Visual Studio Code
TypeScript
212
star
8

vscode-dotnet-test-explorer

.NET Core Test Explorer for Visual Studio Code
TypeScript
202
star
9

chatgpt-teams-bot

A ChatGPT Teams Bot app to let you chat with ChatGPT in Microsoft Teams
TypeScript
200
star
10

vscode-auto-close-tag

Auto Close Tag for Visual Studio Code
TypeScript
169
star
11

awesome-azure-iot

A curated list of awesome Azure Internet of Things projects and resources.
127
star
12

openai-teams-bot

An OpenAI Teams Bot app to let you chat with OpenAI API in Microsoft Teams, similar to ChatGPT Teams Bot app
TypeScript
116
star
13

weapp-955-wlb

955WLB 微信小程序
JavaScript
102
star
14

semantic-kernel-vs-langchain

Compare Semantic Kernel and LangChain
64
star
15

vscode-iot-utility

IoT Utility for Visual Studio Code: Arduino, Espressif, Raspberry Pi, mbed and more
TypeScript
64
star
16

vscode-code-runner-for-web

Run code in browser version of VS Code
TypeScript
49
star
17

vscode-terminal

Terminal for Visual Studio Code
TypeScript
43
star
18

vscode-docker-explorer

Docker Explorer for Visual Studio Code
TypeScript
42
star
19

chatgpt-wechat-bot

ChatGPT 微信机器人,基于 ChatGPT API 和 Wechaty
JavaScript
29
star
20

vscode-translator

VS Code extension to translate between English and Chinese.
TypeScript
25
star
21

vscode-node-red

Node-RED for Visual Studio Code
TypeScript
18
star
22

openai-examples

Code Samples for OpenAI & ChatGPT API
JavaScript
16
star
23

vscode-github-actions

GitHub Actions for VS Code
TypeScript
14
star
24

CodeRunnerVS

Code Runner for Visual Studio
C#
10
star
25

vscode-955-wlb

955.WLB extension for Visual Studio Code
TypeScript
10
star
26

vscode-dotnet

.NET Core Tools for Visual Studio Code
TypeScript
10
star
27

chatgpt-wechat-public-account

把 ChatGPT 接入微信公众号
Python
9
star
28

vscode-azure-storage-explorer

Manage Azure Storage in Visual Studio Code
TypeScript
7
star
29

vscode-azure-iot-toolkit

This extension is now maintained in the Microsoft repo
TypeScript
6
star
30

vscode-extension-leaderboard

Data insight for popular extensions, history of download count and extension leaderboard
TypeScript
6
star
31

vsce-website

Source Code for Visual Studio Code Extension Download Count
JavaScript
6
star
32

vscode-auto-complete-tag

Extension Pack to add close tag and rename paired tag automatically for HTML/XML
6
star
33

formulahendry.github.io.source

Source repo for personal blog
JavaScript
5
star
34

azure-iot-toolkit-for-mobile

Azure IoT Toolkit for Android, iOS and Windows Phone
JavaScript
4
star
35

vscode-iot-extension-pack

Build IoT Solutions on top of awesome technology stacks
4
star
36

weapp-garbage-classification

JavaScript
3
star
37

azure-iot-webclient

Azure IoT Web Client
JavaScript
3
star
38

vscode-chat-room

Chat Room & Chat Bot for VS Code
TypeScript
3
star
39

teams-bot-langchain

A Teams Bot app integrated with LangChain
TypeScript
2
star
40

teams-bot-semantic-kernel

A Teams Bot app integrated with Semantic Kernel and its Microsoft Graph Plugin
C#
2
star
41

vscode-azure-virtual-machine-explorer

Manage Azure Virtual Machine in VS Code
TypeScript
2
star
42

my-first-static-web-app

HTML
1
star
43

azure-cli-content-test

1
star
44

vscode-docker-extension-pack

Docker Extension Pack for Visual Studio Code
1
star
45

intro-html

A robot powered training repository 🤖
1
star
46

uwp-vsce

UWP for Visual Studio Code Extension Marketplace
HTML
1
star
47

awesome-azure-for-java

A curated list of awesome Azure projects and resources for Java
1
star
48

vscode-azure-iot-toolkit-1

TypeScript
1
star