Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/generated/static-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
| `goto_prev_paragraph` | Goto previous paragraph | normal: `` [p ``, select: `` [p `` |
| `dap_launch` | Launch debug target | normal: `` <space>Gl ``, select: `` <space>Gl `` |
| `dap_restart` | Restart debugging session | normal: `` <space>Gr ``, select: `` <space>Gr `` |
| `dap_toggle_breakpoint` | Toggle breakpoint | normal: `` <space>Gb ``, select: `` <space>Gb `` |
| `dap_toggle_breakpoints` | Toggle breakpoints | normal: `` <space>Gb ``, select: `` <space>Gb `` |
| `dap_continue` | Continue program execution | normal: `` <space>Gc ``, select: `` <space>Gc `` |
| `dap_pause` | Pause program execution | normal: `` <space>Gh ``, select: `` <space>Gh `` |
| `dap_step_in` | Step in | normal: `` <space>Gi ``, select: `` <space>Gi `` |
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ impl MappableCommand {
goto_prev_paragraph, "Goto previous paragraph",
dap_launch, "Launch debug target",
dap_restart, "Restart debugging session",
dap_toggle_breakpoint, "Toggle breakpoint",
dap_toggle_breakpoints, "Toggle breakpoints",
dap_continue, "Continue program execution",
dap_pause, "Pause program execution",
dap_step_in, "Step in",
Expand Down
40 changes: 26 additions & 14 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn debug_parameter_prompt(
)
}

pub fn dap_toggle_breakpoint(cx: &mut Context) {
pub fn dap_toggle_breakpoints(cx: &mut Context) {
let (view, doc) = current!(cx.editor);

let Some(path) = doc.path().map(ToOwned::to_owned) else {
Expand All @@ -408,26 +408,38 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) {
};

let text = doc.text().slice(..);
let line = doc.selection(view.id).primary().cursor_line(text);
dap_toggle_breakpoint_impl(cx, path, line);

let mut lines: Vec<usize> = doc
.selection(view.id)
.ranges()
.iter()
.map(|r| r.cursor_line(text))
.collect();
lines.sort();
lines.dedup();

dap_toggle_breakpoints_impl(cx, path, lines);
}

pub fn dap_toggle_breakpoint_impl(cx: &mut Context, path: PathBuf, line: usize) {
pub fn dap_toggle_breakpoints_impl(cx: &mut Context, path: PathBuf, lines: Vec<usize>) {
// TODO: need to map breakpoints over edits and update them?
// we shouldn't really allow editing while debug is running though

let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
// TODO: always keep breakpoints sorted and use binary search to determine insertion point
if let Some(pos) = breakpoints
.iter()
.position(|breakpoint| breakpoint.line == line)
{
breakpoints.remove(pos);
} else {
breakpoints.push(Breakpoint {
line,
..Default::default()
});

for line in lines {
if let Some(pos) = breakpoints
.iter()
.position(|breakpoint| breakpoint.line == line)
{
breakpoints.remove(pos);
} else {
breakpoints.push(Breakpoint {
line,
..Default::default()
});
}
}

let debugger = debugger!(cx.editor);
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"G" => { "Debug (experimental)" sticky=true
"l" => dap_launch,
"r" => dap_restart,
"b" => dap_toggle_breakpoint,
"b" => dap_toggle_breakpoints,
"c" => dap_continue,
"h" => dap_pause,
"i" => dap_step_in,
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ impl EditorView {
view.pos_at_visual_coords(doc, coords.row as u16, coords.col as u16, true)
{
let line = doc.text().char_to_line(char_idx);
commands::dap_toggle_breakpoint_impl(cxt, path, line);
commands::dap_toggle_breakpoints_impl(cxt, path, vec![line]);
return EventResult::Consumed(None);
}
}
Expand Down