on master help sign in
Support launching configs by name
commit1041a5bb07457938ecfcd7da1548adf93def726b authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateTue 24 Aug 2021, 12:21 (5 years ago) parent0e77938
2 files changed+45−13
helix-term/src/commands.rs+44−12 languages.toml+1−1
helix-term/src/commands.rs+44−12
@@ -2022,6 +2022,16 @@ mod cmd {
20222022 Ok(())
20232023 }
20242024
2025+ fn debug_start(
2026+ cx: &mut compositor::Context,
2027+ args: &[&str],
2028+ _event: PromptEvent,
2029+ ) -> anyhow::Result<()> {
2030+ impl_dap_start(&mut cx.editor, args.get(0).map(|name| name.to_string()));
2031+ // TODO templating
2032+ Ok(())
2033+ }
2034+
20252035 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
20262036 TypableCommand {
20272037 name: "quit",
@@ -2261,6 +2271,13 @@ mod cmd {
22612271 fun: tree_sitter_scopes,
22622272 completer: None,
22632273 },
2274+ TypableCommand {
2275+ name: "debug-start",
2276+ alias: None,
2277+ doc: "Start a debug session from a given template with given parameters.",
2278+ fun: debug_start,
2279+ completer: None,
2280+ },
22642281 TypableCommand {
22652282 name: "debug-eval",
22662283 alias: None,
@@ -4385,31 +4402,29 @@ fn suspend(_cx: &mut Context) {
43854402}
43864403
43874404// DAP
4388−fn dap_start(cx: &mut Context) {
4405+fn impl_dap_start(editor: &mut Editor, name: Option<String>) {
43894406 use helix_dap::Client;
43904407 use helix_lsp::block_on;
43914408 use serde_json::to_value;
43924409
4393− let (_, doc) = current!(cx.editor);
4410+ let (_, doc) = current!(editor);
43944411
43954412 let path = match doc.path() {
43964413 Some(path) => path.to_path_buf(),
43974414 None => {
4398− cx.editor
4399− .set_error("Can't start debug: document has no path".to_string());
4415+ editor.set_error("Can't start debug: document has no path".to_string());
44004416 return;
44014417 }
44024418 };
44034419
4404− let config = cx
4405− .editor
4420+ let config = editor
44064421 .syn_loader
44074422 .language_config_for_file_name(&path)
44084423 .and_then(|x| x.debugger.clone());
44094424 let config = match config {
44104425 Some(c) => c,
44114426 None => {
4412− cx.editor.set_error(
4427+ editor.set_error(
44134428 "Can't start debug: no debug adapter available for language".to_string(),
44144429 );
44154430 return;
@@ -4422,23 +4437,40 @@ fn dap_start(cx: &mut Context) {
44224437 let request = debugger.initialize(config.name.clone());
44234438 let _ = block_on(request).unwrap();
44244439
4425− // TODO: picker
4426− let start_config = config.templates.get(0).unwrap();
4440+ let start_config = match name {
4441+ Some(name) => config.templates.iter().find(|t| t.name == name),
4442+ None => config.templates.get(0),
4443+ };
4444+ let start_config = match start_config {
4445+ Some(c) => c,
4446+ None => {
4447+ editor.set_error("Can't start debug: no debug config with given name".to_string());
4448+ return;
4449+ }
4450+ };
4451+
44274452 let args = to_value(start_config.args.clone()).unwrap();
44284453
4454+ // TODO gracefully handle errors from debugger
44294455 match &start_config.request[..] {
44304456 "launch" => block_on(debugger.launch(args)).unwrap(),
44314457 "attach" => block_on(debugger.attach(args)).unwrap(),
44324458 _ => {
4433− cx.editor.set_error("Unsupported request".to_string());
4459+ editor.set_error("Unsupported request".to_string());
44344460 return;
44354461 }
44364462 };
44374463
44384464 // TODO: either await "initialized" or buffer commands until event is received
4439− cx.editor.debugger = Some(debugger);
4465+ editor.debugger = Some(debugger);
44404466 let stream = UnboundedReceiverStream::new(events);
4441− cx.editor.debugger_events.push(stream);
4467+ editor.debugger_events.push(stream);
4468+}
4469+
4470+fn dap_start(cx: &mut Context) {
4471+ // TODO: check that first config does not have templates
4472+ // which cannot be handled with a shortcut
4473+ impl_dap_start(&mut cx.editor, None);
44424474}
44434475
44444476fn dap_toggle_breakpoint(cx: &mut Context) {
languages.toml+1−1
@@ -145,7 +145,7 @@ args = { mode = "debug", program = "main.go" }
145145[[language.debugger.templates]]
146146name = "binary"
147147request = "launch"
148−args = { mode = "exec", program = "main" }
148+args = { mode = "exec", program = "./main" }
149149
150150[[language.debugger.templates]]
151151name = "test"