@@ -391,6 +391,7 @@ fn debug_parameter_prompt(
391391}
392392
393393pub fn dap_toggle_breakpoint(cx: &mut Context) {
394+ // TODO: accept line instead of current selection
394395 let (view, doc) = current!(cx.editor);
395396 let text = doc.text().slice(..);
396397 let pos = doc.selection(view.id).primary().cursor(text);
@@ -413,6 +414,7 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) {
413414 // we shouldn't really allow editing while debug is running though
414415
415416 let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
417+ // TODO: always keep breakpoints sorted and use binary search
416418 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
417419 breakpoints.remove(pos);
418420 } else {
@@ -629,12 +631,14 @@ pub fn dap_disable_exceptions(cx: &mut Context) {
629631 }
630632}
631633
634+// TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets
635+// we also might be editing a breakpoint in a document that's no longer focused
632636pub fn dap_edit_condition(cx: &mut Context) {
633− if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
637+ if let Some((pos, breakpoint)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
634638 let callback = Box::pin(async move {
635639 let call: Callback =
636640 Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
637− let condition = bp.condition.clone();
641+ let condition = breakpoint.condition;
638642 let prompt = Prompt::new(
639643 "condition: ".into(),
640644 None,
@@ -657,14 +661,11 @@ pub fn dap_edit_condition(cx: &mut Context) {
657661 }
658662 };
659663
660− let breakpoints =
661− cx.editor.breakpoints.entry(path.clone()).or_default();
662− breakpoints.remove(pos);
663− bp.condition = match input {
664+ let breakpoints = &mut cx.editor.breakpoints.get_mut(path).unwrap();
665+ breakpoints[pos].condition = match input {
664666 "" => None,
665667 input => Some(input.to_owned()),
666668 };
667− breakpoints.push(bp.clone());
668669
669670 if let Some(debugger) = &mut cx.editor.debugger {
670671 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
@@ -709,11 +710,11 @@ pub fn dap_edit_condition(cx: &mut Context) {
709710}
710711
711712pub fn dap_edit_log(cx: &mut Context) {
712− if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
713+ if let Some((pos, breakpoint)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
713714 let callback = Box::pin(async move {
714715 let call: Callback =
715716 Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
716− let log_message = bp.log_message.clone();
717+ let log_message = breakpoint.log_message;
717718 let prompt = Prompt::new(
718719 "log message: ".into(),
719720 None,
@@ -736,14 +737,11 @@ pub fn dap_edit_log(cx: &mut Context) {
736737 }
737738 };
738739
739− let breakpoints =
740− cx.editor.breakpoints.entry(path.clone()).or_default();
741− breakpoints.remove(pos);
742− bp.log_message = match input {
740+ let breakpoints = &mut cx.editor.breakpoints.get_mut(path).unwrap();
741+ breakpoints[pos].log_message = match input {
743742 "" => None,
744743 input => Some(input.to_owned()),
745744 };
746− breakpoints.push(bp.clone());
747745
748746 if let Some(debugger) = &mut cx.editor.debugger {
749747 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting