summaryrefslogtreecommitdiff
path: root/cli/ops
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-10-02 07:14:55 +0800
committerGitHub <noreply@github.com>2020-10-02 01:14:55 +0200
commit4c779b5e8ca427faf24c26443a8054004827d450 (patch)
treeddb8ded427e4987f2edbb63c1be3661569e0d204 /cli/ops
parent5590b97670206df957c43742f47601356982c658 (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/ops')
-rw-r--r--cli/ops/mod.rs1
-rw-r--r--cli/ops/repl.rs78
-rw-r--r--cli/ops/runtime.rs2
3 files changed, 0 insertions, 81 deletions
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs
index c6d5cc1dc..b1ec5c344 100644
--- a/cli/ops/mod.rs
+++ b/cli/ops/mod.rs
@@ -16,7 +16,6 @@ pub mod permissions;
pub mod plugin;
pub mod process;
pub mod random;
-pub mod repl;
pub mod runtime;
pub mod runtime_compiler;
pub mod signal;
diff --git a/cli/ops/repl.rs b/cli/ops/repl.rs
deleted file mode 100644
index a2c26b2ab..000000000
--- a/cli/ops/repl.rs
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
-use crate::repl;
-use crate::repl::Repl;
-use deno_core::error::bad_resource_id;
-use deno_core::error::AnyError;
-use deno_core::serde_json;
-use deno_core::serde_json::json;
-use deno_core::serde_json::Value;
-use deno_core::BufVec;
-use deno_core::OpState;
-use deno_core::ZeroCopyBuf;
-use serde::Deserialize;
-use std::cell::RefCell;
-use std::rc::Rc;
-use std::sync::Arc;
-use std::sync::Mutex;
-
-pub fn init(rt: &mut deno_core::JsRuntime) {
- super::reg_json_sync(rt, "op_repl_start", op_repl_start);
- super::reg_json_async(rt, "op_repl_readline", op_repl_readline);
-}
-
-struct ReplResource(Arc<Mutex<Repl>>);
-
-#[derive(Deserialize)]
-#[serde(rename_all = "camelCase")]
-struct ReplStartArgs {
- history_file: String,
-}
-
-fn op_repl_start(
- state: &mut OpState,
- args: Value,
- _zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, AnyError> {
- let args: ReplStartArgs = serde_json::from_value(args)?;
- debug!("op_repl_start {}", args.history_file);
- let history_path = {
- let cli_state = super::global_state(state);
- repl::history_path(&cli_state.dir, &args.history_file)
- };
- let repl = repl::Repl::new(history_path);
- let resource = ReplResource(Arc::new(Mutex::new(repl)));
- let rid = state.resource_table.add("repl", Box::new(resource));
- Ok(json!(rid))
-}
-
-#[derive(Deserialize)]
-struct ReplReadlineArgs {
- rid: i32,
- prompt: String,
-}
-
-async fn op_repl_readline(
- state: Rc<RefCell<OpState>>,
- args: Value,
- _zero_copy: BufVec,
-) -> Result<Value, AnyError> {
- let args: ReplReadlineArgs = serde_json::from_value(args)?;
- let rid = args.rid as u32;
- let prompt = args.prompt;
- debug!("op_repl_readline {} {}", rid, prompt);
- let repl = {
- let state = state.borrow();
- let resource = state
- .resource_table
- .get::<ReplResource>(rid)
- .ok_or_else(bad_resource_id)?;
- resource.0.clone()
- };
- tokio::task::spawn_blocking(move || {
- let line = repl.lock().unwrap().readline(&prompt)?;
- Ok(json!(line))
- })
- .await
- .unwrap()
-}
diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs
index b1eddc265..3f7398479 100644
--- a/cli/ops/runtime.rs
+++ b/cli/ops/runtime.rs
@@ -4,7 +4,6 @@ use crate::colors;
use crate::metrics::Metrics;
use crate::permissions::Permissions;
use crate::version;
-use crate::DenoSubcommand;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
@@ -41,7 +40,6 @@ fn op_start(
"noColor": !colors::use_color(),
"pid": std::process::id(),
"ppid": ppid(),
- "repl": gs.flags.subcommand == DenoSubcommand::Repl,
"target": env!("TARGET"),
"tsVersion": version::TYPESCRIPT,
"unstableFlag": gs.flags.unstable,