zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.08k stars 2.71k forks source link

Add run-selected-text to run (Julia) code snippets in the terminal #16102

Open christiankral opened 1 month ago

christiankral commented 1 month ago

Check for existing issues

Describe the feature

I am writing this feature request with the focus on Julia, but it is certainly not restrited to it.

Form my understanding this feture request ist neither covered by #5141 nor by #12598. The zed julia extension https://github.com/JuliaEditorSupport/zed-julia/issues/4#issuecomment-2130935682 seems to require a full project structure with toml file including package and version dependencies. In the testing stage of some Julia code it were advantageous to have the option to just select some code in the editor and execute it in the terminal next to it. Nothing else. A similar feature was implemented in Pulsar with in the "x-terminal" package: The Pulsar command to perform this action is: x-terminal:run-selected-text and its main advantage is its simplicty. If connected to a shortcut, e. g. CTRL + ALT + SHIFT + ENTER, it can be easily integrated into a quick testing procedure.

image

I guess this feature is not yet implemented in Zed.

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

No response

notpeter commented 1 month ago

As I understand it you're asking for multiple things:

  1. Better support for detecting a "default" Julia environment without requiring Project.toml.
  2. Support for executing selected blocks of Julia code.

The first is best filed as an issue on the zed-julia extension repo: https://github.com/JuliaEditorSupport/zed-julia/issues/

As for the second, does Thorsten's reply to the issue you mentioned (#12598) not satisfy this with tasks?

That's already possible with tasks, at least showing the output:

christiankral commented 1 month ago

As I understand it you're asking for multiple things:

  1. Better support for detecting a "default" Julia environment without requiring Project.toml.

Yes, right. My comment in https://github.com/JuliaEditorSupport/zed-julia/issues/4#issuecomment-2282894402 shall rather be summarized in a separate ticket with a specific feature request then.

  1. Support for executing selected blocks of Julia code.

How I understand tasks, they do not exactly match my needs. As the shell to be specifed may either be

  1. (default) Use the system's default terminal configuration in /etc/passwd
  2. A program
  3. A program with arguments

it seems not to be possible to just paste the selected text to an open terminal as shown in my screenshot.

christiankral commented 1 month ago

Let me add to:

  1. Support for executing selected blocks of Julia code.

A feature like run-selected-text should be applied the existing terminal, independent on what command line interfaces has been started. It may be Octave, Julia, or anything else. Therefore, the existing history of what selected text blocks have been run so far, is preserved.

On my opinion the task is not flexible enough as I have to specify the shell or program explicitely. The run-selected-text is a more simple and flexible approach.

piechologist commented 3 weeks ago

I agree that a new action like editor::SendSelectedTextToInternalTerminal would satisfy many use cases.

@christiankral: as a hacky workaround, you could put something like the following code into your keymap.json:

[{
    "context": "Editor && mode == full",
    "bindings": {
        "cmd-y": ["workspace::SendKeystrokes", "cmd-c ctrl-` cmd-v enter"]
    }
}]

This copies the selection or the whole line to the pasteboard, switches to the terminal pane, and pastes the clipboard.

You can make more bindings that copy'n'paste the whole paragraph or the enclosing block.

christiankral commented 3 weeks ago

Thanks @piechologist for your key stroke proposal.