on master help sign in
dap-basic: handle output events
09390beDmitry Sharshakov
helix-dap/examples/dap-basic.rs+12−1
@@ -1,5 +1,7 @@
1−use helix_dap::{Client, Result, SourceBreakpoint};
1+use helix_dap::{Client, Event, OutputEventBody, Result, SourceBreakpoint};
2use serde::{Deserialize, Serialize};
2use serde::{Deserialize, Serialize};
3+use serde_json::from_value;
4+use tokio::sync::mpsc::Receiver;
3
5
4#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
6#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
5#[serde(rename_all = "camelCase")]
7#[serde(rename_all = "camelCase")]
@@ -8,6 +10,12 @@ struct LaunchArguments {
8 program: String,
10 program: String,
9}
11}
10
12
13+async fn output(mut output_event: Receiver<Event>) {
14+ let body: OutputEventBody =
15+ from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
16+ println!("{:?}", body);
17+}
18+
11#[tokio::main]
19#[tokio::main]
12pub async fn main() -> Result<()> {
20pub async fn main() -> Result<()> {
13 let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
21 let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
@@ -25,6 +33,9 @@ pub async fn main() -> Result<()> {
25 println!("create: {:?}", client);
33 println!("create: {:?}", client);
26 let mut client = client?;
34 let mut client = client?;
27
35
36+ let output_event = client.listen_for_event("output".to_owned()).await;
37+ tokio::spawn(output(output_event));
38+
28 println!("init: {:?}", client.initialize("go".to_owned()).await);
39 println!("init: {:?}", client.initialize("go".to_owned()).await);
29 println!("caps: {:#?}", client.capabilities());
40 println!("caps: {:#?}", client.capabilities());
30
41
helix-dap/src/client.rs+13
@@ -254,6 +254,19 @@ struct VariablesResponseBody {
254 variables: Vec<Variable>,
254 variables: Vec<Variable>,
255}
255}
256
256
257+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
258+#[serde(rename_all = "camelCase")]
259+pub struct OutputEventBody {
260+ pub output: String,
261+ pub category: Option<String>,
262+ pub group: Option<String>,
263+ pub line: Option<usize>,
264+ pub column: Option<usize>,
265+ pub variables_reference: Option<usize>,
266+ pub source: Option<Source>,
267+ pub data: Option<Value>,
268+}
269+
257#[derive(Debug)]
270#[derive(Debug)]
258pub struct Client {
271pub struct Client {
259 id: usize,
272 id: usize,
helix-dap/src/lib.rs+1−1
@@ -1,7 +1,7 @@
1mod client;
1mod client;
2mod transport;
2mod transport;
3
3
4−pub use client::{Breakpoint, Client, SourceBreakpoint};
4+pub use client::{Breakpoint, Client, OutputEventBody, SourceBreakpoint};
5pub use transport::{Event, Payload, Request, Response, Transport};
5pub use transport::{Event, Payload, Request, Response, Transport};
6
6
7use thiserror::Error;
7use thiserror::Error;