@@ -2022,6 +2022,16 @@ mod cmd {
2026+ cx: &mut compositor::Context,
2028+ _event: PromptEvent,
2029+ ) -> anyhow::Result<()> {
2030+ impl_dap_start(&mut cx.editor, args.get(0).map(|name| name.to_string()));
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,
2275+ name: "debug-start",
2277+ doc: "Start a debug session from a given template with given parameters.",
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) {
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;
4393− let (_, doc) = current!(cx.editor);
4410+ let (_, doc) = current!(editor);
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 => {
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());
4404− let config = cx
4420+ let config = 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(),
@@ -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();
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),
4444+ let start_config = match start_config {
4447+ editor.set_error("Can't start debug: no debug config with given name".to_string());
4427 let args = to_value(start_config.args.clone()).unwrap();
4452 let args = to_value(start_config.args.clone()).unwrap();
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(),
4433− cx.editor.set_error("Unsupported request".to_string());
4459+ editor.set_error("Unsupported request".to_string());
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);
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);
4444fn dap_toggle_breakpoint(cx: &mut Context) {
4476fn dap_toggle_breakpoint(cx: &mut Context) {