summaryrefslogtreecommitdiff
path: root/helix-dap/examples/dap-dlv.rs
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-21 17:19:11 +0000
committerDmitry Sharshakov2021-08-21 17:19:11 +0000
commitafeaba1113cf6afcb8bea17b4a257079816100ec (patch)
tree21e25608152f743e8bba209f7e9495c14e53e2e1 /helix-dap/examples/dap-dlv.rs
parent5a06263b787710d15278a3caa9fef0f302442b61 (diff)
add rx dispatcher to examples
Diffstat (limited to 'helix-dap/examples/dap-dlv.rs')
-rw-r--r--helix-dap/examples/dap-dlv.rs44
1 files changed, 24 insertions, 20 deletions
diff --git a/helix-dap/examples/dap-dlv.rs b/helix-dap/examples/dap-dlv.rs
index bb5b1963..5db5fa84 100644
--- a/helix-dap/examples/dap-dlv.rs
+++ b/helix-dap/examples/dap-dlv.rs
@@ -1,7 +1,7 @@
-use helix_dap::{events, Client, Event, Result, SourceBreakpoint};
+use helix_dap::{events, Client, Payload, Result, SourceBreakpoint};
use serde::{Deserialize, Serialize};
use serde_json::{from_value, to_value};
-use tokio::sync::mpsc::Receiver;
+use tokio::sync::mpsc::UnboundedReceiver;
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
@@ -10,15 +10,26 @@ struct LaunchArguments {
program: String,
}
-async fn output(mut output_event: Receiver<Event>) {
+async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
loop {
- let body: events::Output =
- from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
- println!(
- "> [{}] {}",
- body.category.unwrap_or("unknown".to_owned()),
- body.output
- );
+ match rx.recv().await.unwrap() {
+ Payload::Event(ev) => match &ev.event[..] {
+ "output" => {
+ let body: events::Output = from_value(ev.body.unwrap()).unwrap();
+ println!(
+ "> [{}] {}",
+ body.category.unwrap_or("unknown".to_owned()),
+ body.output
+ );
+ }
+ "stopped" => {
+ println!("stopped");
+ }
+ _ => {}
+ },
+ Payload::Response(_) => unreachable!(),
+ Payload::Request(_) => todo!(),
+ };
}
}
@@ -35,12 +46,11 @@ pub async fn main() -> Result<()> {
.apply()
.expect("Failed to set up logging");
- let client = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await;
+ let (mut client, events) =
+ Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await?;
println!("create: {:?}", client);
- let mut client = client?;
- let output_event = client.listen_for_event("output".to_owned()).await;
- tokio::spawn(output(output_event));
+ tokio::spawn(dispatch(events));
println!("init: {:?}", client.initialize("go".to_owned()).await);
println!("caps: {:?}", client.capabilities());
@@ -73,14 +83,8 @@ pub async fn main() -> Result<()> {
.read_line(&mut _in)
.expect("Failed to read line");
- let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
-
println!("configurationDone: {:?}", client.configuration_done().await);
- let stop: events::Stopped =
- from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
- println!("stopped: {:?}", stop);
-
let threads = client.threads().await?;
println!("threads: {:#?}", threads);
let bt = client