Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(repl): use an inspector session #7763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
043ee12
refactor(repl): use an inspector session
caspervonb Sep 30, 2020
5c0ed58
Lint
caspervonb Sep 30, 2020
f41db9c
Turn repl mode comment into a TODO comment
caspervonb Sep 30, 2020
b882005
Add real multi-line editing with a bracket validator
caspervonb Sep 30, 2020
203dd77
Remove repl flag from op start
caspervonb Sep 30, 2020
a286e29
Lint
caspervonb Sep 30, 2020
5335bc7
Format
caspervonb Sep 30, 2020
dbae724
Remove debug output on readline errors
caspervonb Sep 30, 2020
f2750a2
Fix flags tests
caspervonb Sep 30, 2020
7568a7e
Save and load history file
caspervonb Sep 30, 2020
06293a2
Ensure history file always exists
caspervonb Sep 30, 2020
4db45f5
Allow history load to fail
caspervonb Sep 30, 2020
98ccecd
Print errors to stderr
caspervonb Sep 30, 2020
36c659d
Support _ and _error
caspervonb Sep 30, 2020
0302a23
Break on globalThis.closed
caspervonb Sep 30, 2020
0e7bf5a
Format
caspervonb Sep 30, 2020
ad40189
Move close check to after eval to avoid printing the result of close()
caspervonb Sep 30, 2020
48e749b
Wrap and retry input
caspervonb Sep 30, 2020
a73b9b7
Ignore multiline test
caspervonb Sep 30, 2020
64d6e2a
Evaluate in strict mode
caspervonb Sep 30, 2020
90f4388
Disable validator for a minute
caspervonb Oct 1, 2020
922f7bc
Fixup
caspervonb Oct 1, 2020
8e6127d
Spawn blocking
caspervonb Oct 1, 2020
af1a4de
Re-enable validator
caspervonb Oct 1, 2020
fe38ac5
Fixup
caspervonb Oct 1, 2020
d43e17c
Explain retry mechanism
caspervonb Oct 1, 2020
e4d374b
Only wrap on things that look like it may be an object literal
caspervonb Oct 1, 2020
2559fa3
Lint
caspervonb Oct 1, 2020
3e7c724
More lint
caspervonb Oct 1, 2020
6548e21
Minor comment on helper struct
caspervonb Oct 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ rand = "0.7.3"
regex = "1.3.9"
ring = "0.16.15"
rustyline = { version = "6.3.0", default-features = false }
rustyline-derive = "0.3.1"
serde = { version = "1.0.116", features = ["derive"] }
sys-info = "0.7.0"
sourcemap = "6.0.1"
Expand Down
4 changes: 4 additions & 0 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub struct Flags {
pub no_remote: bool,
pub read_allowlist: Vec<PathBuf>,
pub reload: bool,
pub repl: bool,
pub seed: Option<u64>,
pub unstable: bool,
pub v8_flags: Option<Vec<String>>,
Expand Down Expand Up @@ -447,6 +448,7 @@ fn completions_parse(flags: &mut Flags, matches: &clap::ArgMatches) {

fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
runtime_args_parse(flags, matches, false);
flags.repl = true;
flags.subcommand = DenoSubcommand::Repl;
flags.allow_net = true;
flags.allow_env = true;
Expand Down Expand Up @@ -2142,6 +2144,7 @@ mod tests {
assert_eq!(
r.unwrap(),
Flags {
repl: true,
subcommand: DenoSubcommand::Repl,
allow_net: true,
allow_env: true,
Expand All @@ -2162,6 +2165,7 @@ mod tests {
assert_eq!(
r.unwrap(),
Flags {
repl: true,
subcommand: DenoSubcommand::Repl,
unstable: true,
import_map_path: Some("import_map.json".to_string()),
Expand Down
1 change: 1 addition & 0 deletions cli/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ impl v8::inspector::ChannelImpl for InspectorSession {
) {
let raw_message = message.unwrap().string().to_string();
let message = serde_json::from_str(&raw_message).unwrap();

self
.response_tx_map
.remove(&call_id)
Expand Down
22 changes: 20 additions & 2 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {}
}
}
}

Expand Down
1 change: 0 additions & 1 deletion cli/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
78 changes: 0 additions & 78 deletions cli/ops/repl.rs

This file was deleted.

2 changes: 0 additions & 2 deletions cli/ops/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading