on master help sign in
Add debug-adapter field to languages.toml
commitc5b210df59983a2caa9c389e5cd22aa670fb4a00 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateMon 23 Aug 2021, 16:48 (5 years ago) parentdabec2d
7 files changed+45−10
Cargo.lock+2 helix-core/Cargo.toml+2 helix-core/src/syntax.rs+3 helix-dap/src/client.rs+4−6 helix-dap/src/types.rs+8 helix-term/src/commands.rs+25−4 languages.toml+1
Cargo.lock+2
@@ -306,12 +306,14 @@ version = "0.4.1"
306306dependencies = [
307307 "arc-swap",
308308 "etcetera",
309+ "helix-dap",
309310 "helix-syntax",
310311 "once_cell",
311312 "quickcheck",
312313 "regex",
313314 "ropey",
314315 "serde",
316+ "serde_json",
315317 "similar",
316318 "smallvec",
317319 "tendril",
helix-core/Cargo.toml+2
@@ -14,6 +14,7 @@ include = ["src/**/*", "README.md"]
1414
1515[dependencies]
1616helix-syntax = { version = "0.4", path = "../helix-syntax" }
17+helix-dap = { version = "0.4", path = "../helix-dap" }
1718
1819ropey = "1.3"
1920smallvec = "1.4"
@@ -28,6 +29,7 @@ arc-swap = "1"
2829regex = "1"
2930
3031serde = { version = "1.0", features = ["derive"] }
32+serde_json = "1.0"
3133toml = "0.5"
3234
3335similar = "1.3"
helix-core/src/syntax.rs+3
@@ -5,6 +5,7 @@ use crate::{
55 Rope, RopeSlice, Tendril,
66};
77
8+use helix_dap::DebugAdapterConfig;
89pub use helix_syntax::get_language;
910
1011use arc_swap::ArcSwap;
@@ -55,6 +56,8 @@ pub struct LanguageConfiguration {
5556
5657 #[serde(skip)]
5758 pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
59+ #[serde(skip_serializing_if = "Option::is_none")]
60+ pub debug_adapter: Option<DebugAdapterConfig>,
5861}
5962
6063#[derive(Debug, Serialize, Deserialize)]
helix-dap/src/client.rs+4−6
@@ -113,16 +113,14 @@ impl Client {
113113 }
114114
115115 pub async fn tcp_process(
116− cmd: &str,
117− args: Vec<&str>,
118− port_format: &str,
116+ config: DebugAdapterConfig,
119117 id: usize,
120118 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
121119 let port = Self::get_port().await.unwrap();
122120
123− let process = Command::new(cmd)
124− .args(args)
125− .args(port_format.replace("{}", &port.to_string()).split(' '))
121+ let process = Command::new(config.command)
122+ .args(config.args)
123+ .args(config.port_arg.replace("{}", &port.to_string()).split(' '))
126124 // silence messages
127125 .stdin(Stdio::null())
128126 .stdout(Stdio::null())
helix-dap/src/types.rs+8
@@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize};
22use serde_json::Value;
33use std::path::PathBuf;
44
5+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
6+#[serde(rename_all = "kebab-case")]
7+pub struct DebugAdapterConfig {
8+ pub command: String,
9+ pub args: Vec<String>,
10+ pub port_arg: String,
11+}
12+
513pub trait Request {
614 type Arguments: serde::de::DeserializeOwned + serde::Serialize;
715 type Result: serde::de::DeserializeOwned + serde::Serialize;
helix-term/src/commands.rs+25−4
@@ -4336,12 +4336,33 @@ fn dap_start(cx: &mut Context) {
43364336 use helix_lsp::block_on;
43374337 use serde_json::to_value;
43384338
4339− let (_, _doc) = current!(cx.editor);
4339+ let (_, doc) = current!(cx.editor);
43404340
4341− // look up config for filetype
4342− // if multiple available, open picker
4341+ // TODO config picker
4342+ let path = match doc.path() {
4343+ Some(path) => path.to_path_buf(),
4344+ None => {
4345+ cx.editor
4346+ .set_error("Can't start debug: document has no path".to_string());
4347+ return;
4348+ }
4349+ };
43434350
4344− let started = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0);
4351+ let config = cx
4352+ .editor
4353+ .syn_loader
4354+ .language_config_for_file_name(&path)
4355+ .and_then(|x| x.debug_adapter.clone());
4356+ let config = match config {
4357+ Some(c) => c,
4358+ None => {
4359+ cx.editor.set_error(
4360+ "Can't start debug: no debug adapter available for language".to_string(),
4361+ );
4362+ return;
4363+ }
4364+ };
4365+ let started = Client::tcp_process(config, 0);
43454366 let (mut debugger, events) = block_on(started).unwrap();
43464367
43474368 let request = debugger.initialize("go".to_owned());
languages.toml+1
@@ -93,6 +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:{}" }
9697
9798[[language]]
9899name = "javascript"