on 2158366 help sign in
117 lines 3.3 kB history raw
1use helix_dap::{events, Client, Event, Payload, Result, SourceBreakpoint};
2use serde::{Deserialize, Serialize};
3use serde_json::to_value;
4use tokio::sync::mpsc::UnboundedReceiver;
6#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
7#[serde(rename_all = "camelCase")]
8struct LaunchArguments {
9 mode: String,
10 program: String,
13async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
14 loop {
15 match rx.recv().await.unwrap() {
16 Payload::Event(Event::Output(events::Output {
17 category, output, ..
18 })) => {
19 println!(
20 "> [{}] {}",
21 category.unwrap_or("unknown".to_owned()),
22 output
23 );
24 }
25 Payload::Event(Event::Stopped(_)) => {
26 println!("stopped");
27 }
28 _ => {}
29 };
30 }
33#[tokio::main]
34pub async fn main() -> Result<()> {
35 let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
37 let stderr_config = fern::Dispatch::new()
38 .format(|out, message, record| out.finish(format_args!("[{}] {}", record.level(), message)))
39 .chain(std::io::stderr());
41 base_config
42 .chain(stderr_config)
43 .apply()
44 .expect("Failed to set up logging");
46 let (mut client, events) =
47 Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await?;
48 println!("create: {:?}", client);
50 tokio::spawn(dispatch(events));
52 println!("init: {:?}", client.initialize("go".to_owned()).await);
53 println!("caps: {:?}", client.capabilities());
55 let args = LaunchArguments {
56 mode: "exec".to_owned(),
57 program: "/tmp/godebug/main".to_owned(),
58 };
60 println!("launch: {:?}", client.launch(to_value(args)?).await);
62 println!(
63 "breakpoints: {:#?}",
64 client
65 .set_breakpoints(
66 "/tmp/godebug/main.go".into(),
67 vec![SourceBreakpoint {
68 line: 8,
69 column: Some(2),
70 condition: None,
71 hit_condition: None,
72 log_message: None,
73 }]
74 )
75 .await
76 );
78 let mut _in = String::new();
79 std::io::stdin()
80 .read_line(&mut _in)
81 .expect("Failed to read line");
83 println!("configurationDone: {:?}", client.configuration_done().await);
85 let threads = client.threads().await?;
86 println!("threads: {:#?}", threads);
87 let bt = client
88 .stack_trace(threads[0].id)
89 .await
90 .expect("expected stack trace");
91 println!("stack trace: {:#?}", bt);
92 let scopes = client
93 .scopes(bt.0[0].id)
94 .await
95 .expect("expected scopes for thread");
96 println!("scopes: {:#?}", scopes);
97 println!(
98 "vars: {:#?}",
99 client.variables(scopes[1].variables_reference).await
100 );
102 let mut _in = String::new();
103 std::io::stdin()
104 .read_line(&mut _in)
105 .expect("Failed to read line");
107 println!("continued: {:?}", client.continue_thread(0).await);
109 let mut _in = String::new();
110 std::io::stdin()
111 .read_line(&mut _in)
112 .expect("Failed to read line");
114 println!("disconnect: {:?}", client.disconnect().await);
116 Ok(())