@@ -1,8 +1,9 @@
1use crate::{
1use crate::{
2 transport::{Payload, Request, Transport},
2 transport::{Payload, Request, Transport},
4− Result,
4+ Error, Result,
6pub use log::{error, info};
7pub use log::{error, info};
8 collections::HashMap,
9 collections::HashMap,
@@ -35,6 +36,33 @@ pub struct Client {
37impl Client {
38impl Client {
39+ // Spawn a process and communicate with it by either TCP or stdio
40+ pub async fn process(
41+ cfg: DebugAdapterConfig,
43+ ) -> Result<(Self, UnboundedReceiver<Payload>)> {
44+ if cfg.transport == "tcp" && cfg.port_arg.is_some() {
47+ cfg.args.iter().map(|s| s.as_str()).collect(),
48+ &cfg.port_arg.unwrap(),
52+ } else if cfg.transport == "stdio" {
55+ cfg.args.iter().map(|s| s.as_str()).collect(),
59+ Result::Err(Error::Other(anyhow!(
60+ "Incorrect transport {}",
38 pub fn streams(
66 pub fn streams(
39 rx: Box<dyn AsyncBufRead + Unpin + Send>,
67 rx: Box<dyn AsyncBufRead + Unpin + Send>,
40 tx: Box<dyn AsyncWrite + Unpin + Send>,
68 tx: Box<dyn AsyncWrite + Unpin + Send>,
@@ -113,14 +141,16 @@ impl Client {
115 pub async fn tcp_process(
143 pub async fn tcp_process(
116− config: DebugAdapterConfig,
144+ cmd: &str,
117 id: usize,
147 id: usize,
118 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
148 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
119 let port = Self::get_port().await.unwrap();
149 let port = Self::get_port().await.unwrap();
121− let process = Command::new(config.command)
151+ let process = Command::new(cmd)
122− .args(config.args)
152+ .args(args)
123− .args(config.port_arg.replace("{}", &port.to_string()).split(' '))
153+ .args(port_format.replace("{}", &port.to_string()).split(' '))
124 // silence messages
154 // silence messages
125 .stdin(Stdio::null())
155 .stdin(Stdio::null())
126 .stdout(Stdio::null())
156 .stdout(Stdio::null())