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.31k stars 2.74k forks source link

Run single function OR highlighted code #8344

Open RustoMCSpit opened 6 months ago

RustoMCSpit commented 6 months ago

Check for existing issues

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

jansol commented 6 months ago

How would you pass arguments to the function?

RustoMCSpit commented 6 months ago

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 commented 6 months ago

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

jansol commented 6 months ago

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 commented 6 months ago

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

no, original idea

JosephTLyons commented 6 months ago

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.

RustoMCSpit commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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

RustoMCSpit commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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 commented 2 months ago

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 commented 2 months ago

sorry to come to this discussion late

no apologies needed!

RustoMCSpit commented 2 months ago

image it could look something like this dropdown

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