on master help sign in
Enable stdio transport via config
839d210Dmitry Sharshakov
helix-dap/src/client.rs+35−5
@@ -1,8 +1,9 @@
1use crate::{
1use crate::{
2 transport::{Payload, Request, Transport},
2 transport::{Payload, Request, Transport},
3 types::*,
3 types::*,
4− Result,
4+ Error, Result,
5};
5};
6+use anyhow::anyhow;
6pub use log::{error, info};
7pub use log::{error, info};
7use std::{
8use std::{
8 collections::HashMap,
9 collections::HashMap,
@@ -35,6 +36,33 @@ pub struct Client {
35}
36}
36
37
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,
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+
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 {
113 }
141 }
114
142
115 pub async fn tcp_process(
143 pub async fn tcp_process(
116− config: DebugAdapterConfig,
144+ cmd: &str,
145+ args: Vec<&str>,
146+ port_format: &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();
120
150
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())
helix-dap/src/types.rs+2−1
@@ -5,9 +5,10 @@ use std::path::PathBuf;
5#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
5#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
6#[serde(rename_all = "kebab-case")]
6#[serde(rename_all = "kebab-case")]
7pub struct DebugAdapterConfig {
7pub struct DebugAdapterConfig {
8+ pub transport: String,
8 pub command: String,
9 pub command: String,
9 pub args: Vec<String>,
10 pub args: Vec<String>,
10− pub port_arg: String,
11+ pub port_arg: Option<String>,
11}
12}
12
13
13pub trait Request {
14pub trait Request {
helix-term/src/commands.rs+1−1
@@ -4362,7 +4362,7 @@ fn dap_start(cx: &mut Context) {
4362 return;
4362 return;
4363 }
4363 }
4364 };
4364 };
4365− let started = Client::tcp_process(config, 0);
4365+ let started = Client::process(config, 0);
4366 let (mut debugger, events) = block_on(started).unwrap();
4366 let (mut debugger, events) = block_on(started).unwrap();
4367
4367
4368 let request = debugger.initialize("go".to_owned());
4368 let request = debugger.initialize("go".to_owned());
languages.toml+1−1
@@ -93,7 +93,7 @@ comment-token = "//"
93language-server = { command = "gopls" }
93language-server = { command = "gopls" }
94# TODO: gopls needs utf-8 offsets?
94# TODO: gopls needs utf-8 offsets?
95indent = { tab-width = 4, unit = "\t" }
95indent = { 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:{}" }
97
97
98[[language.debug-configs]]
98[[language.debug-configs]]
99request = "launch"
99request = "launch"