on master help sign in
dap-basic: handle output events
commit09390be6a568bcf7052c57bf10219c448413d5b0 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSat 14 Aug 2021, 09:14 (5 years ago) parentc72475b
3 files changed+26−2
helix-dap/examples/dap-basic.rs+12−1 helix-dap/src/client.rs+13 helix-dap/src/lib.rs+1−1
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};
22use serde::{Deserialize, Serialize};
3+use serde_json::from_value;
4+use tokio::sync::mpsc::Receiver;
35
46#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
57#[serde(rename_all = "camelCase")]
@@ -8,6 +10,12 @@ struct LaunchArguments {
810 program: String,
911}
1012
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+
1119#[tokio::main]
1220pub async fn main() -> Result<()> {
1321 let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
@@ -25,6 +33,9 @@ pub async fn main() -> Result<()> {
2533 println!("create: {:?}", client);
2634 let mut client = client?;
2735
36+ let output_event = client.listen_for_event("output".to_owned()).await;
37+ tokio::spawn(output(output_event));
38+
2839 println!("init: {:?}", client.initialize("go".to_owned()).await);
2940 println!("caps: {:#?}", client.capabilities());
3041
helix-dap/src/client.rs+13
@@ -254,6 +254,19 @@ struct VariablesResponseBody {
254254 variables: Vec<Variable>,
255255}
256256
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+
257270#[derive(Debug)]
258271pub struct Client {
259272 id: usize,
helix-dap/src/lib.rs+1−1
@@ -1,7 +1,7 @@
11mod client;
22mod transport;
33
4−pub use client::{Breakpoint, Client, SourceBreakpoint};
4+pub use client::{Breakpoint, Client, OutputEventBody, SourceBreakpoint};
55pub use transport::{Event, Payload, Request, Response, Transport};
66
77use thiserror::Error;