diff options
-rw-r--r-- | helix-dap/examples/dap-basic.rs | 13 | ||||
-rw-r--r-- | helix-dap/src/client.rs | 13 | ||||
-rw-r--r-- | helix-dap/src/lib.rs | 2 |
3 files changed, 26 insertions, 2 deletions
diff --git a/helix-dap/examples/dap-basic.rs b/helix-dap/examples/dap-basic.rs index 76fc0dd3..fb52f855 100644 --- a/helix-dap/examples/dap-basic.rs +++ b/helix-dap/examples/dap-basic.rs @@ -1,5 +1,7 @@ -use helix_dap::{Client, Result, SourceBreakpoint}; +use helix_dap::{Client, Event, OutputEventBody, Result, SourceBreakpoint}; use serde::{Deserialize, Serialize}; +use serde_json::from_value; +use tokio::sync::mpsc::Receiver; #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] @@ -8,6 +10,12 @@ struct LaunchArguments { program: String, } +async fn output(mut output_event: Receiver<Event>) { + let body: OutputEventBody = + from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap(); + println!("{:?}", body); +} + #[tokio::main] pub async fn main() -> Result<()> { let base_config = fern::Dispatch::new().level(log::LevelFilter::Info); @@ -25,6 +33,9 @@ pub async fn main() -> Result<()> { println!("create: {:?}", client); let mut client = client?; + let output_event = client.listen_for_event("output".to_owned()).await; + tokio::spawn(output(output_event)); + println!("init: {:?}", client.initialize("go".to_owned()).await); println!("caps: {:#?}", client.capabilities()); diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 7ce7833d..ef7bb153 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -254,6 +254,19 @@ struct VariablesResponseBody { variables: Vec<Variable>, } +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct OutputEventBody { + pub output: String, + pub category: Option<String>, + pub group: Option<String>, + pub line: Option<usize>, + pub column: Option<usize>, + pub variables_reference: Option<usize>, + pub source: Option<Source>, + pub data: Option<Value>, +} + #[derive(Debug)] pub struct Client { id: usize, diff --git a/helix-dap/src/lib.rs b/helix-dap/src/lib.rs index 1e545fd8..408f4d3d 100644 --- a/helix-dap/src/lib.rs +++ b/helix-dap/src/lib.rs @@ -1,7 +1,7 @@ mod client; mod transport; -pub use client::{Breakpoint, Client, SourceBreakpoint}; +pub use client::{Breakpoint, Client, OutputEventBody, SourceBreakpoint}; pub use transport::{Event, Payload, Request, Response, Transport}; use thiserror::Error; |