on master help sign in
A request always needs to have a response, per spec (the body can be empty)
6225401Blaž Hrastnik
helix-dap/src/client.rs+19−38
@@ -505,12 +505,7 @@ impl Client {
505 self.request_counter.fetch_add(1, Ordering::Relaxed)
505 self.request_counter.fetch_add(1, Ordering::Relaxed)
506 }
506 }
507
507
508− async fn request(
509− &self,
510− command: String,
511− arguments: Option<Value>,
508+ async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
512− response: bool,
513− ) -> Result<Option<Response>> {
514 let (callback_rx, mut callback_tx) = channel(1);
509 let (callback_rx, mut callback_tx) = channel(1);
515
510
516 let req = Request {
511 let req = Request {
@@ -524,11 +519,7 @@ impl Client {
524 .send(req)
519 .send(req)
525 .expect("Failed to send request to debugger");
520 .expect("Failed to send request to debugger");
526
521
527− if response {
528− Ok(Some(callback_tx.recv().await.unwrap()?))
522+ Ok(callback_tx.recv().await.unwrap()?)
529− } else {
530− Ok(None)
531− }
532 }
523 }
533
524
534 pub fn capabilities(&self) -> &DebuggerCapabilities {
525 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -555,23 +546,22 @@ impl Client {
555 };
546 };
556
547
557 let response = self
548 let response = self
558− .request("initialize".to_owned(), to_value(args).ok(), true)
549+ .request("initialize".to_owned(), to_value(args).ok())
559− .await?
550+ .await?;
560− .unwrap();
561 self.capabilities = from_value(response.body.unwrap()).ok();
551 self.capabilities = from_value(response.body.unwrap()).ok();
562
552
563 Ok(())
553 Ok(())
564 }
554 }
565
555
566 pub async fn disconnect(&mut self) -> Result<()> {
556 pub async fn disconnect(&mut self) -> Result<()> {
567− self.request("disconnect".to_owned(), None, true).await?;
557+ self.request("disconnect".to_owned(), None).await?;
568 Ok(())
558 Ok(())
569 }
559 }
570
560
571 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
561 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
572 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
562 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
573
563
574− let res = self.request("launch".to_owned(), to_value(args).ok(), true);
564+ let res = self.request("launch".to_owned(), to_value(args).ok());
575 let ev = initialized.recv();
565 let ev = initialized.recv();
576 join!(res, ev).0?;
566 join!(res, ev).0?;
577
567
@@ -581,7 +571,7 @@ impl Client {
581 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
571 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
582 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
572 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
583
573
584− let res = self.request("attach".to_owned(), to_value(args).ok(), false);
574+ let res = self.request("attach".to_owned(), to_value(args).ok());
585 let ev = initialized.recv();
575 let ev = initialized.recv();
586 join!(res, ev).0?;
576 join!(res, ev).0?;
587
577
@@ -609,17 +599,15 @@ impl Client {
609 };
599 };
610
600
611 let response = self
601 let response = self
612− .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
602+ .request("setBreakpoints".to_owned(), to_value(args).ok())
613− .await?
603+ .await?;
614− .unwrap();
615 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
604 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
616
605
617 Ok(body.map(|b| b.breakpoints).unwrap())
606 Ok(body.map(|b| b.breakpoints).unwrap())
618 }
607 }
619
608
620 pub async fn configuration_done(&mut self) -> Result<()> {
609 pub async fn configuration_done(&mut self) -> Result<()> {
621− self.request("configurationDone".to_owned(), None, true)
610+ self.request("configurationDone".to_owned(), None).await?;
622− .await?;
623 Ok(())
611 Ok(())
624 }
612 }
625
613
@@ -627,9 +615,8 @@ impl Client {
627 let args = ContinueArguments { thread_id };
615 let args = ContinueArguments { thread_id };
628
616
629 let response = self
617 let response = self
630− .request("continue".to_owned(), to_value(args).ok(), true)
618+ .request("continue".to_owned(), to_value(args).ok())
631− .await?
619+ .await?;
632− .unwrap();
633
620
634 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
621 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
635
622
@@ -648,9 +635,8 @@ impl Client {
648 };
635 };
649
636
650 let response = self
637 let response = self
651− .request("stackTrace".to_owned(), to_value(args).ok(), true)
638+ .request("stackTrace".to_owned(), to_value(args).ok())
652− .await?
639+ .await?;
653− .unwrap();
654
640
655 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
641 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
656
642
@@ -658,10 +644,7 @@ impl Client {
658 }
644 }
659
645
660 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
646 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
661− let response = self
662− .request("threads".to_owned(), None, true)
647+ let response = self.request("threads".to_owned(), None).await?;
663− .await?
664− .unwrap();
665
648
666 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
649 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
667
650
@@ -672,9 +655,8 @@ impl Client {
672 let args = ScopesArguments { frame_id };
655 let args = ScopesArguments { frame_id };
673
656
674 let response = self
657 let response = self
675− .request("scopes".to_owned(), to_value(args).ok(), true)
658+ .request("scopes".to_owned(), to_value(args).ok())
676− .await?
659+ .await?;
677− .unwrap();
678
660
679 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
661 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
680
662
@@ -691,9 +673,8 @@ impl Client {
691 };
673 };
692
674
693 let response = self
675 let response = self
694− .request("variables".to_owned(), to_value(args).ok(), true)
676+ .request("variables".to_owned(), to_value(args).ok())
695− .await?
677+ .await?;
696− .unwrap();
697
678
698 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
679 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
699
680