@@ -392,22 +392,25 @@ fn debug_parameter_prompt(
392pub fn dap_toggle_breakpoint(cx: &mut Context) {
392pub fn dap_toggle_breakpoint(cx: &mut Context) {
393 // TODO: accept line instead of current selection
393 // TODO: accept line instead of current selection
394 let (view, doc) = current!(cx.editor);
394 let (view, doc) = current!(cx.editor);
395− let text = doc.text().slice(..);
396− let pos = doc.selection(view.id).primary().cursor(text);
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()
403 let path = match doc.path() {
395 let path = match doc.path() {
404− Some(path) => path,
396+ Some(path) => path.clone(),
405 None => {
397 None => {
406 cx.editor
398 cx.editor
407 .set_error("Can't set breakpoint: document has no path".to_string());
399 .set_error("Can't set breakpoint: document has no path".to_string());
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);
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()
412 // TODO: need to map breakpoints over edits and update them?
415 // TODO: need to map breakpoints over edits and update them?
413 // we shouldn't really allow editing while debug is running though
416 // we shouldn't really allow editing while debug is running though
@@ -429,16 +432,8 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) {
429 let request = debugger.set_breakpoints(path.clone(), breakpoints);
432 let request = debugger.set_breakpoints(path.clone(), breakpoints);
430 match block_on(request) {
433 match block_on(request) {
431 Ok(Some(breakpoints)) => {
434 Ok(Some(breakpoints)) => {
432− // TODO: avoid this clone here
435+ // TODO: handle breakpoint.message
433− let old_breakpoints = std::mem::replace(&mut debugger.breakpoints, breakpoints.clone());
434− for bp in breakpoints {
436+ debugger.breakpoints = 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));
443 Err(e) => cx
438 Err(e) => cx