From f55a012fb744b258ac84ac0302cb0b87f7d35173 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Mon, 23 Aug 2021 16:56:41 +0300 Subject: [PATCH] editor: add debug session config --- helix-core/src/syntax.rs | 2 ++ helix-term/src/commands.rs | 21 ++++++++++++++++++--- languages.toml | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index f3272cff..cfe5f5a1 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -58,6 +58,8 @@ pub struct LanguageConfiguration { pub(crate) indent_query: OnceCell>, #[serde(skip_serializing_if = "Option::is_none")] pub debug_adapter: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub debug_configs: Option>>, } #[derive(Debug, Serialize, Deserialize)] diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3b8e1022..9ecc5bfe 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4368,9 +4368,24 @@ fn dap_start(cx: &mut Context) { let request = debugger.initialize("go".to_owned()); let _ = block_on(request).unwrap(); - let mut args = HashMap::new(); - args.insert("mode", "debug"); - args.insert("program", "main.go"); + let sessions = cx + .editor + .syn_loader + .language_config_for_file_name(&path) + .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(), + ); + return; + } + }; + + // TODO: picker + let args = sessions.get(0); let request = debugger.launch(to_value(args).unwrap()); let _ = block_on(request).unwrap(); diff --git a/languages.toml b/languages.toml index 61b68e59..00d81b50 100644 --- a/languages.toml +++ b/languages.toml @@ -95,6 +95,21 @@ language-server = { command = "gopls" } indent = { tab-width = 4, unit = "\t" } debug-adapter = { command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" } +[[language.debug-configs]] +request = "launch" +mode = "debug" +program = "main.go" + +[[language.debug-configs]] +request = "launch" +mode = "exec" +program = "main" + +[[language.debug-configs]] +request = "launch" +mode = "test" +program = "." + [[language]] name = "javascript" scope = "source.js"