on master help sign in
Enable stdio transport via config
commit839d2105739036decf045f6af85ce05152f514ef authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateMon 23 Aug 2021, 17:18 (5 years ago) parentf55a012
4 files changed+39−8
helix-dap/src/client.rs+35−5 helix-dap/src/types.rs+2−1 helix-term/src/commands.rs+1−1 languages.toml+1−1
helix-dap/src/client.rs+35−5
@@ -1,8 +1,9 @@
11use crate::{
22 transport::{Payload, Request, Transport},
33 types::*,
4− Result,
4+ Error, Result,
55};
6+use anyhow::anyhow;
67pub use log::{error, info};
78use std::{
89 collections::HashMap,
@@ -35,6 +36,33 @@ pub struct Client {
3536}
3637
3738impl Client {
39+ // Spawn a process and communicate with it by either TCP or stdio
40+ pub async fn process(
41+ cfg: DebugAdapterConfig,
42+ id: usize,
43+ ) -> Result<(Self, UnboundedReceiver<Payload>)> {
44+ if cfg.transport == "tcp" && cfg.port_arg.is_some() {
45+ Self::tcp_process(
46+ &cfg.command,
47+ cfg.args.iter().map(|s| s.as_str()).collect(),
48+ &cfg.port_arg.unwrap(),
49+ id,
50+ )
51+ .await
52+ } else if cfg.transport == "stdio" {
53+ Self::stdio(
54+ &cfg.command,
55+ cfg.args.iter().map(|s| s.as_str()).collect(),
56+ id,
57+ )
58+ } else {
59+ Result::Err(Error::Other(anyhow!(
60+ "Incorrect transport {}",
61+ cfg.transport
62+ )))
63+ }
64+ }
65+
3866 pub fn streams(
3967 rx: Box<dyn AsyncBufRead + Unpin + Send>,
4068 tx: Box<dyn AsyncWrite + Unpin + Send>,
@@ -113,14 +141,16 @@ impl Client {
113141 }
114142
115143 pub async fn tcp_process(
116− config: DebugAdapterConfig,
144+ cmd: &str,
145+ args: Vec<&str>,
146+ port_format: &str,
117147 id: usize,
118148 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
119149 let port = Self::get_port().await.unwrap();
120150
121− let process = Command::new(config.command)
122− .args(config.args)
123− .args(config.port_arg.replace("{}", &port.to_string()).split(' '))
151+ let process = Command::new(cmd)
152+ .args(args)
153+ .args(port_format.replace("{}", &port.to_string()).split(' '))
124154 // silence messages
125155 .stdin(Stdio::null())
126156 .stdout(Stdio::null())
helix-dap/src/types.rs+2−1
@@ -5,9 +5,10 @@ use std::path::PathBuf;
55#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
66#[serde(rename_all = "kebab-case")]
77pub struct DebugAdapterConfig {
8+ pub transport: String,
89 pub command: String,
910 pub args: Vec<String>,
10− pub port_arg: String,
11+ pub port_arg: Option<String>,
1112}
1213
1314pub trait Request {
helix-term/src/commands.rs+1−1
@@ -4362,7 +4362,7 @@ fn dap_start(cx: &mut Context) {
43624362 return;
43634363 }
43644364 };
4365− let started = Client::tcp_process(config, 0);
4365+ let started = Client::process(config, 0);
43664366 let (mut debugger, events) = block_on(started).unwrap();
43674367
43684368 let request = debugger.initialize("go".to_owned());
languages.toml+1−1
@@ -93,7 +93,7 @@ comment-token = "//"
9393language-server = { command = "gopls" }
9494# TODO: gopls needs utf-8 offsets?
9595indent = { tab-width = 4, unit = "\t" }
96−debug-adapter = { command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" }
96+debug-adapter = { transport = "tcp", command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" }
9797
9898[[language.debug-configs]]
9999request = "launch"