diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index ee7aa0ebd..ae99a1595 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -57,10 +57,7 @@ pub struct LanguageConfiguration { #[serde(skip)] pub(crate) indent_query: OnceCell>, #[serde(skip_serializing_if = "Option::is_none")] - pub debug_adapter: Option, - // TODO: names for those - #[serde(skip_serializing_if = "Option::is_none")] - pub debug_configs: Option>>, + pub debugger: Option, } #[derive(Debug, Serialize, Deserialize)] diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index ed4f8ed50..43afc4c61 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -225,7 +225,9 @@ impl Client { } pub fn capabilities(&self) -> &DebuggerCapabilities { - self.caps.as_ref().expect("debugger not yet initialized!") + self.caps + .as_ref() + .expect("debugger not yet initialized!") } pub async fn initialize(&mut self, adapter_id: String) -> Result<()> { diff --git a/helix-dap/src/types.rs b/helix-dap/src/types.rs index 390fa7f38..e8543dcbf 100644 --- a/helix-dap/src/types.rs +++ b/helix-dap/src/types.rs @@ -1,6 +1,14 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::path::PathBuf; +use std::{collections::HashMap, path::PathBuf}; + +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct DebugTemplate { + pub name: String, + pub request: String, + pub args: HashMap +} #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] @@ -10,6 +18,7 @@ pub struct DebugAdapterConfig { pub command: String, pub args: Vec, pub port_arg: Option, + pub templates: Vec, } pub trait Request { diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8c1cd5d83..e762aaccf 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4392,7 +4392,6 @@ fn dap_start(cx: &mut Context) { let (_, doc) = current!(cx.editor); - // TODO config picker let path = match doc.path() { Some(path) => path.to_path_buf(), None => { @@ -4406,7 +4405,7 @@ fn dap_start(cx: &mut Context) { .editor .syn_loader .language_config_for_file_name(&path) - .and_then(|x| x.debug_adapter.clone()); + .and_then(|x| x.debugger.clone()); let config = match config { Some(c) => c, None => { @@ -4416,30 +4415,26 @@ fn dap_start(cx: &mut Context) { return; } }; + let started = Client::process(config.clone(), 0); let (mut debugger, events) = block_on(started).unwrap(); - let request = debugger.initialize(config.name); + let request = debugger.initialize(config.name.clone()); let _ = block_on(request).unwrap(); - let sessions = doc.language_config().and_then(|x| x.debug_configs.clone()); - - let sessions = match sessions { - Some(c) => c, - None => { - cx.editor.set_error( - "Can't start debug: no debug sessions available for language".to_string(), - ); + // TODO: picker + let start_config = config.templates.get(0).unwrap(); + let args = to_value(start_config.args.clone()).unwrap(); + + match &start_config.request[..] { + "launch" => block_on(debugger.launch(args)).unwrap(), + "attach" => block_on(debugger.attach(args)).unwrap(), + _ => { + cx.editor.set_error("Unsupported request".to_string()); return; } }; - // TODO: picker - let args = sessions.get(0); - - let request = debugger.launch(to_value(args).unwrap()); - let _ = block_on(request).unwrap(); - // TODO: either await "initialized" or buffer commands until event is received cx.editor.debugger = Some(debugger); let stream = UnboundedReceiverStream::new(events); diff --git a/languages.toml b/languages.toml index 756fc30be..c9b8987b9 100644 --- a/languages.toml +++ b/languages.toml @@ -19,11 +19,6 @@ config = """ language-server = { command = "rust-analyzer" } indent = { tab-width = 4, unit = " " } -debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" } - -[[language.debug-configs]] -console = "internalConsole" -program = "target/debug/rustdebug" [[language]] name = "toml" @@ -74,11 +69,6 @@ comment-token = "//" language-server = { command = "clangd" } indent = { tab-width = 2, unit = " " } -debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" } - -[[language.debug-configs]] -console = "internalConsole" -program = "main" [[language]] name = "cpp" @@ -90,11 +80,6 @@ comment-token = "//" language-server = { command = "clangd" } indent = { tab-width = 2, unit = " " } -debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" } - -[[language.debug-configs]] -console = "internalConsole" -program = "main" [[language]] name = "go" @@ -108,19 +93,28 @@ comment-token = "//" language-server = { command = "gopls" } # TODO: gopls needs utf-8 offsets? indent = { tab-width = 4, unit = "\t" } -debug-adapter = { name = "go", transport = "tcp", command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" } -[[language.debug-configs]] -mode = "debug" -program = "main.go" - -[[language.debug-configs]] -mode = "exec" -program = "main" - -[[language.debug-configs]] -mode = "test" -program = "." +[language.debugger] +name = "go" +transport = "tcp" +command = "dlv" +args = ["dap"] +port-arg = "-l 127.0.0.1:{}" + +[[language.debugger.templates]] +name = "source" +request = "launch" +args = { mode = "debug", program = "main.go" } + +[[language.debugger.templates]] +name = "binary" +request = "launch" +args = { mode = "exec", program = "main" } + +[[language.debugger.templates]] +name = "test" +request = "launch" +args = { mode = "test", program = "." } [[language]] name = "javascript"