on master help sign in
Revert "compat: don't wait for launch and attach response"
ae32159Dmitry Sharshakov
helix-dap/src/client.rs+28−43
@@ -12,7 +12,6 @@ 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− join,
16 net::TcpStream,
15 net::TcpStream,
17 process::{Child, Command},
16 process::{Child, Command},
18 sync::{
17 sync::{
@@ -450,12 +449,7 @@ impl Client {
450 self.request_counter.fetch_add(1, Ordering::Relaxed)
449 self.request_counter.fetch_add(1, Ordering::Relaxed)
451 }
450 }
452
451
453− async fn request(
454− &self,
455− command: String,
456− arguments: Option<Value>,
452+ async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
457− response: bool,
458− ) -> Result<Option<Response>> {
459 let (callback_rx, mut callback_tx) = channel(1);
453 let (callback_rx, mut callback_tx) = channel(1);
460
454
461 let req = Request {
455 let req = Request {
@@ -470,11 +464,10 @@ impl Client {
470 .send(req)
464 .send(req)
471 .expect("Failed to send request to debugger");
465 .expect("Failed to send request to debugger");
472
466
473− if response {
474− Ok(Some(callback_tx.recv().await.unwrap()?))
467+ callback_tx
475− } else {
468+ .recv()
476− Ok(None)
469+ .await
477− }
470+ .expect("Failed to receive response")
478 }
471 }
479
472
480 pub fn capabilities(&self) -> &DebuggerCapabilities {
473 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -501,25 +494,25 @@ impl Client {
501 };
494 };
502
495
503 let response = self
496 let response = self
504− .request("initialize".to_owned(), to_value(args).ok(), true)
497+ .request("initialize".to_owned(), to_value(args).ok())
505− .await?
498+ .await?;
506− .unwrap();
507 self.capabilities = from_value(response.body.unwrap()).ok();
499 self.capabilities = from_value(response.body.unwrap()).ok();
508
500
509 Ok(())
501 Ok(())
510 }
502 }
511
503
512 pub async fn disconnect(&mut self) -> Result<()> {
504 pub async fn disconnect(&mut self) -> Result<()> {
513− self.request("disconnect".to_owned(), None, true).await?;
505+ self.request("disconnect".to_owned(), None).await?;
514 Ok(())
506 Ok(())
515 }
507 }
516
508
517 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
509 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
518 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
510 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
519
511
520− let res = self.request("launch".to_owned(), to_value(args).ok(), false);
512+ self.request("launch".to_owned(), to_value(args).ok())
513+ .await?;
514+
521− let ev = initialized.recv();
515+ initialized.recv().await;
522− join!(res, ev).0?;
523
516
524 Ok(())
517 Ok(())
525 }
518 }
@@ -527,9 +520,10 @@ impl Client {
527 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
520 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
528 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
521 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
529
522
530− let res = self.request("attach".to_owned(), to_value(args).ok(), false);
523+ self.request("attach".to_owned(), to_value(args).ok())
524+ .await?;
525+
531− let ev = initialized.recv();
526+ initialized.recv().await;
532− join!(res, ev).0?;
533
527
534 Ok(())
528 Ok(())
535 }
529 }
@@ -555,17 +549,15 @@ impl Client {
555 };
549 };
556
550
557 let response = self
551 let response = self
558− .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
552+ .request("setBreakpoints".to_owned(), to_value(args).ok())
559− .await?
553+ .await?;
560− .unwrap();
561 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
554 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
562
555
563 Ok(body.map(|b| b.breakpoints).unwrap())
556 Ok(body.map(|b| b.breakpoints).unwrap())
564 }
557 }
565
558
566 pub async fn configuration_done(&mut self) -> Result<()> {
559 pub async fn configuration_done(&mut self) -> Result<()> {
567− self.request("configurationDone".to_owned(), None, true)
560+ self.request("configurationDone".to_owned(), None).await?;
568− .await?;
569 Ok(())
561 Ok(())
570 }
562 }
571
563
@@ -573,9 +565,8 @@ impl Client {
573 let args = ContinueArguments { thread_id };
565 let args = ContinueArguments { thread_id };
574
566
575 let response = self
567 let response = self
576− .request("continue".to_owned(), to_value(args).ok(), true)
568+ .request("continue".to_owned(), to_value(args).ok())
577− .await?
569+ .await?;
578− .unwrap();
579
570
580 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
571 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
581
572
@@ -594,9 +585,8 @@ impl Client {
594 };
585 };
595
586
596 let response = self
587 let response = self
597− .request("stackTrace".to_owned(), to_value(args).ok(), true)
588+ .request("stackTrace".to_owned(), to_value(args).ok())
598− .await?
589+ .await?;
599− .unwrap();
600
590
601 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
591 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
602
592
@@ -604,10 +594,7 @@ impl Client {
604 }
594 }
605
595
606 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
596 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
607− let response = self
608− .request("threads".to_owned(), None, true)
597+ let response = self.request("threads".to_owned(), None).await?;
609− .await?
610− .unwrap();
611
598
612 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
599 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
613
600
@@ -618,9 +605,8 @@ impl Client {
618 let args = ScopesArguments { frame_id };
605 let args = ScopesArguments { frame_id };
619
606
620 let response = self
607 let response = self
621− .request("scopes".to_owned(), to_value(args).ok(), true)
608+ .request("scopes".to_owned(), to_value(args).ok())
622− .await?
609+ .await?;
623− .unwrap();
624
610
625 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
611 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
626
612
@@ -637,9 +623,8 @@ impl Client {
637 };
623 };
638
624
639 let response = self
625 let response = self
640− .request("variables".to_owned(), to_value(args).ok(), true)
626+ .request("variables".to_owned(), to_value(args).ok())
641− .await?
627+ .await?;
642− .unwrap();
643
628
644 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
629 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
645
630