aboutsummaryrefslogtreecommitdiff
path: root/helix-dap
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-16 09:16:06 +0000
committerBlaž Hrastnik2021-08-20 04:48:32 +0000
commitd39baa3b4e1f5bc1a03533e7b22af0043ec1eac9 (patch)
tree11f769898442e5d4fbddb8aacf2b7ff05fb33cb5 /helix-dap
parent0300dbdeb378fa5797a23ce8b3f72e2749c3ce50 (diff)
Start integrating into the editor's event loop
Diffstat (limited to 'helix-dap')
-rw-r--r--helix-dap/Cargo.toml2
-rw-r--r--helix-dap/src/client.rs22
-rw-r--r--helix-dap/src/transport.rs21
3 files changed, 20 insertions, 25 deletions
diff --git a/helix-dap/Cargo.toml b/helix-dap/Cargo.toml
index ce1e2d16..7582067e 100644
--- a/helix-dap/Cargo.toml
+++ b/helix-dap/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "helix-dap"
-version = "0.3.0"
+version = "0.4.0"
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
edition = "2018"
license = "MPL-2.0"
diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs
index 0f23dd15..baf924b9 100644
--- a/helix-dap/src/client.rs
+++ b/helix-dap/src/client.rs
@@ -186,12 +186,12 @@ impl Client {
&self,
arguments: R::Arguments,
) -> Result<R::Result> {
- let (callback_rx, mut callback_tx) = channel(1);
+ let (callback_tx, mut callback_rx) = channel(1);
let arguments = Some(serde_json::to_value(arguments)?);
let req = Request {
- back_ch: Some(callback_rx),
+ back_ch: Some(callback_tx),
seq: self.next_request_id(),
command: R::COMMAND.to_string(),
arguments,
@@ -201,7 +201,7 @@ impl Client {
.send(req)
.expect("Failed to send request to debugger");
- let response = callback_tx.recv().await.unwrap()?;
+ let response = callback_rx.recv().await.unwrap()?;
let response = serde_json::from_value(response.body.unwrap_or_default())?;
Ok(response)
}
@@ -209,7 +209,7 @@ impl Client {
pub fn capabilities(&self) -> &DebuggerCapabilities {
self.capabilities
.as_ref()
- .expect("language server not yet initialized!")
+ .expect("debugger not yet initialized!")
}
pub async fn initialize(&mut self, adapter_id: String) -> Result<()> {
@@ -240,21 +240,19 @@ impl Client {
}
pub async fn launch(&mut self, args: serde_json::Value) -> Result<()> {
- let mut initialized = self.listen_for_event("initialized".to_owned()).await;
+ // TODO: buffer these until initialized arrives
- let res = self.request::<requests::Launch>(args);
- let ev = initialized.recv();
- join!(res, ev).0?;
+ let response = self.request::<requests::Launch>(args).await?;
+ log::error!("launch response {}", response);
Ok(())
}
pub async fn attach(&mut self, args: serde_json::Value) -> Result<()> {
- let mut initialized = self.listen_for_event("initialized".to_owned()).await;
+ // TODO: buffer these until initialized arrives
- let res = self.request::<requests::Attach>(args);
- let ev = initialized.recv();
- join!(res, ev).0?;
+ let response = self.request::<requests::Attach>(args).await?;
+ log::error!("attach response {}", response);
Ok(())
}
diff --git a/helix-dap/src/transport.rs b/helix-dap/src/transport.rs
index bca1351c..062e0447 100644
--- a/helix-dap/src/transport.rs
+++ b/helix-dap/src/transport.rs
@@ -159,20 +159,17 @@ impl Transport {
}
fn process_response(res: Response) -> Result<Response> {
- match res.success {
- true => {
- info!("<- DAP success in response to {}", res.request_seq);
+ if res.success {
+ info!("<- DAP success in response to {}", res.request_seq);
- Ok(res)
- }
- false => {
- error!(
- "<- DAP error {:?} ({:?}) for command #{} {}",
- res.message, res.body, res.request_seq, res.command
- );
+ Ok(res)
+ } else {
+ error!(
+ "<- DAP error {:?} ({:?}) for command #{} {}",
+ res.message, res.body, res.request_seq, res.command
+ );
- Err(Error::Other(anyhow::format_err!("{:?}", res.body)))
- }
+ Err(Error::Other(anyhow::format_err!("{:?}", res.body)))
}
}