diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-10-02 07:14:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-02 01:14:55 +0200 |
commit | 4c779b5e8ca427faf24c26443a8054004827d450 (patch) | |
tree | ddb8ded427e4987f2edbb63c1be3661569e0d204 /cli/main.rs | |
parent | 5590b97670206df957c43742f47601356982c658 (diff) |
refactor(repl): use an inspector session (#7763)
This ports the REPL over to Rust and makes use of an inspector session to run a REPL on top of any isolate which lets make full use of rustylines various things like validators and completors without having to introduce a bunch of hard to test internal ops and glue code.
An accidental but good side effect of this is that the multiple line input we previously had is now an editable multi-line input prompt that is correctly stored in the history as a single entry.
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/cli/main.rs b/cli/main.rs index f888a6c6c..4546bc374 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -63,6 +63,7 @@ use crate::file_fetcher::SourceFileFetcher; use crate::file_fetcher::TextDocument; use crate::fs as deno_fs; use crate::global_state::GlobalState; +use crate::inspector::InspectorSession; use crate::media_type::MediaType; use crate::permissions::Permissions; use crate::worker::MainWorker; @@ -428,9 +429,26 @@ async fn run_repl(flags: Flags) -> Result<(), AnyError> { let main_module = ModuleSpecifier::resolve_url_or_path("./$deno$repl.ts").unwrap(); let global_state = GlobalState::new(flags)?; - let mut worker = MainWorker::new(&global_state, main_module); + let mut worker = MainWorker::new(&global_state, main_module.clone()); + (&mut *worker).await?; + + let inspector = worker + .inspector + .as_mut() + .expect("Inspector is not created."); + + let inspector_session = InspectorSession::new(&mut **inspector); + let repl = repl::run(&global_state, inspector_session); + + tokio::pin!(repl); + loop { - (&mut *worker).await?; + tokio::select! { + result = &mut repl => { + return result; + } + _ = &mut *worker => {} + } } } |