Skip to content

Tidy up the REPL main loop - #11655

Merged
stormasm merged 14 commits into
nushell:mainfrom
rtpg:tidy-repl
Jan 31, 2024
Merged

stormasm merged 14 commits into
nushell:mainfrom
rtpg:tidy-repl

Conversation

@rtpg

@rtpg rtpg commented Jan 28, 2024

Copy link
Copy Markdown
Contributor

While working on #11288 I was having some trouble tracking the main REPL loop, so I've sent in a bunch of tiny refactorings on this branch.

These are almost all of the "move code from one place to another" variety, and each commit is meant to be independent, except for the last one, which is trying to be a bit more clever to handle the decision of autocd'ing vs running a command. Feel free to just go through each commit and cherry pick the ones that look good.

This leads to evaluate_repl going from ending on line 715 to ending on line 395. Again, this is mostly just moving code around, but I think this set of changes will make other changes around juggling the stack to avoid cloning easier to review.

@fdncred

fdncred commented Jan 28, 2024

Copy link
Copy Markdown
Contributor

I'm generally ok with this refactoring, as long as nothing is broken. As a rule, we maintainers are against macros. The perf! macro could probably be converted to an fn and be fine though.

@rtpg

rtpg commented Jan 28, 2024 •

Copy link
Copy Markdown
Contributor Author

Would you be comfortable with losing the file line numbers on the perf log or something? The reason I went for the macro is so that we could use line! And friends and have it report the "right line". If I use a function instead, I end up with the same problem as the original code: having a function call with 6 arguments that will autoformat to being over 6 lines in the code.

I'm fine just reverting that part of the changes. I understand the aversion to macros.

@fdncred

fdncred commented Jan 28, 2024

Copy link
Copy Markdown
Contributor

Would you be comfortable with losing the file line numbers on the perf log or something?

Not really. I put that information in there so we'd know exactly who is saying what and where.

Maybe others won't mind perf!(), not sure.

@rtpg

rtpg commented Jan 29, 2024

Copy link
Copy Markdown
Contributor Author

I agree, and prefer having the line information. I've pushed up a revert for the perf macro change, so the (for my uses anyways) more important changes can move forward

@stormasm

Copy link
Copy Markdown
Contributor

@rtpg I like the flavor of what you are doing --- would you mind putting more documentation in the new methods you have created for example here are the ones I would like more information on what they are doing --- it will help others as they read this code in the future

  • do_shell_integration_finalize_command
  • parse_operation
  • do_history_meta_post_execution
  • do_history_meta_pre_execution
  • do_auto_cd

Also --- maybe in the next PR after this one --- you could bust out the above methods and others into another file possibly called

repl_helper.rs

or something to that effect...

Ideally the only method located inside repl.rs should be the ONE public function

pub fn evaluate_repl

As you are doing this work think about scoping issues and what it would take to drastically reduce the amount of code
here from an API perspective...

Imagine having a nu-cli that had a nice API that you could use to build up your very own CLI not called nu-cli

Imagine we had another crate called nu-cli-simple or nu-cli-lean and you wanted just the basic functionality without all of the bells and whistles that nushell throws in there...

It could be used for testing purposes just to do integration testing etc...

Not that we are doing that --- but think about the API calls that are needed more globally from a nu-cli perspective

The use case for this is that developers who are embedding nushell in their applications or hardware etc...

Do NOT WANT all of the cruft we throw in there to give the big GIANT Bells and whistles experience of nushell...

They just want to be able to parse and run the nu language and thats it with possibly even a simpler
Reedline experience...

Imagine a world where Reedline did not have menus / completions etc...
Or you could tailer Reedline not to have Menus and Completions

So you have this TINY cli that just parses / and evaluates and thats it...

I am open for more discussion on this topic because its something I think about a lot...

And many thanks for your effort 😄

@rtpg

rtpg commented Jan 31, 2024

Copy link
Copy Markdown
Contributor Author

@stormasm I'll try and write some comments. Honestly I'm not 100% sure what each block does, so I think I'll need some help in the review to make sure what I write is true.

As this is a refactor, I am avoiding changes to behavior or the like (parse_operation is the big change that requires a bit of staring at to realize it's equivalent modulo one extra string clone). But while working through this I'm hoping to identify some grand lines. But to be honest a lot of this stuff is really about a REPL in particular. Though some things are probably valuable details (some of the control code stuff) that can be used.

@stormasm

Copy link
Copy Markdown
Contributor

@rtpg I have been looking at this code myself for a long time hoping that someone like yourself would come along and take an interest in nu-cli and start to observe areas of improvement 😄

Any and all that you do is both clean up and improvement and its certainly much appreciated by the entire nushell community...

@rtpg

rtpg commented Jan 31, 2024

Copy link
Copy Markdown
Contributor Author

Alright, I added some comments and renamed some functions. I do plan on still being in this file, but I am not comfortable adding too many changes to this specific PR (want to minimize breakage worries on this one)

@stormasm

Copy link
Copy Markdown
Contributor

Alright, I added some comments and renamed some functions. I do plan on still being in this file, but I am not comfortable adding too many changes to this specific PR (want to minimize breakage worries on this one)

Agreed don't add more stuff --- lets get this current state landed as a PR and then we can consider the next step if you feel there is more work you would like to do...

Also we are getting close to our next release date of Feb 6 --- so since this code is so critical to the running of nushell --- its got to work with no detectable issues by our users on the main branch...

@stormasm
stormasm merged commit d40019a into nushell:main Jan 31, 2024
@stormasm

Copy link
Copy Markdown
Contributor

@rtpg thanks for doing this work --- I would hold off on more changes --- if you were thinking of doing them until a few days after our next release --- next week... We will be code freezing in a few days usually this weekend...

@rtpg
rtpg deleted the tidy-repl branch February 1, 2024 01:28
@hustcer hustcer added this to the v0.90.0 milestone Feb 3, 2024
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
While working on nushell#11288 I was having some trouble tracking the main REPL
loop, so I've sent in a bunch of tiny refactorings on this branch.

These are almost all of the "move code from one place to another"
variety, and each commit is meant to be independent, _except for the
last one_, which is trying to be a bit more clever to handle the
decision of autocd'ing vs running a command. Feel free to just go
through each commit and cherry pick the ones that look good.

This leads to `evaluate_repl` going from ending on line 715 to ending on
line 395. Again, this is mostly just moving code around, but I think
this set of changes will make other changes around juggling the stack to
avoid cloning easier to review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants