Add debug-adapter field to languages.toml

pull/574/head
Dmitry Sharshakov 3 years ago
parent dabec2d799
commit c5b210df59
No known key found for this signature in database
GPG Key ID: 471FD32E15FD8473

2
Cargo.lock generated

@ -306,12 +306,14 @@ version = "0.4.1"
dependencies = [ dependencies = [
"arc-swap", "arc-swap",
"etcetera", "etcetera",
"helix-dap",
"helix-syntax", "helix-syntax",
"once_cell", "once_cell",
"quickcheck", "quickcheck",
"regex", "regex",
"ropey", "ropey",
"serde", "serde",
"serde_json",
"similar", "similar",
"smallvec", "smallvec",
"tendril", "tendril",

@ -14,6 +14,7 @@ include = ["src/**/*", "README.md"]
[dependencies] [dependencies]
helix-syntax = { version = "0.4", path = "../helix-syntax" } helix-syntax = { version = "0.4", path = "../helix-syntax" }
helix-dap = { version = "0.4", path = "../helix-dap" }
ropey = "1.3" ropey = "1.3"
smallvec = "1.4" smallvec = "1.4"
@ -28,6 +29,7 @@ arc-swap = "1"
regex = "1" regex = "1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.5" toml = "0.5"
similar = "1.3" similar = "1.3"

@ -5,6 +5,7 @@ use crate::{
Rope, RopeSlice, Tendril, Rope, RopeSlice, Tendril,
}; };
use helix_dap::DebugAdapterConfig;
pub use helix_syntax::get_language; pub use helix_syntax::get_language;
use arc_swap::ArcSwap; use arc_swap::ArcSwap;
@ -55,6 +56,8 @@ pub struct LanguageConfiguration {
#[serde(skip)] #[serde(skip)]
pub(crate) indent_query: OnceCell<Option<IndentQuery>>, pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_adapter: Option<DebugAdapterConfig>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

@ -113,16 +113,14 @@ impl Client {
} }
pub async fn tcp_process( pub async fn tcp_process(
cmd: &str, config: DebugAdapterConfig,
args: Vec<&str>,
port_format: &str,
id: usize, id: usize,
) -> Result<(Self, UnboundedReceiver<Payload>)> { ) -> Result<(Self, UnboundedReceiver<Payload>)> {
let port = Self::get_port().await.unwrap(); let port = Self::get_port().await.unwrap();
let process = Command::new(cmd) let process = Command::new(config.command)
.args(args) .args(config.args)
.args(port_format.replace("{}", &port.to_string()).split(' ')) .args(config.port_arg.replace("{}", &port.to_string()).split(' '))
// silence messages // silence messages
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::null()) .stdout(Stdio::null())

@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use std::path::PathBuf; 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 { pub trait Request {
type Arguments: serde::de::DeserializeOwned + serde::Serialize; type Arguments: serde::de::DeserializeOwned + serde::Serialize;
type Result: serde::de::DeserializeOwned + serde::Serialize; type Result: serde::de::DeserializeOwned + serde::Serialize;

@ -4336,12 +4336,33 @@ fn dap_start(cx: &mut Context) {
use helix_lsp::block_on; use helix_lsp::block_on;
use serde_json::to_value; use serde_json::to_value;
let (_, _doc) = current!(cx.editor); let (_, doc) = current!(cx.editor);
// look up config for filetype // TODO config picker
// if multiple available, open 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 (mut debugger, events) = block_on(started).unwrap();
let request = debugger.initialize("go".to_owned()); let request = debugger.initialize("go".to_owned());

@ -93,6 +93,7 @@ comment-token = "//"
language-server = { command = "gopls" } language-server = { command = "gopls" }
# TODO: gopls needs utf-8 offsets? # TODO: gopls needs utf-8 offsets?
indent = { tab-width = 4, unit = "\t" } indent = { tab-width = 4, unit = "\t" }
debug-adapter = { command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" }
[[language]] [[language]]
name = "javascript" name = "javascript"

Loading…
Cancel
Save