@@ -391,6 +391,7 @@ fn debug_parameter_prompt(
393pub fn dap_toggle_breakpoint(cx: &mut Context) {
393pub fn dap_toggle_breakpoint(cx: &mut Context) {
394+ // TODO: accept line instead of current selection
394 let (view, doc) = current!(cx.editor);
395 let (view, doc) = current!(cx.editor);
395 let text = doc.text().slice(..);
396 let text = doc.text().slice(..);
396 let pos = doc.selection(view.id).primary().cursor(text);
397 let pos = doc.selection(view.id).primary().cursor(text);
@@ -413,6 +414,7 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) {
413 // we shouldn't really allow editing while debug is running though
414 // we shouldn't really allow editing while debug is running though
415 let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
416 let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
417+ // TODO: always keep breakpoints sorted and use binary search
416 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
418 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
417 breakpoints.remove(pos);
419 breakpoints.remove(pos);
@@ -629,12 +631,14 @@ pub fn dap_disable_exceptions(cx: &mut Context) {
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
632pub fn dap_edit_condition(cx: &mut Context) {
636pub 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) {
634 let callback = Box::pin(async move {
638 let callback = Box::pin(async move {
635 let call: Callback =
639 let call: Callback =
636 Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
640 Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
637− let condition = bp.condition.clone();
641+ let condition = breakpoint.condition;
638 let prompt = Prompt::new(
642 let prompt = Prompt::new(
639 "condition: ".into(),
643 "condition: ".into(),
@@ -657,14 +661,11 @@ pub fn dap_edit_condition(cx: &mut Context) {
661− cx.editor.breakpoints.entry(path.clone()).or_default();
664+ let breakpoints = &mut cx.editor.breakpoints.get_mut(path).unwrap();
662− breakpoints.remove(pos);
663− bp.condition = match input {
665+ breakpoints[pos].condition = match input {
664 "" => None,
666 "" => None,
665 input => Some(input.to_owned()),
667 input => Some(input.to_owned()),
667− breakpoints.push(bp.clone());
669 if let Some(debugger) = &mut cx.editor.debugger {
670 if let Some(debugger) = &mut cx.editor.debugger {
670 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
671 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
@@ -709,11 +710,11 @@ pub fn dap_edit_condition(cx: &mut Context) {
711pub fn dap_edit_log(cx: &mut Context) {
712pub 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) {
713 let callback = Box::pin(async move {
714 let callback = Box::pin(async move {
714 let call: Callback =
715 let call: Callback =
715 Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
716 Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
716− let log_message = bp.log_message.clone();
717+ let log_message = breakpoint.log_message;
717 let prompt = Prompt::new(
718 let prompt = Prompt::new(
718 "log message: ".into(),
719 "log message: ".into(),
@@ -736,14 +737,11 @@ pub fn dap_edit_log(cx: &mut Context) {
740− cx.editor.breakpoints.entry(path.clone()).or_default();
740+ let breakpoints = &mut cx.editor.breakpoints.get_mut(path).unwrap();
741− breakpoints.remove(pos);
742− bp.log_message = match input {
741+ breakpoints[pos].log_message = match input {
743 "" => None,
742 "" => None,
744 input => Some(input.to_owned()),
743 input => Some(input.to_owned()),
746− breakpoints.push(bp.clone());
748 if let Some(debugger) = &mut cx.editor.debugger {
746 if let Some(debugger) = &mut cx.editor.debugger {
749 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
747 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting