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

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

Open
1 task done
christiankral opened this issue Aug 12, 2024 · 7 comments
Open
1 task done
Labels
enhancement [core label] language An umbrella label for all programming languages syntax behaviors

Comments

@christiankral
Copy link

Check for existing issues

  • Completed

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 JuliaEditorSupport/zed-julia#4 (comment) 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
Copy link
Member

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:

@notpeter notpeter added awaiting info Issue that needs more information from the user language An umbrella label for all programming languages syntax behaviors and removed triage labels Aug 12, 2024
@christiankral
Copy link
Author

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 JuliaEditorSupport/zed-julia#4 (comment) 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
Copy link
Author

christiankral commented Aug 12, 2024

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
Copy link

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
Copy link
Author

Thanks @piechologist for your key stroke proposal.

@JosephTLyons JosephTLyons removed the awaiting info Issue that needs more information from the user label Oct 13, 2024
@mcabbott
Copy link

mcabbott commented Dec 30, 2024

Thanks for this hint, @piechologist

This opens a new terminal in the Bottom Dock, if one is not present. The same as View > Terminal Panel, obviously enough since cmd-c ctrl-` is its shortcut.

However, if I drag this terminal to the Right Dock a split of the main pane? (where I want it, for reasons of space) then it is no longer used, and instead I get another terminal in the bottom dock.

Is there any way around that? Would it be reasonable to change the behaviour of View > Terminal Panel to move focus to the most recently used terminal, in any dock, rather than the most recently used one within the bottom dock?

Edit, possibly #21144 describes the same issue. That about "tasks" and setting use_new_terminal=false, but perhaps View > Terminal Panel uses the same code. Adding "use_new_terminal": false to settings.json does not seem to change anything.

@piechologist
Copy link

Is there any way around that? Would it be reasonable to change the behaviour of View > Terminal Panel to move focus to the most recently used terminal, in any dock, rather than the most recently used one within the bottom dock?

Edit, possibly #21144 describes the same issue. That about "tasks" and setting use_new_terminal=false, but perhaps View > Terminal Panel uses the same code. Adding "use_new_terminal": false to settings.json does not seem to change anything.

I can't find an action that would focus the most recently used terminal. When I drag the terminal to the right it occupies a second workspace pane. Then, I can switch between the editor cmd-1 and the terminal cmd-2.

I tried the binding "cmd-c cmd-2 cmd-v enter" which runs the code but:

  • the terminal must already be open on the right or things get messed up (try it with a dummy file)
  • there must be exactly two panes (if you split the editor, the terminal would be in a third pane cmd-3)

IMO, this approach is too error prone to be usable.

I assume a solution to the issue you linked to wouldn't help in our case as it's about tasks.

Hopefully, Zed will gain an API for those kinds of things (dreaming of new features in 2025 😉). BTW, I use similar key bindings and an external terminal glued to Zed with some macOS scripting. I find Zed's terminal and its integration too limited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] language An umbrella label for all programming languages syntax behaviors
Projects
None yet
Development

No branches or pull requests

5 participants