@@ -12,6 +12,7 @@ use std::sync::{
12use std::{collections::HashMap, process::Stdio};
12use std::{collections::HashMap, process::Stdio};
13use tokio::{
13use tokio::{
14 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
14 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
15 net::TcpStream,
16 net::TcpStream,
16 process::{Child, Command},
17 process::{Child, Command},
@@ -449,7 +450,12 @@ impl Client {
449 self.request_counter.fetch_add(1, Ordering::Relaxed)
450 self.request_counter.fetch_add(1, Ordering::Relaxed)
452− async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
456+ arguments: Option<Value>,
458+ ) -> Result<Option<Response>> {
453 let (callback_rx, mut callback_tx) = channel(1);
459 let (callback_rx, mut callback_tx) = channel(1);
455 let req = Request {
461 let req = Request {
@@ -464,10 +470,11 @@ impl Client {
464 .send(req)
470 .send(req)
465 .expect("Failed to send request to debugger");
471 .expect("Failed to send request to debugger");
467− callback_tx
474+ Ok(Some(callback_tx.recv().await.unwrap()?))
468− .recv()
475+ } else {
470− .expect("Failed to receive response")
477+ }
473 pub fn capabilities(&self) -> &DebuggerCapabilities {
480 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -494,25 +501,25 @@ impl Client {
496 let response = self
503 let response = self
497− .request("initialize".to_owned(), to_value(args).ok())
504+ .request("initialize".to_owned(), to_value(args).ok(), true)
498− .await?;
505+ .await?
499 self.capabilities = from_value(response.body.unwrap()).ok();
507 self.capabilities = from_value(response.body.unwrap()).ok();
504 pub async fn disconnect(&mut self) -> Result<()> {
512 pub async fn disconnect(&mut self) -> Result<()> {
505− self.request("disconnect".to_owned(), None).await?;
513+ self.request("disconnect".to_owned(), None, true).await?;
509 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
517 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
510 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
518 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
512− self.request("launch".to_owned(), to_value(args).ok())
520+ let res = self.request("launch".to_owned(), to_value(args).ok(), true);
515− initialized.recv().await;
521+ let ev = initialized.recv();
@@ -520,10 +527,9 @@ impl Client {
520 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
527 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
521 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
528 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
523− self.request("attach".to_owned(), to_value(args).ok())
530+ let res = self.request("attach".to_owned(), to_value(args).ok(), false);
526− initialized.recv().await;
531+ let ev = initialized.recv();
@@ -549,15 +555,17 @@ impl Client {
551 let response = self
557 let response = self
552− .request("setBreakpoints".to_owned(), to_value(args).ok())
558+ .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
553− .await?;
559+ .await?
554 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
561 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
556 Ok(body.map(|b| b.breakpoints).unwrap())
563 Ok(body.map(|b| b.breakpoints).unwrap())
559 pub async fn configuration_done(&mut self) -> Result<()> {
566 pub async fn configuration_done(&mut self) -> Result<()> {
560− self.request("configurationDone".to_owned(), None).await?;
567+ self.request("configurationDone".to_owned(), None, true)
@@ -565,8 +573,9 @@ impl Client {
565 let args = ContinueArguments { thread_id };
573 let args = ContinueArguments { thread_id };
567 let response = self
575 let response = self
568− .request("continue".to_owned(), to_value(args).ok())
576+ .request("continue".to_owned(), to_value(args).ok(), true)
569− .await?;
577+ .await?
571 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
580 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
@@ -585,8 +594,9 @@ impl Client {
587 let response = self
596 let response = self
588− .request("stackTrace".to_owned(), to_value(args).ok())
597+ .request("stackTrace".to_owned(), to_value(args).ok(), true)
589− .await?;
598+ .await?
591 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
601 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
@@ -594,7 +604,10 @@ impl Client {
596 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
606 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
597− let response = self.request("threads".to_owned(), None).await?;
608+ .request("threads".to_owned(), None, true)
599 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
612 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
@@ -605,8 +618,9 @@ impl Client {
605 let args = ScopesArguments { frame_id };
618 let args = ScopesArguments { frame_id };
607 let response = self
620 let response = self
608− .request("scopes".to_owned(), to_value(args).ok())
621+ .request("scopes".to_owned(), to_value(args).ok(), true)
609− .await?;
622+ .await?
611 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
625 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
@@ -623,8 +637,9 @@ impl Client {
625 let response = self
639 let response = self
626− .request("variables".to_owned(), to_value(args).ok())
640+ .request("variables".to_owned(), to_value(args).ok(), true)
627− .await?;
641+ .await?
629 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
644 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();