Code Monkey home page Code Monkey logo

io-runner's Introduction

IO Runner WIP⚠️

简体中文

Visual Studio Marketplace Version

Simplifies single-file code execution in VSCode.

  • Execute single-file code quickly.
  • Redirects input/output to separate views.
  • Execute launch configurations from launch.json and tasks from tasks.json.
  • Support VSCode's configuration variables in configuration. (By using connor4312/vscode-variables, not fully implemented. VSCode does not support it natively).
  • Automatically choose launch configurations based on file extensions, maintaining independent context environments for each file(non-persistent storage).
  • Automatically adapts to any theme in VSCode via CSS variables for better native compatibility.
  • more...

This extension may still have the following issues to be resolved:

  • Due to executing native tasks in VSCode, it is significantly slower than running commands directly.
    • Consider manually executing tasks by parsing the task configuration.
  • CodeMirror has been introduced as an editor, but it seems unnecessary.
    • Consider simulating some features through a textarea would suffice, but for large texts, a virtual view/line number mechanism needs to be implemented.
    • Pray that VSCode provides Webview with the ability to use native editors.
  • The pause mechanism for file execution is not elegant enough.

Configuration Guide

Currently, this extension is NOT ready to use out of the box. It depends on configurations in launch.json and tasks specified in tasks.json.

io-runner.launchMap

Map file extensions to launch configuration names, for example:

"io-runner.launchMap": {
    "c": [ "(lldb) Launch" ],
    "cpp": [ "(lldb) Launch" ]
}

io-runner.launchInterpreter

Map the type of launch configuration to the interpreter for interpreted languages, for example:

"io-runner.launchInterpreter": {
    "python": "python3",
    "node": "node",
}

io-runner.defaultEncoding

Default encoding for input/output. If you are using Windows with non-English language, you may need to set it to the encoding corresponding to your system language to display the correct language characters.

For example, Simplified Chinese users may need to set it to gbk. Japanese users may need to set it to shift_jis.

The values and their explanations can be selected directly in the settings(UI). You can also refer to TextDecoder: encoding property or package.json for more detailed information.

io-runner.timeout

The maximum time allowed for the program to run. If the program does not complete within the specified time, it will be forcibly terminated.

Unit: milliseconds

Default: 10000 (10 seconds)

Examples

For a better experience, it is better to set reveal in presentation to slient in the corresponding task in tasks.json.

    "presentation": {
        "reveal": "never"
    }, 

Compiled Languages

For compiled languages, take C/C++ as an example, if you have the following launch configuration:

{
    "type": "lldb",
    "request": "launch",
    "name": "(lldb) Launch", // The value of name here corresponds to the value in launchMap below
    "preLaunchTask": "buildG++",
    "postDebugTask": "removeDevFolder",
    "program": "${fileDirname}/.dev/${fileBasenameNoExtension}.out",
    "args": [],
    "cwd": "${fileDirname}",
}

You need to add the following to io-runner.launchMap:

"io-runner.launchMap": {
    "c": [ "(lldb) Launch" ],
    "cpp": [ "(lldb) Launch" ]
}

When you open the IO Runner panel in a C/C++ file, you can choose (lldb) Launch to start the process. The extension will automatically execute the buildG++ task (preLaunchTask), then run the output file specified in the program field. Finally, it will execute the removeDevFolder task (postDebugTask).

Interpreted Languages

For languages that require an interpreter, such as Python, you have the following in launch.json:

{
    "type": "python", // The value of type here corresponds to the key of the interpreter below
    "request": "launch",
    "name": "Python: Current File",
    "program": "${file}",
    "console": "integratedTerminal"
}

You still need to configure in io-runner.launchMap:

"io-runner.launchMap": {
    "py": [ "Python: Current File" ],
}

Also, You need to configure in io-runner.launchInterpreter with the interpreter command matching the type field:

"io-runner.launchInterpreter": {
    "python": "python3",
}

Now, in a Python file, when you open the IO Runner panel, you can choose Python: Current File to start. The extension will automatically execute the python3 command, running the current file.

Commands

  • io-runner.run - Execute the current file
  • io-runner.stop - Stop the current execution
  • io-runner.panel.focus - Focus on the IO Runner panel

You can increase efficiency by binding these commands to shortcut keys.

Credits

The project is heavily inspired by CmdBlockZQG's OI Runner.

Some components and design tokens are from vscode-webview-ui-toolkit to maintain a consistent appearance with VSCode's interface.

I employ microsoft/fast to develop the frontend interface because of its lightweight design, seamlessly integrated with vscode-webview-ui-toolkit's components.

License

MIT License © 2023 maxchang3

This project is initialized by using the template starter-vscode.

io-runner's People

Contributors

maxchang3 avatar renovate[bot] avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

io-runner's Issues

Chinese Character Decoding Error on Windows

Problem Description

In the Windows environment, there is an issue with the Chinese character output decoding error. After conducting tests, it appears to be related to the use of UTF-8 encoding by TextDecoder. It may be necessary to determine the encoding based on the environment or detection from text.

Testing

The problem can be resolved by changing the encoding to GBK. However, even after this modification, the stdout concatenated in the endRun within executeProgram still appears as gibberish. Therefore, it is recommended to uniformly store the output in an ArrayBuffer in the final output of executeProgram for easier and consistent decoding.

Note

The purpose of overwriting stdout after endRun is to address the following issue:

During extensive text output, the standard output stream may be processed in fragments. To enhance the visual perception of running speed, partial content can be displayed before completion. However, if the standard output stream is sent too quickly, leading to incomplete processing of logic inserted into the front-end output box, the actual execution may have already finished. In such cases, the final result should be promptly displayed.

This design has some issues that may be addressed in future optimizations or removal.


The above is a translation of the original text, which reads as follows:

Windows 下中文输出乱码

问题描述

在 Windows 环境下,中文输出出现乱码问题。经过测试发现,与 TextDecoder 使用 UTF-8 编码有关,可能需要根据环境判断使用编码,或者从文本中检测。

测试

通过修改编码为 GBK 可以解决问题。然而,在 endRun 中,executeProgram 拼接的 stdout 仍然为乱码。因此,建议在 executeProgram 的最后输出中,统一使用 ArrayBuffer 进行存储,以便更方便地进行统一解码。

在 endRun 后覆盖一次 stdout 的目的是解决以下问题:

在大量文本输出时,标准输出流可能会进行分片处理。为了提高视觉上的运行速度,可以在生成部分内容后先显示出来。然而,如果标准输出流的发送速度过快,导致插入到前端输出框的逻辑处理还未完成时,实际上运行已经结束。此时应即时呈现最终结果。

这个设计存在一些问题,可能会在后续优化或取消。

Make encoding optional

Currently, Windows employs legacy encoding (like GBK, JIS) for many languages (like Chinese / Japanese) instead of Unicode. While it is possible to switch the default encoding to UTF-8, this may lead to various complications.

Additionally, adjusting the terminal encoding is not a step most users are unlikely to do. Hence, providing an optional encoding feature is a preferable approach.

Better User Experience in encoding selection

To enhance user experience further, we propose the implementation of automatic encoding detection or a user prompt for encoding selection. This feature would contribute to a more seamless and user-friendly encoding experience.

Command send and view switching logic

Currently, when a program runs, the results are sent to the frontend and written to the current view. However, if a user switches from Program A to Program B before A's results are received, A's results might be written into B's context, causing data confusion.

Requirements

Command Sending Logic: Each command should include the current view information to ensure results are written to the correct view context.
Front-End Handling: The front-end should verify the view information in the results before writing them to the view.

Current Logic

Run a program and send results to the front end.
The front end writes results to the current view.

Issue

Switching from Program A to Program B before A's results are received causes A's results to be written into B's context.

Expected Behavior

Each command includes view information.

The front end writes data to matching objects by view information.
Frontend updates view information upon switching.

Python - Improved Conda/Virtual Environment User Experience

Problem Description

Currently, when using virtual environments such as Conda in Python, IO Runner fails to automatically activate the environment, requiring users to manually specify the path.


The above is a translation of the original text, which reads as follows:

目前 Python 如果使用了 Conda 等虚拟环境,IO Runner 无法自动激活环境,需要用户手动指定路径。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.