• 请不要在回答技术问题时复制粘贴 AI 生成的内容
formulahendry
V2EX  ›  程序员

Code Runner for VS Code, 支持运行 27 种语言 (C, C++, Java , JS, PHP , Python , Perl, Ruby, Go, Lua, Groovy, PowerShell...)

  •  8
     
  •   formulahendry ·
    formulahendry · Jan 14, 2017 · 18733 views
    This topic created in 3581 days ago, the information mentioned may be changed or developed.

    经过了半年的打磨,Code Runner已经支持了 27 种语言: C, C++, Java, JS, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F#, C#, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml, R, AppleScript, Elixir 。并且支持以下几个主要功能:

    • Run code file of current active Text Editor
    • Run selected code snippet in Text Editor
    • Run custom command with customized parameters
    • 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

    run code

    如果大家发现了任何 bug 或者有什么建议,欢迎来GitHub给我提 issue 或者 PR 。

    Supplement 1  ·  Jan 3, 2019

    最近还开通了"玩转VS Code"的公众号。希望能和大家分享一下VS Code使用和开发的一些经验,主要希望提供的内容包括但不限于:

    • VS Code 快速入门
    • VS Code 使用技巧
    • VS Code 插件推荐
    • VS Code 插件开发

    有兴趣的童鞋,可以来关注"玩转VS Code"公众号。也希望听听大家的意见,更希望看到什么样的内容。 QR

    59 replies  •  2018-03-11 17:21:12 +08:00
    langmoe
    langmoe
    Jan 14, 2017
    1
    我还以为买的 Code Runner 又有更新了。。
    chairchan
    chairchan
    Jan 14, 2017 via Android
    2
    兹词 正在用😀
    KiriGiri
    KiriGiri
    Jan 14, 2017 via Android
    3
    可以添加一个功能,把运行结果直接替换选中的代码,就像 vim 的:'<,'>!command 。
    asxaqz
    asxaqz
    Jan 14, 2017
    4
    一直在用。支持。
    0915240
    0915240
    Jan 14, 2017
    5
    我曹 !
    兹词~~
    40huo
    40huo
    Jan 14, 2017
    6
    兹词,好用!
    cdwyd
    cdwyd
    Jan 14, 2017
    7
    python 的输出不是实时的吗?测试了下是全部执行完才统一输出
    quericy
    quericy
    Jan 14, 2017
    8
    厉害了,已安装
    exoticknight
    exoticknight
    Jan 14, 2017
    9
    好厉害,是不是应该换了……
    kchum
    kchum
    Jan 14, 2017
    10
    我也以为是 Code Runner 2 。。
    loading
    loading
    Jan 14, 2017 via Android
    11
    比 vs go 是不是强一些呢,看看。
    pipecat
    pipecat
    Jan 14, 2017 via iPhone
    12
    在用,支持
    formulahendry
    formulahendry
    OP
    Jan 14, 2017
    13
    @langmoe @kchum 我们这个 Code Runner 可是免费跨平台的哦😁
    formulahendry
    formulahendry
    OP
    Jan 14, 2017
    14
    @KiriGiri VIM 没怎么用过,能具体说下吗?比如说,运行 var a = 1 + 2 ,然后把代码替换为 var a = 3?
    blanu
    blanu
    Jan 14, 2017 via iPhone
    15
    Great! VSCode 自带的调试运行时太重,这个看上去就非常方便
    formulahendry
    formulahendry
    OP
    Jan 14, 2017
    16
    @blanu 对滴!而且能选择运行 code snippet ,快捷轻巧😎
    XYxe
    XYxe
    Jan 14, 2017
    17
    Python 输出的中文会乱码
    另外,不能区分 Python2 和 Python3 吗?
    formulahendry
    formulahendry
    OP
    Jan 14, 2017❤️1
    18
    @XYxe
    关于乱码,有两个解决方法:
    1. 设置 PYTHONIOENCODING ,参考 https://github.com/formulahendry/vscode-code-runner/issues/33#issuecomment-263131627
    "code-runner.executorMap": {
    "python": "set PYTHONIOENCODING=utf8 && python"
    }
    2. 设置使用 built-in terminal ,参考 https://github.com/formulahendry/vscode-code-runner/issues/25#issuecomment-257123682
    "code-runner.runInTerminal": true

    关于区分 Python2 和 Python3 ,可以在 user settings 自定义 code-runner.executorMap ,参考 https://github.com/formulahendry/vscode-code-runner#configuration
    XYxe
    XYxe
    Jan 14, 2017
    19
    @formulahendry 啊,谢谢 。不能把 Python2 和 3 设置为不同语言吗?因为不同的文件可能需要不同版本, 每次修改设置会比较麻烦。
    formulahendry
    formulahendry
    OP
    Jan 14, 2017
    20
    @cdwyd 唉, python 真的有这个问题唉,其他语言倒是能实时输出的😅不过有办法可以 workaround ,在 user settings 设置使用 ntegrated Terminal :
    "code-runner.runInTerminal": true
    cdwyd
    cdwyd
    Jan 14, 2017 via Android
    21
    @formulahendry
    明天试试这个,开启那个 repl 也能解决
    viko16
    viko16
    Jan 14, 2017 via Android
    22
    好棒,赞赞赞
    formulahendry
    formulahendry
    OP
    Jan 14, 2017
    23
    @XYxe Python2 和 3 的文件都是.py 吧?似乎并不能自动区分出来。如果只是不同的 Workspace 会用不同 python 版本,可以在 File-> Preferences->Workspace Settings 设置不同的 python 解释器,这样不知道能满足需求吗?如果在同一个 Workspace 会用不同 python 版本,可以考虑使用 custom command :"code-runner.customCommand": "python3"
    cdwyd
    cdwyd
    Jan 14, 2017
    24
    @formulahendry
    忽略上一条吧 专门起来看了下就是用的"code-runner.runInTerminal": true 😅
    Lattez
    Lattez
    Jan 14, 2017
    25
    赞赞赞!!自己配的话太麻烦,每次开个新的都要重新弄
    XYxe
    XYxe
    Jan 14, 2017
    26
    @formulahendry 可以通过 shebang 来判断吗?
    formulahendry
    formulahendry
    OP
    Jan 15, 2017
    27
    @XYxe 目前对文件类型的判断是直接调用 VS Code 的 API , VS Code 并没有对 python 2 和 python 3 有区分。而且 shebang 在 Windows 上并没有吧。不过可以考虑当作个 feature 来做。欢迎到 github 给我提这个 feature ,如果你想自己实现的话,也非常欢迎 PR !
    formulahendry
    formulahendry
    OP
    Jan 15, 2017
    28
    @cdwyd 哈哈哈😆
    Lxxyx
    Lxxyx
    Jan 15, 2017 via Android
    29
    刚试了试,感觉很棒,谢谢楼主。
    kuaner
    kuaner
    Jan 15, 2017 via iPhone
    30
    哈哈,原来作者在这呀,非常棒的插件
    anuxs
    anuxs
    Jan 15, 2017 via iPhone
    31
    支持。试试。
    DearMark
    DearMark
    Jan 15, 2017 via Android
    32
    32 个赞\(≧▽≦)/
    visitantzj
    visitantzj
    Jan 15, 2017
    34
    赞一个, 小文件直接用着很方便, 文件多再设 proj
    formulahendry
    formulahendry
    OP
    Jan 15, 2017
    35
    @KiriGiri 很有意思的功能!可以考虑实现下!
    formulahendry
    formulahendry
    OP
    Jan 15, 2017
    36
    @visitantzj 对!运行单个小文件非常方便!
    xuboying
    xuboying
    Jan 15, 2017 via iPhone
    37
    这个要具体语言的运行库么,还是楼主的云上运行?
    hxtheone
    hxtheone
    Jan 15, 2017
    38
    这个必须赞
    renyiqiu
    renyiqiu
    Jan 15, 2017
    39
    mark 一下
    formulahendry
    formulahendry
    OP
    Jan 15, 2017
    40
    @xuboying 对的,需要相应的解释器或编译器。比如 JS 需要 Node , C 需要 gcc 。当然也可以根据需要自己设置,比如可以用 clang 替换 gcc 。
    icreeper
    icreeper
    Jan 15, 2017
    41
    感觉比 CodeRunner2 还好用!赞一个
    formulahendry
    formulahendry
    OP
    Jan 15, 2017 via Android
    42
    @icreeper 😎😎
    manongvpn
    manongvpn
    Jan 16, 2017 via Android
    43
    大牛
    araraloren
    araraloren
    Jan 16, 2017
    44
    看起来不错的样子,最近也有点使用 VSCODE 的兴趣~~ mark 一下
    coa
    coa
    Jan 16, 2017
    45
    这个强, Code Runner 2 胜在支持 Objective C ,可惜收费。。求问 Atom 下有没有类似的东西。。。
    WeeH9T
    WeeH9T
    Feb 7, 2017
    46
    @formulahendry vs2015 没找到 CTRL+P ,怎么安装。。。
    formulahendry
    formulahendry
    OP
    Feb 7, 2017
    47
    @hambut 这个插件是 Visual Studio Code 的: https://code.visualstudio.com/ ,不是 VS IDE 😅
    WeeH9T
    WeeH9T
    Feb 7, 2017
    48
    @formulahendry #47 好尴尬啊。。刚才下了 VS CODE 试了下,别的都挺满意, CTRL SHIFT O 有些认不出来,没有 minimap 暂时性流失。。
    formulahendry
    formulahendry
    OP
    Feb 7, 2017
    49
    @hambut 看什么语言了吧, Node.js 有 built-in 支持,其它语言的'Go to Symbol'还是要另外装插件
    vito0719
    vito0719
    May 11, 2017
    50
    能在 windows 下运行 swift 吗?
    formulahendry
    formulahendry
    OP
    May 12, 2017
    51
    @vito0719 Bash on Windows :)
    vito0719
    vito0719
    May 12, 2017
    52
    @formulahendry 我在 bash 里已经可以用 swift 了,请问在 vs code 里还需要改什么?
    formulahendry
    formulahendry
    OP
    May 13, 2017
    53
    @vito0719
    1. 设置 Integrated Terminal 用 Bash on Ubuntu (on Windows): https://code.visualstudio.com/docs/editor/integrated-terminal#_windows:"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
    2. 设置 Code Runner 用 Integrated Terminal:"code-runner.runInTerminal": true
    vito0719
    vito0719
    May 15, 2017
    55
    @formulahendry 好像问题是路径?我运行得到的回复是这样的:
    Playground.swift"-CZZ:/mnt/c/Users/vito0719$ swift "c:\Users\vito0719\Documents\
    <unknown>:0: error: no such file or directory: 'c:\Users\vito0719\Documents\Playground.swift'

    好像要改成 /mnt/c/Users/这样的路径才行,这个有方法吗?
    formulahendry
    formulahendry
    OP
    May 15, 2017
    56
    @vito0719 的确目前有 limitation,现在有 issue 在 track: https://github.com/formulahendry/vscode-code-runner/issues/106
    jin7
    jin7
    Jul 22, 2017
    57
    @formulahendry 嗨~. 我发现 powershell 中文乱码了.
    ps1 文件, 编码是 ucs2-le, 代码页是 1200
    设置
    ```
    "code-runner.runInTerminal": true,
    "code-runner.executorMap": {
    "powershell": "chcp 1200>nul && powershell -ExecutionPolicy ByPass -File"
    }
    ```
    输出是一行乱码: ��Ч����ҳ
    设置成 chcp 65001 可以输出, 只是中文当作 ansi 编码解析了.

    为什么我要把 ps1 文件保存为 ucs2-le 编码, 因为, powershell 好像不认 utf8 编码, 中文会乱码. 用 ucs2-le 就没事.
    jin7
    jin7
    Jul 23, 2017
    58
    我发现 chcp 1200 为无效代码页.
    但是我把文件保存为 utf8, 并且设置如下, 也没有用
    ```
    "code-runner.runInTerminal": true,
    "code-runner.executorMap": {
    "powershell": "chcp 65001>nul && powershell -ExecutionPolicy ByPass -File"
    }
    ```
    bestswifter
    bestswifter
    Mar 11, 2018
    59
    可否把 runCustomCommand 命令和 run 命令的快捷键设置为同一个呢?

    我有一个需求是,如果没有指定 customCommand,就按照 executorMap 里面的配置来执行,如果有 customCommand,则优先执行 customCommand。

    我知道 keybindings.json 里面有一个 when 字段,但是不知道该填什么值
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1686 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 96ms · UTC 23:49 · PVG 07:49 · LAX 15:49 · JFK 18:49
    ♥ Do have faith in what you're doing.