denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.15k stars 5.36k forks source link

Consider switch to reedline crate #13125

Closed bartlomieju closed 1 year ago

bartlomieju commented 2 years ago

Currently we use rustyline crate for the REPL. However there are shortcomings in that crate, mainly it gives us no control over "external prints".

If you have code like:

setInterval(() => {
  console.log("foo");
}, 1000);

Its output gonna be interleaved with prompt:

❯ deno
Deno 1.17.0
exit using ctrl+d or close()
> setInterval(() => console.log("foo"), 1000);
1
> barfoo
foo
foo

Uncaught ReferenceError: bar is not defined
    at <anonymous>:2:1
> foo
> bafoo
> barfoo
> barafoo
foo
foo
foo

Ideally the output would go into line above the prompt line.

https://docs.rs/reedline has all the necessary APIs to fit our purposes and seems to be more battle tested (it's the base for nushell.sh)

This switch would allow us to address: https://github.com/denoland/deno/issues/8049

CC @dsherret

sophiajt commented 2 years ago

Hi all - JT from the Nushell project.

Thanks for looking into reedline. I wanted to share a bit of "full disclosure" for reedline, as you're making your decision. Nushell currently, like deno, uses rustyline. We started up reedline, hopeful that it'd be a good replacement for rustyline for us. Currently, reedline is getting close (we're using it in our upcoming nushell engine rewrite to test it out), but there are a few gaps between it and reedline.

We've got a channel on the Nushell discord called #external-collab which is a great place to jump in and brainstorm with the Nushell and reedline folks about possible changes to reedline. We'd love to chat.

bartlomieju commented 2 years ago

Hi @jntrnr, thanks for reaching out!

We did some preliminary tests with reedline (CC @crowlKats) and found a major blocker at the moment, is that Reedline struct is neither Sync nor Send. In the REPL we're running the editor on a separate thread (becuase the editor interface is sync) and we use channels for completions (because Deno's LSP and executing code in V8 is an async operation).

I think we'll wait until engine-q and reedline are incorporated into main branch of nushell and get released before making the switch. That said, I'm a huge fan of both nushell and API for reedline and this is definitely something I want to explore in Q1 of 2022. I'll reach out on Discord for further conversation.

sophiajt commented 1 year ago

@bartlomieju - out of curiosity, which direction did you go for line editing?

bartlomieju commented 1 year ago

Hey @jntrnr, due to limited bandwidth we are sticking with rustyline for now, but we might revisit the topic in the future.