aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-24 09:21:00 +0000
committerDmitry Sharshakov2021-08-24 09:21:00 +0000
commit1041a5bb07457938ecfcd7da1548adf93def726b (patch)
tree0b3183b1e8131ae69709e1a980efbd726aacf843
parent0e779381a86ad6d790f3664e1d1506d01f9ba1f3 (diff)
Support launching configs by name
-rw-r--r--helix-term/src/commands.rs56
-rw-r--r--languages.toml2
2 files changed, 45 insertions, 13 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index e762aacc..7e685f8b 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2022,6 +2022,16 @@ mod cmd {
Ok(())
}
+ fn debug_start(
+ cx: &mut compositor::Context,
+ args: &[&str],
+ _event: PromptEvent,
+ ) -> anyhow::Result<()> {
+ impl_dap_start(&mut cx.editor, args.get(0).map(|name| name.to_string()));
+ // TODO templating
+ Ok(())
+ }
+
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "quit",
@@ -2262,6 +2272,13 @@ mod cmd {
completer: None,
},
TypableCommand {
+ name: "debug-start",
+ alias: None,
+ doc: "Start a debug session from a given template with given parameters.",
+ fun: debug_start,
+ completer: None,
+ },
+ TypableCommand {
name: "debug-eval",
alias: None,
doc: "Evaluate expression in current debug context.",
@@ -4385,31 +4402,29 @@ fn suspend(_cx: &mut Context) {
}
// DAP
-fn dap_start(cx: &mut Context) {
+fn impl_dap_start(editor: &mut Editor, name: Option<String>) {
use helix_dap::Client;
use helix_lsp::block_on;
use serde_json::to_value;
- let (_, doc) = current!(cx.editor);
+ let (_, doc) = current!(editor);
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());
+ editor.set_error("Can't start debug: document has no path".to_string());
return;
}
};
- let config = cx
- .editor
+ let config = editor
.syn_loader
.language_config_for_file_name(&path)
.and_then(|x| x.debugger.clone());
let config = match config {
Some(c) => c,
None => {
- cx.editor.set_error(
+ editor.set_error(
"Can't start debug: no debug adapter available for language".to_string(),
);
return;
@@ -4422,23 +4437,40 @@ fn dap_start(cx: &mut Context) {
let request = debugger.initialize(config.name.clone());
let _ = block_on(request).unwrap();
- // TODO: picker
- let start_config = config.templates.get(0).unwrap();
+ let start_config = match name {
+ Some(name) => config.templates.iter().find(|t| t.name == name),
+ None => config.templates.get(0),
+ };
+ let start_config = match start_config {
+ Some(c) => c,
+ None => {
+ editor.set_error("Can't start debug: no debug config with given name".to_string());
+ return;
+ }
+ };
+
let args = to_value(start_config.args.clone()).unwrap();
+ // TODO gracefully handle errors from debugger
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());
+ editor.set_error("Unsupported request".to_string());
return;
}
};
// TODO: either await "initialized" or buffer commands until event is received
- cx.editor.debugger = Some(debugger);
+ editor.debugger = Some(debugger);
let stream = UnboundedReceiverStream::new(events);
- cx.editor.debugger_events.push(stream);
+ editor.debugger_events.push(stream);
+}
+
+fn dap_start(cx: &mut Context) {
+ // TODO: check that first config does not have templates
+ // which cannot be handled with a shortcut
+ impl_dap_start(&mut cx.editor, None);
}
fn dap_toggle_breakpoint(cx: &mut Context) {
diff --git a/languages.toml b/languages.toml
index 266af55f..416aa802 100644
--- a/languages.toml
+++ b/languages.toml
@@ -145,7 +145,7 @@ args = { mode = "debug", program = "main.go" }
[[language.debugger.templates]]
name = "binary"
request = "launch"
-args = { mode = "exec", program = "main" }
+args = { mode = "exec", program = "./main" }
[[language.debugger.templates]]
name = "test"