A request always needs to have a response, per spec (the body can be empty)

This commit is contained in:
Blaž Hrastnik 2021-08-16 12:31:11 +09:00
parent 3f62799656
commit 6225401e84

View File

@ -505,12 +505,7 @@ fn next_request_id(&self) -> u64 {
self.request_counter.fetch_add(1, Ordering::Relaxed) self.request_counter.fetch_add(1, Ordering::Relaxed)
} }
async fn request( async fn request(&self, command: String, arguments: Option<Value>) -> Result<Response> {
&self,
command: String,
arguments: Option<Value>,
response: bool,
) -> Result<Option<Response>> {
let (callback_rx, mut callback_tx) = channel(1); let (callback_rx, mut callback_tx) = channel(1);
let req = Request { let req = Request {
@ -524,11 +519,7 @@ async fn request(
.send(req) .send(req)
.expect("Failed to send request to debugger"); .expect("Failed to send request to debugger");
if response { Ok(callback_tx.recv().await.unwrap()?)
Ok(Some(callback_tx.recv().await.unwrap()?))
} else {
Ok(None)
}
} }
pub fn capabilities(&self) -> &DebuggerCapabilities { pub fn capabilities(&self) -> &DebuggerCapabilities {
@ -555,23 +546,22 @@ pub async fn initialize(&mut self, adapter_id: String) -> Result<()> {
}; };
let response = self let response = self
.request("initialize".to_owned(), to_value(args).ok(), true) .request("initialize".to_owned(), to_value(args).ok())
.await? .await?;
.unwrap();
self.capabilities = from_value(response.body.unwrap()).ok(); self.capabilities = from_value(response.body.unwrap()).ok();
Ok(()) Ok(())
} }
pub async fn disconnect(&mut self) -> Result<()> { pub async fn disconnect(&mut self) -> Result<()> {
self.request("disconnect".to_owned(), None, true).await?; self.request("disconnect".to_owned(), None).await?;
Ok(()) Ok(())
} }
pub async fn launch(&mut self, args: impl Serialize) -> Result<()> { pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
let mut initialized = self.listen_for_event("initialized".to_owned()).await; let mut initialized = self.listen_for_event("initialized".to_owned()).await;
let res = self.request("launch".to_owned(), to_value(args).ok(), true); let res = self.request("launch".to_owned(), to_value(args).ok());
let ev = initialized.recv(); let ev = initialized.recv();
join!(res, ev).0?; join!(res, ev).0?;
@ -581,7 +571,7 @@ pub async fn launch(&mut self, args: impl Serialize) -> Result<()> {
pub async fn attach(&mut self, args: impl Serialize) -> Result<()> { pub async fn attach(&mut self, args: impl Serialize) -> Result<()> {
let mut initialized = self.listen_for_event("initialized".to_owned()).await; let mut initialized = self.listen_for_event("initialized".to_owned()).await;
let res = self.request("attach".to_owned(), to_value(args).ok(), false); let res = self.request("attach".to_owned(), to_value(args).ok());
let ev = initialized.recv(); let ev = initialized.recv();
join!(res, ev).0?; join!(res, ev).0?;
@ -609,17 +599,15 @@ pub async fn set_breakpoints(
}; };
let response = self let response = self
.request("setBreakpoints".to_owned(), to_value(args).ok(), true) .request("setBreakpoints".to_owned(), to_value(args).ok())
.await? .await?;
.unwrap();
let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok(); let body: Option<SetBreakpointsResponseBody> = from_value(response.body.unwrap()).ok();
Ok(body.map(|b| b.breakpoints).unwrap()) Ok(body.map(|b| b.breakpoints).unwrap())
} }
pub async fn configuration_done(&mut self) -> Result<()> { pub async fn configuration_done(&mut self) -> Result<()> {
self.request("configurationDone".to_owned(), None, true) self.request("configurationDone".to_owned(), None).await?;
.await?;
Ok(()) Ok(())
} }
@ -627,9 +615,8 @@ pub async fn continue_thread(&mut self, thread_id: usize) -> Result<Option<bool>
let args = ContinueArguments { thread_id }; let args = ContinueArguments { thread_id };
let response = self let response = self
.request("continue".to_owned(), to_value(args).ok(), true) .request("continue".to_owned(), to_value(args).ok())
.await? .await?;
.unwrap();
let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok(); let body: Option<ContinueResponseBody> = from_value(response.body.unwrap()).ok();
@ -648,9 +635,8 @@ pub async fn stack_trace(
}; };
let response = self let response = self
.request("stackTrace".to_owned(), to_value(args).ok(), true) .request("stackTrace".to_owned(), to_value(args).ok())
.await? .await?;
.unwrap();
let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap(); let body: StackTraceResponseBody = from_value(response.body.unwrap()).unwrap();
@ -658,10 +644,7 @@ pub async fn stack_trace(
} }
pub async fn threads(&mut self) -> Result<Vec<Thread>> { pub async fn threads(&mut self) -> Result<Vec<Thread>> {
let response = self let response = self.request("threads".to_owned(), None).await?;
.request("threads".to_owned(), None, true)
.await?
.unwrap();
let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap(); let body: ThreadsResponseBody = from_value(response.body.unwrap()).unwrap();
@ -672,9 +655,8 @@ pub async fn scopes(&mut self, frame_id: usize) -> Result<Vec<Scope>> {
let args = ScopesArguments { frame_id }; let args = ScopesArguments { frame_id };
let response = self let response = self
.request("scopes".to_owned(), to_value(args).ok(), true) .request("scopes".to_owned(), to_value(args).ok())
.await? .await?;
.unwrap();
let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap(); let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
@ -691,9 +673,8 @@ pub async fn variables(&mut self, variables_reference: usize) -> Result<Vec<Vari
}; };
let response = self let response = self
.request("variables".to_owned(), to_value(args).ok(), true) .request("variables".to_owned(), to_value(args).ok())
.await? .await?;
.unwrap();
let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap(); let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();