on master help sign in
dap: Modify breakpoints in place with no cloning
commit5f329a22c48ebf586da12323b6e1f45e9d78fdc1 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 22 Nov 2021, 11:09 (5 years ago) parent3b3c396
3 files changed+20−22
helix-term/src/commands/dap.rs+12−14 helix-term/src/ui/editor.rs+6−6 helix-view/src/view.rs+2−2
helix-term/src/commands/dap.rs+12−14
@@ -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
helix-term/src/ui/editor.rs+6−6
@@ -978,17 +978,17 @@ impl EditorView {
978978
979979 let result = editor.tree.views().find_map(|(view, _focus)| {
980980 view.gutter_coords_at_screen_coords(row, column)
981− .map(|coords| (coords.0, coords.1, view.id))
981+ .map(|coords| (coords, view.id))
982982 });
983983
984− if let Some((line, _, view_id)) = result {
984+ if let Some((coords, view_id)) = result {
985985 editor.tree.focus = view_id;
986986
987987 let doc = editor
988988 .documents
989989 .get_mut(&editor.tree.get(view_id).doc)
990990 .unwrap();
991− if let Ok(pos) = doc.text().try_line_to_char(line) {
991+ if let Ok(pos) = doc.text().try_line_to_char(coords.row) {
992992 doc.set_selection(view_id, Selection::point(pos));
993993 commands::dap_toggle_breakpoint(cxt);
994994
@@ -1080,10 +1080,10 @@ impl EditorView {
10801080 } => {
10811081 let result = cxt.editor.tree.views().find_map(|(view, _focus)| {
10821082 view.gutter_coords_at_screen_coords(row, column)
1083− .map(|coords| (coords.0, coords.1, view.id))
1083+ .map(|coords| (coords, view.id))
10841084 });
10851085
1086− if let Some((line, _, view_id)) = result {
1086+ if let Some((coords, view_id)) = result {
10871087 cxt.editor.tree.focus = view_id;
10881088
10891089 let doc = cxt
@@ -1091,7 +1091,7 @@ impl EditorView {
10911091 .documents
10921092 .get_mut(&cxt.editor.tree.get(view_id).doc)
10931093 .unwrap();
1094− if let Ok(pos) = doc.text().try_line_to_char(line) {
1094+ if let Ok(pos) = doc.text().try_line_to_char(coords.row) {
10951095 doc.set_selection(view_id, Selection::point(pos));
10961096 if modifiers == crossterm::event::KeyModifiers::ALT {
10971097 commands::Command::dap_edit_log.execute(cxt);
helix-view/src/view.rs+2−2
@@ -253,7 +253,7 @@ impl View {
253253 /// Translates screen coordinates into coordinates on the gutter of the view.
254254 /// Returns a tuple of usize typed line and column numbers starting with 0.
255255 /// Returns None if coordinates are not on the gutter.
256− pub fn gutter_coords_at_screen_coords(&self, row: u16, column: u16) -> Option<(usize, usize)> {
256+ pub fn gutter_coords_at_screen_coords(&self, row: u16, column: u16) -> Option<Position> {
257257 // 1 for status
258258 if row < self.area.top() || row >= self.area.bottom() {
259259 return None;
@@ -263,7 +263,7 @@ impl View {
263263 return None;
264264 }
265265
266− Some((
266+ Some(Position::new(
267267 (row - self.area.top()) as usize,
268268 (column - self.area.left()) as usize,
269269 ))