@@ -1,7 +1,7 @@
1−use helix_dap::{events, Client, Event, Result, SourceBreakpoint};
1+use helix_dap::{events, Client, Payload, Result, SourceBreakpoint};
22use serde::{Deserialize, Serialize};
33use serde_json::{from_value, to_value};
4−use tokio::sync::mpsc::Receiver;
4+use tokio::sync::mpsc::UnboundedReceiver;
55
66#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
77#[serde(rename_all = "camelCase")]
@@ -10,15 +10,26 @@ struct LaunchArguments {
1010 program: String,
1111}
1212
13−async fn output(mut output_event: Receiver<Event>) {
13+async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
1414 loop {
15− let body: events::Output =
16− from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
17− println!(
18− "> [{}] {}",
19− body.category.unwrap_or("unknown".to_owned()),
20− body.output
21− );
15+ match rx.recv().await.unwrap() {
16+ Payload::Event(ev) => match &ev.event[..] {
17+ "output" => {
18+ let body: events::Output = from_value(ev.body.unwrap()).unwrap();
19+ println!(
20+ "> [{}] {}",
21+ body.category.unwrap_or("unknown".to_owned()),
22+ body.output
23+ );
24+ }
25+ "stopped" => {
26+ println!("stopped");
27+ }
28+ _ => {}
29+ },
30+ Payload::Response(_) => unreachable!(),
31+ Payload::Request(_) => todo!(),
32+ };
2233 }
2334}
2435
@@ -35,12 +46,11 @@ pub async fn main() -> Result<()> {
3546 .apply()
3647 .expect("Failed to set up logging");
3748
38− let client = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await;
49+ let (mut client, events) =
50+ Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await?;
3951 println!("create: {:?}", client);
40− let mut client = client?;
4152
42− let output_event = client.listen_for_event("output".to_owned()).await;
43− tokio::spawn(output(output_event));
53+ tokio::spawn(dispatch(events));
4454
4555 println!("init: {:?}", client.initialize("go".to_owned()).await);
4656 println!("caps: {:?}", client.capabilities());
@@ -73,14 +83,8 @@ pub async fn main() -> Result<()> {
7383 .read_line(&mut _in)
7484 .expect("Failed to read line");
7585
76− let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
77−
7886 println!("configurationDone: {:?}", client.configuration_done().await);
7987
80− let stop: events::Stopped =
81− from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
82− println!("stopped: {:?}", stop);
83−
8488 let threads = client.threads().await?;
8589 println!("threads: {:#?}", threads);
8690 let bt = client