on master help sign in
Revert "compat: don't wait for launch and attach response"

This reverts commit 766e3380622e2c7ddf5051ed672b78ece8d99f1f. Not required for lldb-vscode

commitae321592479545b3d86319daf2527c76ba46c0c4 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSat 14 Aug 2021, 14:01 (5 years ago) parent4f2b8fb
1 file changed+28−43
helix-dap/src/client.rs+28−43
helix-dap/src/client.rs+28−43
@@ -12,7 +12,6 @@ use std::sync::{
1212use std::{collections::HashMap, process::Stdio};
1313use tokio::{
1414 io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
15− join,
1615 net::TcpStream,
1716 process::{Child, Command},
1817 sync::{
@@ -450,12 +449,7 @@ impl Client {
450449 self.request_counter.fetch_add(1, Ordering::Relaxed)
451450 }
452451
453− async fn request(
454− &self,
455− command: String,
456− arguments: Option<Value>,
457− response: bool,
458− ) -> Result<Option<Response>> {
452+ async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
459453 let (callback_rx, mut callback_tx) = channel(1);
460454
461455 let req = Request {
@@ -470,11 +464,10 @@ impl Client {
470464 .send(req)
471465 .expect("Failed to send request to debugger");
472466
473− if response {
474− Ok(Some(callback_tx.recv().await.unwrap()?))
475− } else {
476− Ok(None)
477− }
467+ callback_tx
468+ .recv()
469+ .await
470+ .expect("Failed to receive response")
478471 }
479472
480473 pub fn capabilities(&self) -> &DebuggerCapabilities {
@@ -501,25 +494,25 @@ impl Client {
501494 };
502495
503496 let response = self
504− .request("initialize".to_owned(), to_value(args).ok(), true)
505− .await?
506− .unwrap();
497+ .request("initialize".to_owned(), to_value(args).ok())
498+ .await?;
507499 self.capabilities = from_value(response.body.unwrap()).ok();
508500
509501 Ok(())
510502 }
511503
512504 pub async fn disconnect(&mut self) -> Result<()> {
513− self.request("disconnect".to_owned(), None, true).await?;
505+ self.request("disconnect".to_owned(), None).await?;
514506 Ok(())
515507 }
516508
517509 pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
518510 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
519511
520− let res = self.request("launch".to_owned(), to_value(args).ok(), false);
521− let ev = initialized.recv();
522− join!(res, ev).0?;
512+ self.request("launch".to_owned(), to_value(args).ok())
513+ .await?;
514+
515+ initialized.recv().await;
523516
524517 Ok(())
525518 }
@@ -527,9 +520,10 @@ impl Client {
527520 pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
528521 let mut initialized = self.listen_for_event("initialized".to_owned()).await;
529522
530− let res = self.request("attach".to_owned(), to_value(args).ok(), false);
531− let ev = initialized.recv();
532− join!(res, ev).0?;
523+ self.request("attach".to_owned(), to_value(args).ok())
524+ .await?;
525+
526+ initialized.recv().await;
533527
534528 Ok(())
535529 }
@@ -555,17 +549,15 @@ impl Client {
555549 };
556550
557551 let response = self
558− .request("setBreakpoints".to_owned(), to_value(args).ok(), true)
559− .await?
560− .unwrap();
552+ .request("setBreakpoints".to_owned(), to_value(args).ok())
553+ .await?;
561554 let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
562555
563556 Ok(body.map(|b| b.breakpoints).unwrap())
564557 }
565558
566559 pub async fn configuration_done(&mut self) -> Result<()> {
567− self.request("configurationDone".to_owned(), None, true)
568− .await?;
560+ self.request("configurationDone".to_owned(), None).await?;
569561 Ok(())
570562 }
571563
@@ -573,9 +565,8 @@ impl Client {
573565 let args = ContinueArguments { thread_id };
574566
575567 let response = self
576− .request("continue".to_owned(), to_value(args).ok(), true)
577− .await?
578− .unwrap();
568+ .request("continue".to_owned(), to_value(args).ok())
569+ .await?;
579570
580571 let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
581572
@@ -594,9 +585,8 @@ impl Client {
594585 };
595586
596587 let response = self
597− .request("stackTrace".to_owned(), to_value(args).ok(), true)
598− .await?
599− .unwrap();
588+ .request("stackTrace".to_owned(), to_value(args).ok())
589+ .await?;
600590
601591 let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
602592
@@ -604,10 +594,7 @@ impl Client {
604594 }
605595
606596 pub async fn threads(&mut self) -> Result<Vec<Thread>> {
607− let response = self
608− .request("threads".to_owned(), None, true)
609− .await?
610− .unwrap();
597+ let response = self.request("threads".to_owned(), None).await?;
611598
612599 let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
613600
@@ -618,9 +605,8 @@ impl Client {
618605 let args = ScopesArguments { frame_id };
619606
620607 let response = self
621− .request("scopes".to_owned(), to_value(args).ok(), true)
622− .await?
623− .unwrap();
608+ .request("scopes".to_owned(), to_value(args).ok())
609+ .await?;
624610
625611 let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
626612
@@ -637,9 +623,8 @@ impl Client {
637623 };
638624
639625 let response = self
640− .request("variables".to_owned(), to_value(args).ok(), true)
641− .await?
642− .unwrap();
626+ .request("variables".to_owned(), to_value(args).ok())
627+ .await?;
643628
644629 let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
645630