From ae321592479545b3d86319daf2527c76ba46c0c4 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 14 Aug 2021 14:01:29 +0300 Subject: [PATCH] Revert "compat: don't wait for launch and attach response" This reverts commit 766e3380622e2c7ddf5051ed672b78ece8d99f1f. Not required for lldb-vscode --- helix-dap/src/client.rs | 71 ++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 0b3a9928f..23cdefbd6 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -12,7 +12,6 @@ use std::sync::{ use std::{collections::HashMap, process::Stdio}; use tokio::{ io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter}, - join, net::TcpStream, process::{Child, Command}, sync::{ @@ -450,12 +449,7 @@ impl Client { self.request_counter.fetch_add(1, Ordering::Relaxed) } - async fn request( - &self, - command: String, - arguments: Option, - response: bool, - ) -> Result> { + async fn request(&self, command: String, arguments: Option) -> Result { let (callback_rx, mut callback_tx) = channel(1); let req = Request { @@ -470,11 +464,10 @@ impl Client { .send(req) .expect("Failed to send request to debugger"); - if response { - Ok(Some(callback_tx.recv().await.unwrap()?)) - } else { - Ok(None) - } + callback_tx + .recv() + .await + .expect("Failed to receive response") } pub fn capabilities(&self) -> &DebuggerCapabilities { @@ -501,25 +494,25 @@ impl Client { }; let response = self - .request("initialize".to_owned(), to_value(args).ok(), true) - .await? - .unwrap(); + .request("initialize".to_owned(), to_value(args).ok()) + .await?; self.capabilities = from_value(response.body.unwrap()).ok(); Ok(()) } pub async fn disconnect(&mut self) -> Result<()> { - self.request("disconnect".to_owned(), None, true).await?; + self.request("disconnect".to_owned(), None).await?; Ok(()) } pub async fn launch(&mut self, args: impl Serialize) -> Result<()> { let mut initialized = self.listen_for_event("initialized".to_owned()).await; - let res = self.request("launch".to_owned(), to_value(args).ok(), false); - let ev = initialized.recv(); - join!(res, ev).0?; + self.request("launch".to_owned(), to_value(args).ok()) + .await?; + + initialized.recv().await; Ok(()) } @@ -527,9 +520,10 @@ impl Client { pub async fn attach(&mut self, args: impl Serialize) -> Result<()> { let mut initialized = self.listen_for_event("initialized".to_owned()).await; - let res = self.request("attach".to_owned(), to_value(args).ok(), false); - let ev = initialized.recv(); - join!(res, ev).0?; + self.request("attach".to_owned(), to_value(args).ok()) + .await?; + + initialized.recv().await; Ok(()) } @@ -555,17 +549,15 @@ impl Client { }; let response = self - .request("setBreakpoints".to_owned(), to_value(args).ok(), true) - .await? - .unwrap(); + .request("setBreakpoints".to_owned(), to_value(args).ok()) + .await?; let body: Option = from_value(response.body.unwrap()).ok(); Ok(body.map(|b| b.breakpoints).unwrap()) } pub async fn configuration_done(&mut self) -> Result<()> { - self.request("configurationDone".to_owned(), None, true) - .await?; + self.request("configurationDone".to_owned(), None).await?; Ok(()) } @@ -573,9 +565,8 @@ impl Client { let args = ContinueArguments { thread_id }; let response = self - .request("continue".to_owned(), to_value(args).ok(), true) - .await? - .unwrap(); + .request("continue".to_owned(), to_value(args).ok()) + .await?; let body: Option = from_value(response.body.unwrap()).ok(); @@ -594,9 +585,8 @@ impl Client { }; let response = self - .request("stackTrace".to_owned(), to_value(args).ok(), true) - .await? - .unwrap(); + .request("stackTrace".to_owned(), to_value(args).ok()) + .await?; let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap(); @@ -604,10 +594,7 @@ impl Client { } pub async fn threads(&mut self) -> Result> { - let response = self - .request("threads".to_owned(), None, true) - .await? - .unwrap(); + let response = self.request("threads".to_owned(), None).await?; let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap(); @@ -618,9 +605,8 @@ impl Client { let args = ScopesArguments { frame_id }; let response = self - .request("scopes".to_owned(), to_value(args).ok(), true) - .await? - .unwrap(); + .request("scopes".to_owned(), to_value(args).ok()) + .await?; let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap(); @@ -637,9 +623,8 @@ impl Client { }; let response = self - .request("variables".to_owned(), to_value(args).ok(), true) - .await? - .unwrap(); + .request("variables".to_owned(), to_value(args).ok()) + .await?; let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();