Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code runner #5141

Closed
1 task done
chlorocodes opened this issue Nov 7, 2022 · 12 comments
Closed
1 task done

Code runner #5141

chlorocodes opened this issue Nov 7, 2022 · 12 comments
Labels
editor Feedback for code editing, formatting, editor iterations, etc feature [core label]

Comments

@chlorocodes
Copy link

Check for existing issues

  • Completed

Is your feature request related to a problem?

No.

Describe the solution you'd like

I think it would be pretty cool to be able to execute code from within the editor without needing to manually run a node * or python * command from a terminal tab. Basically looking for something similar to VSCode's Code Runner extension.

If applicable, add mockups / screenshots to help present your vision of the feature

VSCode Code Runner

@chlorocodes chlorocodes added feature [core label] triage labels Nov 7, 2022
@JosephTLyons JosephTLyons added editor Feedback for code editing, formatting, editor iterations, etc and removed triage labels Nov 7, 2022
@nvoynov
Copy link

nvoynov commented Dec 8, 2023

Code runner is an essential feature for any text editor that pretends to be a developer's editor. In my Ruby development flow, I constantly hundreds of times a day make changes and run Ruby test scripts from Atom. I still prefer Atom's clean interface and theme having tried VS Code, Sublime, and even Helix.

Atom Script extension is still very convenient because when I run tests and see errors in the full-file-path:line-number format it gives me the ability to navigate exactly to the point just in milliseconds.

Sublime Text has it from the box, at least for C and Ruby - just press Ctrl+B. Atom Script Runner by Ctrl+Shift+B.

Another solution could be to add a sort of shell-commands with the ability to pass the reference to current file in the editor, sort of just ruby %full-path-to-the-current-file-in-editor%

"run-shell-with": [
  {  
     "name": "run Ruby",
     "args": [
        "ruby",
        "%full-path-to-the-current-file-in-editor%", 
        "some other options"
      ]
  },
  {
     "name": "rake test",
     "args": ["rake test"]
  }
]

@olegchir
Copy link

olegchir commented Feb 18, 2024

Hello, it's a very important feature. Of course, you can write your automation on top of AHK-Windows/X11-Linux/whatever, but it's way better to have at least an easy way to land a build-and-run shortcut

@Anthony-Eid
Copy link
Contributor

I'm interested in contributing to this issue, but would need some guidance. Could someone please point me in the right direction to start working on this?

@SomeoneToIgnore
Copy link
Contributor

Me and @osiewicz are working #7108

It is not planned to be as fancy as in the video initially, but soon™ we expect to have a way to have pyhonN some_script.py dynamic tasks in the corresponding modal.

@osiewicz works on that particular bit and things looked good so far, consider pairing with him if you want to work on this particular task.

@Anthony-Eid
Copy link
Contributor

I'm interested in pairing with @osiewicz, but I'm still relatively new to the open source community and don't know how I should go about doing that. Should I just send him a message asking to work with him or would it be more appropriate to comment on #7108 about it?

@osiewicz
Copy link
Contributor

Hey, yeah, tagging is enough; what timezone are you in?
I am in GMT+1 and I am (generally speaking) available between 10am and 6pm; if you're in US timezones I can also stay a bit longer, especially on Tuesdays and Thursdays.

@Anthony-Eid
Copy link
Contributor

I'm in EST so I think you're about 6 hours ahead of me.

Would you be free to pair up this Thursday?

@osiewicz
Copy link
Contributor

Yep! I've sent you a message on Discord, let's figure out the schedule there.

@berkaayildiz
Copy link

Hello, is there any updates regarding this issue?

SomeoneToIgnore added a commit that referenced this issue Apr 15, 2024
Part of #5141

* adds "run selection" and "run file" tasks for bash and Python.
* replaces newlines with `\n` symbols in the human-readable task labels
* properly escapes task command arguments when spawning the task in
terminal

Caveats:

* bash tasks will always use user's default shell to spawn the
selections, but they should rather respect the shebang line even if it's
not selected
* Python tasks will always use `python3` to spawn its tasks now, as
there's no proper mechanism in Zed to deal with different Python
executables

Release Notes:

- Added tasks for bash and Python to execute selections and open files
in terminal
@SomeoneToIgnore
Copy link
Contributor

#10548 (will be part of Zed 0.132) had added language tasks to Bash and Python, allowing to run a selection, or the opened file via user's default shell or python3 in it.
There are caveats (such as python3-only hardcode), but this is a start for basic cases which hopefully helps many people already.

Zed tasks can be customized and have access to editor selections, so other languages may be supported locally now already.
The tasks modal with all tasks applicable for the latest caret position is opened with task::Spawn action or a command panel, also there's a footer button to show the modal and task status:
image

What's missing so far:

  • more language support, preferably on the extension level.
  • more logic to better select an appropriate executable for all cases (e.g. python2 or a proper node binary)
  • "run task for current line" + corresponding UI for visibility — @osiewicz works on this and will use the same language task providers

Technically, the issue could be closed and the missing parts considered in follow-ups, but let's keep the issue open at least before the 0.132 is actually released.

@notpeter
Copy link
Member

Tasks have been out for a bit and so I'm going close this issue.

Feel free to open additional issues with enhancement requests for improving task functionality in Zed. See: Zed Tasks Documentation for more.


For reference, there is a default task for "execute selection" (as requested above) but if you want a custom version of the same (say using an alternate binary) you can easily do so using ZED_SELECTED_TEXT task variable:

// .zed/tasks.json
[
  {
    "label": "myvenv: execute selection",
    "command": "myvenv/bin/python3",
    "args": ["-c", "${ZED_SELECTED_TEXT}"]
    //"cwd": "/path/to/dir",
    //"env": { "foo": "bar" },
  }
]

Happy tasking!

@igniscyan
Copy link

@notpeter Sorry to necro this, but I followed another issue that mentioned the debugger feature request being bundled here - is an in client debugger something that's still in the pipeline or has that changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor Feedback for code editing, formatting, editor iterations, etc feature [core label]
Projects
None yet
Development

No branches or pull requests

10 participants