on master help sign in
editor: add Node.js debugger
commitd943a51e3e8e2cd77cc336c30eb954378e81fe31 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 26 Sep 2021, 21:36 (5 years ago) parent0e51e5f
5 files changed+44−3
helix-core/src/syntax.rs+4 helix-dap/src/client.rs+13 helix-dap/src/lib.rs+1−1 helix-term/src/commands/dap.rs+14−2 languages.toml+12
helix-core/src/syntax.rs+4
@@ -5,6 +5,7 @@ use crate::{
55 Rope, RopeSlice, Tendril,
66};
77
8+use helix_dap::DebuggerQuirks;
89pub use helix_syntax::get_language;
910
1011use arc_swap::ArcSwap;
@@ -107,11 +108,14 @@ pub struct DebugTemplate {
107108pub struct DebugAdapterConfig {
108109 pub name: String,
109110 pub transport: String,
111+ #[serde(default)]
110112 pub command: String,
111113 #[serde(default)]
112114 pub args: Vec<String>,
113115 pub port_arg: Option<String>,
114116 pub templates: Vec<DebugTemplate>,
117+ #[serde(default)]
118+ pub quirks: DebuggerQuirks,
115119}
116120
117121#[derive(Debug, Serialize, Deserialize)]
helix-dap/src/client.rs+13
@@ -5,6 +5,7 @@ use crate::{
55};
66use anyhow::anyhow;
77pub use log::{error, info};
8+use serde::{Deserialize, Serialize};
89use std::{
910 collections::HashMap,
1011 net::{IpAddr, Ipv4Addr, SocketAddr},
@@ -20,6 +21,13 @@ use tokio::{
2021 time,
2122};
2223
24+// Different workarounds for adapters' differences
25+#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
26+pub struct DebuggerQuirks {
27+ #[serde(default)]
28+ pub absolute_paths: bool,
29+}
30+
2331#[derive(Debug)]
2432pub struct Client {
2533 id: usize,
@@ -34,6 +42,7 @@ pub struct Client {
3442 /// Currently active frame for the current thread.
3543 pub active_frame: Option<usize>,
3644 pub breakpoints: Vec<Breakpoint>,
45+ pub quirks: DebuggerQuirks,
3746}
3847
3948impl Client {
@@ -45,6 +54,9 @@ impl Client {
4554 port_arg: Option<String>,
4655 id: usize,
4756 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
57+ if command == "" {
58+ return Result::Err(Error::Other(anyhow!("Command not provided")));
59+ }
4860 if transport == "tcp" && port_arg.is_some() {
4961 Self::tcp_process(
5062 &command,
@@ -82,6 +94,7 @@ impl Client {
8294 thread_id: None,
8395 active_frame: None,
8496 breakpoints: vec![],
97+ quirks: DebuggerQuirks::default(),
8598 };
8699
87100 tokio::spawn(Self::recv(server_rx, client_rx));
helix-dap/src/lib.rs+1−1
@@ -2,7 +2,7 @@ mod client;
22mod transport;
33mod types;
44
5−pub use client::Client;
5+pub use client::{Client, DebuggerQuirks};
66pub use events::Event;
77pub use transport::{Payload, Response, Transport};
88pub use types::*;
helix-term/src/commands/dap.rs+14−2
@@ -5,7 +5,7 @@ use crate::{
55 job::Callback,
66 ui::{FilePicker, Prompt, PromptEvent},
77};
8−use helix_core::Selection;
8+use helix_core::{syntax::DebugConfigCompletion, Selection};
99use helix_dap::{self as dap, Client};
1010use helix_lsp::block_on;
1111
@@ -206,6 +206,8 @@ pub fn dap_start_impl(
206206 return;
207207 }
208208
209+ debugger.quirks = config.quirks;
210+
209211 let start_config = match name {
210212 Some(name) => config.templates.iter().find(|t| t.name == name),
211213 None => config.templates.get(0),
@@ -225,8 +227,18 @@ pub fn dap_start_impl(
225227 for (k, t) in template {
226228 let mut value = t;
227229 for (i, x) in params.iter().enumerate() {
230+ let mut param = x.to_string();
231+ if let Some(DebugConfigCompletion::Advanced(cfg)) = start_config.completion.get(i) {
232+ if cfg.completion == Some("filename".to_owned())
233+ || cfg.completion == Some("directory".to_owned())
234+ {
235+ param = std::fs::canonicalize(x).ok()
236+ .and_then(|pb| pb.into_os_string().into_string().ok())
237+ .unwrap_or(x.to_string());
238+ }
239+ }
228240 // For param #0 replace {0} in args
229− value = value.replace(format!("{{{}}}", i).as_str(), x);
241+ value = value.replace(format!("{{{}}}", i).as_str(), &param);
230242 }
231243
232244 if let Ok(integer) = value.parse::<usize>() {
languages.toml+12
@@ -188,6 +188,18 @@ comment-token = "//"
188188
189189indent = { tab-width = 2, unit = " " }
190190
191+[language.debugger]
192+name = "node-debug2"
193+transport = "stdio"
194+# args consisting of cmd (node) and path to adapter should be added to user's configuration
195+quirks = { absolute-paths = true }
196+
197+[[language.debugger.templates]]
198+name = "source"
199+request = "launch"
200+completion = [ { name = "main", completion = "filename", default = "index.js" } ]
201+args = { program = "{0}" }
202+
191203[[language]]
192204name = "typescript"
193205scope = "source.ts"