aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--helix-core/Cargo.toml2
-rw-r--r--helix-core/src/syntax.rs3
-rw-r--r--helix-dap/src/client.rs10
-rw-r--r--helix-dap/src/types.rs8
-rw-r--r--helix-term/src/commands.rs29
-rw-r--r--languages.toml1
7 files changed, 45 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 57ddb01c..fe5c4713 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -306,12 +306,14 @@ version = "0.4.1"
dependencies = [
"arc-swap",
"etcetera",
+ "helix-dap",
"helix-syntax",
"once_cell",
"quickcheck",
"regex",
"ropey",
"serde",
+ "serde_json",
"similar",
"smallvec",
"tendril",
diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml
index 8c83816c..8fdfa3ce 100644
--- a/helix-core/Cargo.toml
+++ b/helix-core/Cargo.toml
@@ -14,6 +14,7 @@ include = ["src/**/*", "README.md"]
[dependencies]
helix-syntax = { version = "0.4", path = "../helix-syntax" }
+helix-dap = { version = "0.4", path = "../helix-dap" }
ropey = "1.3"
smallvec = "1.4"
@@ -28,6 +29,7 @@ arc-swap = "1"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
toml = "0.5"
similar = "1.3"
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 4bceb73b..f3272cff 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -5,6 +5,7 @@ use crate::{
Rope, RopeSlice, Tendril,
};
+use helix_dap::DebugAdapterConfig;
pub use helix_syntax::get_language;
use arc_swap::ArcSwap;
@@ -55,6 +56,8 @@ pub struct LanguageConfiguration {
#[serde(skip)]
pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub debug_adapter: Option<DebugAdapterConfig>,
}
#[derive(Debug, Serialize, Deserialize)]
diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs
index 98b88e23..79c65cf7 100644
--- a/helix-dap/src/client.rs
+++ b/helix-dap/src/client.rs
@@ -113,16 +113,14 @@ impl Client {
}
pub async fn tcp_process(
- cmd: &str,
- args: Vec<&str>,
- port_format: &str,
+ config: DebugAdapterConfig,
id: usize,
) -> Result<(Self, UnboundedReceiver<Payload>)> {
let port = Self::get_port().await.unwrap();
- let process = Command::new(cmd)
- .args(args)
- .args(port_format.replace("{}", &port.to_string()).split(' '))
+ let process = Command::new(config.command)
+ .args(config.args)
+ .args(config.port_arg.replace("{}", &port.to_string()).split(' '))
// silence messages
.stdin(Stdio::null())
.stdout(Stdio::null())
diff --git a/helix-dap/src/types.rs b/helix-dap/src/types.rs
index 26cd69fb..152996a1 100644
--- a/helix-dap/src/types.rs
+++ b/helix-dap/src/types.rs
@@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::path::PathBuf;
+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
+#[serde(rename_all = "kebab-case")]
+pub struct DebugAdapterConfig {
+ pub command: String,
+ pub args: Vec<String>,
+ pub port_arg: String,
+}
+
pub trait Request {
type Arguments: serde::de::DeserializeOwned + serde::Serialize;
type Result: serde::de::DeserializeOwned + serde::Serialize;
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index e35b5d51..3b8e1022 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4336,12 +4336,33 @@ fn dap_start(cx: &mut Context) {
use helix_lsp::block_on;
use serde_json::to_value;
- let (_, _doc) = current!(cx.editor);
+ let (_, doc) = current!(cx.editor);
- // look up config for filetype
- // if multiple available, open picker
+ // TODO config picker
+ let path = match doc.path() {
+ Some(path) => path.to_path_buf(),
+ None => {
+ cx.editor
+ .set_error("Can't start debug: document has no path".to_string());
+ return;
+ }
+ };
- let started = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0);
+ let config = cx
+ .editor
+ .syn_loader
+ .language_config_for_file_name(&path)
+ .and_then(|x| x.debug_adapter.clone());
+ let config = match config {
+ Some(c) => c,
+ None => {
+ cx.editor.set_error(
+ "Can't start debug: no debug adapter available for language".to_string(),
+ );
+ return;
+ }
+ };
+ let started = Client::tcp_process(config, 0);
let (mut debugger, events) = block_on(started).unwrap();
let request = debugger.initialize("go".to_owned());
diff --git a/languages.toml b/languages.toml
index 47155523..61b68e59 100644
--- a/languages.toml
+++ b/languages.toml
@@ -93,6 +93,7 @@ comment-token = "//"
language-server = { command = "gopls" }
# TODO: gopls needs utf-8 offsets?
indent = { tab-width = 4, unit = "\t" }
+debug-adapter = { command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" }
[[language]]
name = "javascript"