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