helix-mirror/helix-dap/examples/dap-dlv.rs

123 lines
3.4 KiB
Rust
Raw Normal View History

2021-08-22 13:13:43 +04:00
use helix_dap::{events, Client, Event, Payload, Result, SourceBreakpoint};
use serde::{Deserialize, Serialize};
2021-08-22 13:13:43 +04:00
use serde_json::to_value;
2021-08-21 21:19:11 +04:00
use tokio::sync::mpsc::UnboundedReceiver;
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct LaunchArguments {
mode: String,
program: String,
}
2021-08-21 21:19:11 +04:00
async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
loop {
2021-08-21 21:19:11 +04:00
match rx.recv().await.unwrap() {
2021-08-22 13:13:43 +04:00
Payload::Event(Event::Output(events::Output {
category, output, ..
})) => {
println!(
"> [{}] {}",
category.unwrap_or("unknown".to_owned()),
output
);
}
Payload::Event(Event::Stopped(_)) => {
println!("stopped");
}
_ => {}
2021-08-21 21:19:11 +04:00
};
}
2021-08-14 10:14:05 +04:00
}
#[tokio::main]
pub async fn main() -> Result<()> {
2021-08-12 17:45:01 +04:00
let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
let stderr_config = fern::Dispatch::new()
.format(|out, message, record| out.finish(format_args!("[{}] {}", record.level(), message)))
.chain(std::io::stderr());
base_config
.chain(stderr_config)
.apply()
.expect("Failed to set up logging");
2021-08-21 21:19:11 +04:00
let (mut client, events) =
Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await?;
2021-08-13 21:13:27 +04:00
println!("create: {:?}", client);
2021-08-21 21:19:11 +04:00
tokio::spawn(dispatch(events));
2021-08-14 10:14:05 +04:00
2021-08-13 21:18:15 +04:00
println!("init: {:?}", client.initialize("go".to_owned()).await);
2021-08-14 12:41:23 +04:00
println!("caps: {:?}", client.capabilities());
let args = LaunchArguments {
mode: "exec".to_owned(),
program: "/tmp/godebug/main".to_owned(),
};
2021-08-16 09:05:10 +04:00
println!("launch: {:?}", client.launch(to_value(args)?).await);
println!(
2021-08-12 18:49:12 +04:00
"breakpoints: {:#?}",
client
.set_breakpoints(
2021-08-20 17:48:59 +04:00
"/tmp/godebug/main.go".into(),
vec![SourceBreakpoint {
line: 8,
column: Some(2),
2021-08-12 22:23:55 +04:00
condition: None,
hit_condition: None,
log_message: None,
}]
)
.await
);
let mut _in = String::new();
std::io::stdin()
.read_line(&mut _in)
.expect("Failed to read line");
println!("configurationDone: {:?}", client.configuration_done().await);
2021-08-14 09:42:06 +04:00
let mut _in = String::new();
std::io::stdin()
.read_line(&mut _in)
.expect("Failed to read line");
2021-08-14 17:36:06 +04:00
let threads = client.threads().await?;
println!("threads: {:#?}", threads);
let bt = client
.stack_trace(threads[0].id)
.await
.expect("expected stack trace");
println!("stack trace: {:#?}", bt);
let scopes = client
.scopes(bt.0[0].id)
.await
.expect("expected scopes for thread");
println!("scopes: {:#?}", scopes);
println!(
"vars: {:#?}",
client.variables(scopes[1].variables_reference).await
);
let mut _in = String::new();
std::io::stdin()
.read_line(&mut _in)
.expect("Failed to read line");
println!("continued: {:?}", client.continue_thread(0).await);
let mut _in = String::new();
std::io::stdin()
.read_line(&mut _in)
.expect("Failed to read line");
println!("disconnect: {:?}", client.disconnect().await);
Ok(())
}