mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 21:47:07 +04:00
add rx dispatcher to examples
This commit is contained in:
parent
5a06263b78
commit
afeaba1113
@ -1,7 +1,7 @@
|
|||||||
use helix_dap::{events, Client, Event, Result, SourceBreakpoint};
|
use helix_dap::{events, Client, Payload, Result, SourceBreakpoint};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{from_value, to_value};
|
use serde_json::{from_value, to_value};
|
||||||
use tokio::sync::mpsc::Receiver;
|
use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
@ -10,16 +10,27 @@ struct LaunchArguments {
|
|||||||
program: String,
|
program: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn output(mut output_event: Receiver<Event>) {
|
async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
|
||||||
loop {
|
loop {
|
||||||
let body: events::Output =
|
match rx.recv().await.unwrap() {
|
||||||
from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
|
Payload::Event(ev) => match &ev.event[..] {
|
||||||
|
"output" => {
|
||||||
|
let body: events::Output = from_value(ev.body.unwrap()).unwrap();
|
||||||
println!(
|
println!(
|
||||||
"> [{}] {}",
|
"> [{}] {}",
|
||||||
body.category.unwrap_or("unknown".to_owned()),
|
body.category.unwrap_or("unknown".to_owned()),
|
||||||
body.output
|
body.output
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
"stopped" => {
|
||||||
|
println!("stopped");
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
Payload::Response(_) => unreachable!(),
|
||||||
|
Payload::Request(_) => todo!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -35,12 +46,11 @@ pub async fn main() -> Result<()> {
|
|||||||
.apply()
|
.apply()
|
||||||
.expect("Failed to set up logging");
|
.expect("Failed to set up logging");
|
||||||
|
|
||||||
let client = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await;
|
let (mut client, events) =
|
||||||
|
Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0).await?;
|
||||||
println!("create: {:?}", client);
|
println!("create: {:?}", client);
|
||||||
let mut client = client?;
|
|
||||||
|
|
||||||
let output_event = client.listen_for_event("output".to_owned()).await;
|
tokio::spawn(dispatch(events));
|
||||||
tokio::spawn(output(output_event));
|
|
||||||
|
|
||||||
println!("init: {:?}", client.initialize("go".to_owned()).await);
|
println!("init: {:?}", client.initialize("go".to_owned()).await);
|
||||||
println!("caps: {:?}", client.capabilities());
|
println!("caps: {:?}", client.capabilities());
|
||||||
@ -73,14 +83,8 @@ pub async fn main() -> Result<()> {
|
|||||||
.read_line(&mut _in)
|
.read_line(&mut _in)
|
||||||
.expect("Failed to read line");
|
.expect("Failed to read line");
|
||||||
|
|
||||||
let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
|
|
||||||
|
|
||||||
println!("configurationDone: {:?}", client.configuration_done().await);
|
println!("configurationDone: {:?}", client.configuration_done().await);
|
||||||
|
|
||||||
let stop: events::Stopped =
|
|
||||||
from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
|
|
||||||
println!("stopped: {:?}", stop);
|
|
||||||
|
|
||||||
let threads = client.threads().await?;
|
let threads = client.threads().await?;
|
||||||
println!("threads: {:#?}", threads);
|
println!("threads: {:#?}", threads);
|
||||||
let bt = client
|
let bt = client
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use helix_dap::{events, Client, Event, Result, SourceBreakpoint};
|
use helix_dap::{events, Client, Payload, Result, SourceBreakpoint};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{from_value, to_value};
|
use serde_json::{from_value, to_value};
|
||||||
use tokio::sync::mpsc::Receiver;
|
use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
@ -10,16 +10,27 @@ struct LaunchArguments {
|
|||||||
console: String,
|
console: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn output(mut output_event: Receiver<Event>) {
|
async fn dispatch(mut rx: UnboundedReceiver<Payload>) {
|
||||||
loop {
|
loop {
|
||||||
let body: events::Output =
|
match rx.recv().await.unwrap() {
|
||||||
from_value(output_event.recv().await.unwrap().body.unwrap()).unwrap();
|
Payload::Event(ev) => match &ev.event[..] {
|
||||||
|
"output" => {
|
||||||
|
let body: events::Output = from_value(ev.body.unwrap()).unwrap();
|
||||||
println!(
|
println!(
|
||||||
"> [{}] {}",
|
"> [{}] {}",
|
||||||
body.category.unwrap_or("unknown".to_owned()),
|
body.category.unwrap_or("unknown".to_owned()),
|
||||||
body.output
|
body.output
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
"stopped" => {
|
||||||
|
println!("stopped");
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
Payload::Response(_) => unreachable!(),
|
||||||
|
Payload::Request(_) => todo!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -35,12 +46,10 @@ pub async fn main() -> Result<()> {
|
|||||||
.apply()
|
.apply()
|
||||||
.expect("Failed to set up logging");
|
.expect("Failed to set up logging");
|
||||||
|
|
||||||
let client = Client::tcp_process("lldb-vscode", vec![], "-p {}", 0).await;
|
let (mut client, events) = Client::tcp_process("lldb-vscode", vec![], "-p {}", 0).await?;
|
||||||
println!("create: {:?}", client);
|
println!("create: {:?}", client);
|
||||||
let mut client = client?;
|
|
||||||
|
|
||||||
let output_event = client.listen_for_event("output".to_owned()).await;
|
tokio::spawn(dispatch(events));
|
||||||
tokio::spawn(output(output_event));
|
|
||||||
|
|
||||||
println!("init: {:?}", client.initialize("lldb".to_owned()).await);
|
println!("init: {:?}", client.initialize("lldb".to_owned()).await);
|
||||||
println!("caps: {:?}", client.capabilities());
|
println!("caps: {:?}", client.capabilities());
|
||||||
@ -73,14 +82,8 @@ pub async fn main() -> Result<()> {
|
|||||||
.read_line(&mut _in)
|
.read_line(&mut _in)
|
||||||
.expect("Failed to read line");
|
.expect("Failed to read line");
|
||||||
|
|
||||||
let mut stopped_event = client.listen_for_event("stopped".to_owned()).await;
|
|
||||||
|
|
||||||
println!("configurationDone: {:?}", client.configuration_done().await);
|
println!("configurationDone: {:?}", client.configuration_done().await);
|
||||||
|
|
||||||
let stop: events::Stopped =
|
|
||||||
from_value(stopped_event.recv().await.unwrap().body.unwrap()).unwrap();
|
|
||||||
println!("stopped: {:?}", stop);
|
|
||||||
|
|
||||||
let threads = client.threads().await?;
|
let threads = client.threads().await?;
|
||||||
println!("threads: {:#?}", threads);
|
println!("threads: {:#?}", threads);
|
||||||
let bt = client
|
let bt = client
|
||||||
|
Loading…
Reference in New Issue
Block a user