@@ -392,22 +392,25 @@ fn debug_parameter_prompt(
392392pub fn dap_toggle_breakpoint(cx: &mut Context) {
393393 // TODO: accept line instead of current selection
394394 let (view, doc) = current!(cx.editor);
395− let text = doc.text().slice(..);
396− let pos = doc.selection(view.id).primary().cursor(text);
397−
398− let breakpoint = helix_dap::SourceBreakpoint {
399− line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
400− ..Default::default()
401− };
402−
403395 let path = match doc.path() {
404− Some(path) => path,
396+ Some(path) => path.clone(),
405397 None => {
406398 cx.editor
407399 .set_error("Can't set breakpoint: document has no path".to_string());
408400 return;
409401 }
410402 };
403+ let text = doc.text().slice(..);
404+ let pos = doc.selection(view.id).primary().cursor(text);
405+ let line = text.char_to_line(pos);
406+ dap_toggle_breakpoint_impl(cx, path, line);
407+}
408+
409+pub fn dap_toggle_breakpoint_impl(cx: &mut Context, path: std::path::PathBuf, line: usize) {
410+ let breakpoint = helix_dap::SourceBreakpoint {
411+ line: line + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
412+ ..Default::default()
413+ };
411414
412415 // TODO: need to map breakpoints over edits and update them?
413416 // we shouldn't really allow editing while debug is running though
@@ -429,16 +432,8 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) {
429432 let request = debugger.set_breakpoints(path.clone(), breakpoints);
430433 match block_on(request) {
431434 Ok(Some(breakpoints)) => {
432− // TODO: avoid this clone here
433− let old_breakpoints = std::mem::replace(&mut debugger.breakpoints, breakpoints.clone());
434− for bp in breakpoints {
435− if !old_breakpoints.iter().any(|b| b.message == bp.message) {
436− if let Some(msg) = &bp.message {
437− cx.editor.set_status(format!("Breakpoint set: {}", msg));
438− break;
439− }
440− }
441− }
435+ // TODO: handle breakpoint.message
436+ debugger.breakpoints = breakpoints;
442437 }
443438 Err(e) => cx
444439 .editor