@@ -1,7 +1,7 @@
1−use helix_dap::{events, Client, Event, Result, SourceBreakpoint};
1+use helix_dap::{events, Client, Payload, Result, SourceBreakpoint};
2use serde::{Deserialize, Serialize};
2use serde::{Deserialize, Serialize};
3use serde_json::{from_value, to_value};
3use serde_json::{from_value, to_value};
4−use tokio::sync::mpsc::Receiver;
4+use tokio::sync::mpsc::UnboundedReceiver;
6#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
6#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
7#[serde(rename_all = "camelCase")]
7#[serde(rename_all = "camelCase")]
@@ -10,15 +10,26 @@ struct LaunchArguments {
10 program: String,
10 program: String,
13−async fn output(mut output_event: Receiver<Event>) {
13+async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
15+ match rx.recv().await.unwrap() {
16+ Payload::Event(ev) => match &ev.event[..] {
15− let body: events::Output =
18+ let body: events::Output = from_value(ev.body.unwrap()).unwrap();
16− from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
17− println!(
19+ println!(
18− "> [{}] {}",
20+ "> [{}] {}",
19− body.category.unwrap_or("unknown".to_owned()),
21+ body.category.unwrap_or("unknown".to_owned()),
20− body.output
22+ body.output
30+ Payload::Response(_) => unreachable!(),
31+ Payload::Request(_) => todo!(),
@@ -35,12 +46,11 @@ pub async fn main() -> Result<()> {
36 .expect("Failed to set up logging");
47 .expect("Failed to set up logging");
49+ let (mut client, events) =
38− let client = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await;
50+ Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await?;
39 println!("create: {:?}", client);
51 println!("create: {:?}", client);
40− let mut client = client?;
42− let output_event = client.listen_for_event("output".to_owned()).await;
53+ tokio::spawn(dispatch(events));
43− tokio::spawn(output(output_event));
45 println!("init: {:?}", client.initialize("go".to_owned()).await);
55 println!("init: {:?}", client.initialize("go".to_owned()).await);
46 println!("caps: {:?}", client.capabilities());
56 println!("caps: {:?}", client.capabilities());
@@ -73,14 +83,8 @@ pub async fn main() -> Result<()> {
73 .read_line(&mut _in)
83 .read_line(&mut _in)
74 .expect("Failed to read line");
84 .expect("Failed to read line");
76− let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
78 println!("configurationDone: {:?}", client.configuration_done().await);
86 println!("configurationDone: {:?}", client.configuration_done().await);
80− let stop: events::Stopped =
81− from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
82− println!("stopped: {:?}", stop);
84 let threads = client.threads().await?;
88 let threads = client.threads().await?;
85 println!("threads: {:#?}", threads);
89 println!("threads: {:#?}", threads);
86 let bt = client
90 let bt = client