@@ -1355,6 +1355,7 @@ fn append_mode(cx: &mut Context) {
1355mod cmd {
1355mod cmd {
1356 use super::*;
1356 use super::*;
1358+ use helix_dap::SourceBreakpoint;
1358 use helix_view::editor::Action;
1359 use helix_view::editor::Action;
1359 use ui::completers::{self, Completer};
1360 use ui::completers::{self, Completer};
@@ -1978,6 +1979,27 @@ mod cmd {
1982+ fn get_breakpoint_at_current_line(
1983+ cx: &mut compositor::Context,
1984+ ) -> Option<(usize, SourceBreakpoint)> {
1985+ let (view, doc) = current!(cx.editor);
1986+ let text = doc.text().slice(..);
1988+ let pos = doc.selection(view.id).primary().cursor(text);
1989+ let line = text.char_to_line(pos) + 1; // 1-indexing in DAP, 0-indexing in Helix
1990+ let path = match doc.path() {
1991+ Some(path) => path.to_path_buf(),
1992+ None => return None,
1995+ let breakpoints = cx.editor.breakpoints.get(&path.clone()).unwrap_or(&vec);
1996+ let i = breakpoints.iter().position(|b| b.line == line);
1998+ Some(i) => Some((i, breakpoints.get(i).unwrap().clone())),
1981 fn edit_breakpoint_impl(
2003 fn edit_breakpoint_impl(
1982 cx: &mut compositor::Context,
2004 cx: &mut compositor::Context,
1983 condition: Option<String>,
2005 condition: Option<String>,
@@ -1985,15 +2007,7 @@ mod cmd {
1985 ) -> anyhow::Result<()> {
2007 ) -> anyhow::Result<()> {
1986 use helix_lsp::block_on;
2008 use helix_lsp::block_on;
1988− let (view, doc) = current!(cx.editor);
2010+ let (_, doc) = current!(cx.editor);
1989− let text = doc.text().slice(..);
1990− let pos = doc.selection(view.id).primary().cursor(text);
1991− let breakpoint = helix_dap::SourceBreakpoint {
1992− line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
1995− ..Default::default()
1997 let path = match doc.path() {
2011 let path = match doc.path() {
1998 Some(path) => path.to_path_buf(),
2012 Some(path) => path.to_path_buf(),
1999 None => {
2013 None => {
@@ -2001,12 +2015,13 @@ mod cmd {
2018+ if let Some((pos, mut bp)) = get_breakpoint_at_current_line(cx) {
2004− let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
2019+ let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
2005− if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
2006 breakpoints.remove(pos);
2020 breakpoints.remove(pos);
2007− breakpoints.push(breakpoint);
2022+ bp.condition = condition;
2023+ bp.log_message = log_message;
2009− let breakpoints = breakpoints.clone();
2024+ breakpoints.push(bp);
2011 if let Some(debugger) = &mut cx.editor.debugger {
2026 if let Some(debugger) = &mut cx.editor.debugger {
2012 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
2027 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
@@ -2032,7 +2047,7 @@ mod cmd {
2033 // bail!("Can't edit breakpoint: debugger does not support logpoints")
2048 // bail!("Can't edit breakpoint: debugger does not support logpoints")
2035− let request = debugger.set_breakpoints(path, breakpoints);
2050+ let request = debugger.set_breakpoints(path, breakpoints.clone());
2036 if let Err(e) = block_on(request) {
2051 if let Err(e) = block_on(request) {
2037 bail!("Failed to set breakpoints: {:?}", e)
2052 bail!("Failed to set breakpoints: {:?}", e)