on master help sign in
Support launching configs by name
1041a5bDmitry Sharshakov
helix-term/src/commands.rs+44−12
@@ -2022,6 +2022,16 @@ mod cmd {
2022 Ok(())
2022 Ok(())
2023 }
2023 }
2024
2024
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+
2025 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2035 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2026 TypableCommand {
2036 TypableCommand {
2027 name: "quit",
2037 name: "quit",
@@ -2261,6 +2271,13 @@ mod cmd {
2261 fun: tree_sitter_scopes,
2271 fun: tree_sitter_scopes,
2262 completer: None,
2272 completer: None,
2263 },
2273 },
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+ },
2264 TypableCommand {
2281 TypableCommand {
2265 name: "debug-eval",
2282 name: "debug-eval",
2266 alias: None,
2283 alias: None,
@@ -4385,31 +4402,29 @@ fn suspend(_cx: &mut Context) {
4385}
4402}
4386
4403
4387// DAP
4404// DAP
4388−fn dap_start(cx: &mut Context) {
4405+fn impl_dap_start(editor: &mut Editor, name: Option<String>) {
4389 use helix_dap::Client;
4406 use helix_dap::Client;
4390 use helix_lsp::block_on;
4407 use helix_lsp::block_on;
4391 use serde_json::to_value;
4408 use serde_json::to_value;
4392
4409
4393− let (_, doc) = current!(cx.editor);
4410+ let (_, doc) = current!(editor);
4394
4411
4395 let path = match doc.path() {
4412 let path = match doc.path() {
4396 Some(path) => path.to_path_buf(),
4413 Some(path) => path.to_path_buf(),
4397 None => {
4414 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());
4400 return;
4416 return;
4401 }
4417 }
4402 };
4418 };
4403
4419
4404− let config = cx
4420+ let config = editor
4405− .editor
4406 .syn_loader
4421 .syn_loader
4407 .language_config_for_file_name(&path)
4422 .language_config_for_file_name(&path)
4408 .and_then(|x| x.debugger.clone());
4423 .and_then(|x| x.debugger.clone());
4409 let config = match config {
4424 let config = match config {
4410 Some(c) => c,
4425 Some(c) => c,
4411 None => {
4426 None => {
4412− cx.editor.set_error(
4427+ editor.set_error(
4413 "Can't start debug: no debug adapter available for language".to_string(),
4428 "Can't start debug: no debug adapter available for language".to_string(),
4414 );
4429 );
4415 return;
4430 return;
@@ -4422,23 +4437,40 @@ fn dap_start(cx: &mut Context) {
4422 let request = debugger.initialize(config.name.clone());
4437 let request = debugger.initialize(config.name.clone());
4423 let _ = block_on(request).unwrap();
4438 let _ = block_on(request).unwrap();
4424
4439
4425− // TODO: picker
4440+ let start_config = match name {
4441+ Some(name) => config.templates.iter().find(|t| t.name == name),
4426− let start_config = config.templates.get(0).unwrap();
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+
4427 let args = to_value(start_config.args.clone()).unwrap();
4452 let args = to_value(start_config.args.clone()).unwrap();
4428
4453
4454+ // TODO gracefully handle errors from debugger
4429 match &start_config.request[..] {
4455 match &start_config.request[..] {
4430 "launch" => block_on(debugger.launch(args)).unwrap(),
4456 "launch" => block_on(debugger.launch(args)).unwrap(),
4431 "attach" => block_on(debugger.attach(args)).unwrap(),
4457 "attach" => block_on(debugger.attach(args)).unwrap(),
4432 _ => {
4458 _ => {
4433− cx.editor.set_error("Unsupported request".to_string());
4459+ editor.set_error("Unsupported request".to_string());
4434 return;
4460 return;
4435 }
4461 }
4436 };
4462 };
4437
4463
4438 // TODO: either await "initialized" or buffer commands until event is received
4464 // TODO: either await "initialized" or buffer commands until event is received
4439− cx.editor.debugger = Some(debugger);
4465+ editor.debugger = Some(debugger);
4440 let stream = UnboundedReceiverStream::new(events);
4466 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);
4442}
4474}
4443
4475
4444fn dap_toggle_breakpoint(cx: &mut Context) {
4476fn dap_toggle_breakpoint(cx: &mut Context) {
languages.toml+1−1
@@ -145,7 +145,7 @@ args = { mode = "debug", program = "main.go" }
145[[language.debugger.templates]]
145[[language.debugger.templates]]
146name = "binary"
146name = "binary"
147request = "launch"
147request = "launch"
148−args = { mode = "exec", program = "main" }
148+args = { mode = "exec", program = "./main" }
149
149
150[[language.debugger.templates]]
150[[language.debugger.templates]]
151name = "test"
151name = "test"