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 = [
"arc-swap",
"etcetera",
"helix-dap",
"helix-syntax",
"once_cell",
"quickcheck",
"regex",
"ropey",
"serde",
"serde_json",
"similar",
"smallvec",
"tendril",

@ -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"

@ -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)]

@ -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())

@ -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;

@ -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());

@ -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"

Loading…
Cancel
Save