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

Run single function OR highlighted code #8344

Open
1 task done
RustoMCSpit opened this issue Feb 24, 2024 · 24 comments
Open
1 task done

Run single function OR highlighted code #8344

RustoMCSpit opened this issue Feb 24, 2024 · 24 comments
Labels
enhancement [core label] potential extension Functionality that could be implemented as an extension (consider moving to community extensions) terminal Feedback for terminal integration, shell commands, etc

Comments

@RustoMCSpit
Copy link

Check for existing issues

  • Completed

Describe the feature

So you'd highlight a function via highlighting it with your mouse and then hit something like F6 (or maybe right click its name, whatever) and then you'd be prompted in the terminal to input the values of all the arguments and it would show you what the function returned as well as outputted (etc.). Useful debugging feature.

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

No response

@RustoMCSpit RustoMCSpit added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Feb 24, 2024
@jansol
Copy link
Contributor

jansol commented Feb 25, 2024

How would you pass arguments to the function?

@RustoMCSpit
Copy link
Author

How would you pass arguments to the function?

i said 'prompted in the terminal'? not sure whats not being communicated here sorry.

take the below pseudo code

def coinToss (color, amount, speed):
CODE HERE

the terminal would be prompt me for all parameters (someone else can figure out if we should make the user define the variable type while inputting too)
Insert color:
Insert amount:
Insert speed:

and it would then show the outputs of all variables and what returned.

if the function is recursive it would display each recursuions values and if the function had args (undefined amount of parameters) the terminal would ask how many you want to put in

or maybe have it just display return output, or have it as an option for the user. general idea

@SomeoneToIgnore
Copy link
Contributor

Do you have any examples from other ide/editors that support this feature?

@jansol
Copy link
Contributor

jansol commented Feb 25, 2024

i said 'prompted in the terminal'? not sure whats not being communicated here sorry.

Ah, sorry. Seems I skipped a line while reading.

@SomeoneToIgnore One similar thing I can immediately think of is the Matlab GUI where you have a panel with an editable real-time listing of variables in global scope, which will be in force when you run code snippets.

@RustoMCSpit
Copy link
Author

Do you have any examples from other ide/editors that support this feature?

no, original idea

@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Feb 27, 2024

It seems like this feature would require us to build custom support for every language. For example, for a single Rust function, we would need to hoist it into some compilable project so that we could run it. It seems like a huge lift to get that to work for one language, let alone many.

@JosephTLyons JosephTLyons added terminal Feedback for terminal integration, shell commands, etc potential extension Functionality that could be implemented as an extension (consider moving to community extensions) and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Feb 27, 2024
@RustoMCSpit
Copy link
Author

It seems like this feature would require us to build custom support for every language. For example, for a single Rust function, we would need to hoist it into some compilable project so that we could run it. It seems like a huge lift to get that to work for one language, let alone many.

*not every language is compiled

@JosephTLyons
Copy link
Collaborator

It seems like this feature would require us to build custom support for every language. For example, for a single Rust function, we would need to hoist it into some compilable project so that we could run it. It seems like a huge lift to get that to work for one language, let alone many.

*not every language is compiled

Right, a compiled language would need to be compiled, an interpreted language would need an interpreter / repl.

@RustoMCSpit
Copy link
Author

It seems like a huge lift to get that to work for one language, let alone many.

well if the interpreter can read the whole project, it can read a single function too. compiled languages would cause issue however. am i missing something here

@mrnugget
Copy link
Member

I think a good first step would be the ability to "pipe" selected text (or a syntactic node) to an external program. We could do that via tasks even. So say you select text, you hit cmd-shift-p, use task: spawn task with stdin (or whatever) and type in ruby (or whatever) and that ruby process would receive the given selection as stdin.

@RustoMCSpit
Copy link
Author

RustoMCSpit commented Feb 29, 2024

to an external program.

as long as it works with the virtual environment and has access to all modules and files thats fine

So say you select text

well the idea was just for functions but selected texts works too, we should still have the right click a function and have a "run function" option

type in ruby

by default, it should just use the interpreter of whatever the rest of the file sees. i feel like inputting a different interpreter is pretty niche but still should be considered

I think a good first step would be the ability to "pipe" selected text (or a syntactic node) to an external program. We could do that via tasks even. So say you select text, you hit cmd-shift-p, use task: spawn task with stdin (or whatever) and type in ruby (or whatever) and that ruby process would receive the given selection as stdin.

sounds fine to me but what about handling of recursive functions or functions with an undefined amount of parameters, etc.? do we just show recursion graphs and have a certain string to stop inputting?

@JosiahParry
Copy link

Right, a compiled language would need to be compiled, an interpreted language would need an interpreter / repl.

I think this is really what I'm after. I write Rust and want to be able to run cargo check with a key stroke and when I write R or python I want to be able to execute code in my repl with cmd + enter

@RustoMCSpit RustoMCSpit changed the title Run single function Run single function OR highlighted code Mar 1, 2024
@RustoMCSpit
Copy link
Author

I've changed the title. Now we're going with right click (secondary click) of a function name or selected code.

@RustoMCSpit
Copy link
Author

I've changed the title. Now we're going with right click (secondary click) of a function name or selected code.

just to be clear, zed does have a 'run current script in the integrated terminal' like vscode right?

@RustoMCSpit
Copy link
Author

I think this is really what I'm after. I write Rust and want to be able to run cargo check with a key stroke and when I write R or python I want to be able to execute code in my repl with cmd + enter

rust is trickier by nature as it's compiled, it's doable though if the devs spend time on it. interpreted is much easier.

@JosiahParry
Copy link

I think this is really what I'm after. I write Rust and want to be able to run cargo check with a key stroke and when I write R or python I want to be able to execute code in my repl with cmd + enter

rust is trickier by nature as it's compiled, it's doable though if the devs spend time on it. interpreted is much easier.

Using the development tasks is making it easier. Would be great if the tasks can be bound to keystrokes

@gsamat
Copy link

gsamat commented Apr 13, 2024

I want to reiterate that VS Code has RunSelectedText feature which is very useful for shell-wrangling (as mentioned in issue #8656 which is closed as duplicate to this). Instead of editing commands directly in Terminal, you edit your shell code in a good editor and ability to run it via single command is super useful.

In this Issue, however, there is a need for a 'data input interface', which might be additional work. Maybe keep them separate?

@polymorphicengine
Copy link

sorry to come to this discussion late, but i have one more suggestion:
it would be great if you could not only run selected code, but also just a line or 'block' of code, where a block is defined by several lines without any free lines inbetween. this is very useful in live coding

@RustoMCSpit
Copy link
Author

sorry to come to this discussion late

no apologies needed!

@RustoMCSpit
Copy link
Author

image
it could look something like this dropdown

https://youtu.be/X0OylwLzBQw?si=VgtX9gqr-6siTypn&t=387

@RustoMCSpit
Copy link
Author

I want to reiterate that VS Code has RunSelectedText feature which is very useful for shell-wrangling (as mentioned in issue #8656 which is closed as duplicate to this). Instead of editing commands directly in Terminal, you edit your shell code in a good editor and ability to run it via single command is super useful.

In this Issue, however, there is a need for a 'data input interface', which might be additional work. Maybe keep them separate?

can you include a screen recording of that?

@RustoMCSpit
Copy link
Author

In this Issue, however, there is a need for a 'data input interface', which might be additional work. Maybe keep them separate?

are you sure? they seem related to me

@ToddMCr
Copy link

ToddMCr commented Dec 1, 2024

For those who want to run highlighted text, this is working well for me in ~/.config/zed/keymap.json:

{
    "context": "Editor",
    "bindings": {
      "cmd-enter": ["workspace::SendKeystrokes", "cmd-c ctrl-` cmd-v enter"]
    }
  }

(found from #16102 (comment))

@mcabbott
Copy link

Thanks, that's great!

Is there any way to make it work with the terminal on the right? I wrote a longer comment about this in #16102, perhaps best to discuss there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] potential extension Functionality that could be implemented as an extension (consider moving to community extensions) terminal Feedback for terminal integration, shell commands, etc
Projects
None yet
Development

No branches or pull requests

10 participants