on master help sign in
dap: Fix an off-by-one and move the function over to commands/dap
commit54f8e5c9c3c3295b7756adde504f403d36965734 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 2 Dec 2021, 10:21 (5 years ago) parent573cb39
2 files changed+19−21
helix-term/src/commands.rs−17 helix-term/src/commands/dap.rs+19−4
helix-term/src/commands.rs−17
@@ -1897,7 +1897,6 @@ mod cmd {
18971897 use super::*;
18981898
18991899 use helix_view::editor::Action;
1900− use helix_view::editor::Breakpoint;
19011900 use ui::completers::{self, Completer};
19021901
19031902 #[derive(Clone)]
@@ -2562,22 +2561,6 @@ mod cmd {
25622561 Ok(())
25632562 }
25642563
2565− pub fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> {
2566− let (view, doc) = current!(editor);
2567− let text = doc.text().slice(..);
2568−
2569− let pos = doc.selection(view.id).primary().cursor(text);
2570− let line = text.char_to_line(pos) + 1; // 1-indexing in DAP, 0-indexing in Helix
2571− let path = match doc.path() {
2572− Some(path) => path,
2573− None => return None,
2574− };
2575− editor.breakpoints.get(path).and_then(|breakpoints| {
2576− let i = breakpoints.iter().position(|b| b.line == line);
2577− i.map(|i| (i, breakpoints[i].clone()))
2578− })
2579− }
2580−
25812564 fn debug_start(
25822565 cx: &mut compositor::Context,
25832566 args: &[&str],
helix-term/src/commands/dap.rs+19−4
@@ -1,6 +1,5 @@
11use super::{align_view, Align, Context, Editor};
22use crate::{
3− commands,
43 compositor::Compositor,
54 job::Callback,
65 ui::{self, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
@@ -161,6 +160,22 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
161160 cx.push_layer(Box::new(picker))
162161}
163162
163+fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> {
164+ let (view, doc) = current!(editor);
165+ let text = doc.text().slice(..);
166+
167+ let pos = doc.selection(view.id).primary().cursor(text);
168+ let line = text.char_to_line(pos);
169+ let path = match doc.path() {
170+ Some(path) => path,
171+ None => return None,
172+ };
173+ editor.breakpoints.get(path).and_then(|breakpoints| {
174+ let i = breakpoints.iter().position(|b| b.line == line);
175+ i.map(|i| (i, breakpoints[i].clone()))
176+ })
177+}
178+
164179// -- DAP
165180
166181pub fn dap_start_impl(
@@ -381,7 +396,7 @@ fn debug_parameter_prompt(
381396 });
382397 cx.jobs.callback(callback);
383398 } else {
384− commands::dap_start_impl(
399+ dap_start_impl(
385400 cx.editor,
386401 Some(&config_name),
387402 None,
@@ -679,7 +694,7 @@ pub fn dap_disable_exceptions(cx: &mut Context) {
679694
680695// TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets
681696pub fn dap_edit_condition(cx: &mut Context) {
682− if let Some((pos, breakpoint)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
697+ if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) {
683698 let path = match doc!(cx.editor).path() {
684699 Some(path) => path.clone(),
685700 None => return,
@@ -726,7 +741,7 @@ pub fn dap_edit_condition(cx: &mut Context) {
726741}
727742
728743pub fn dap_edit_log(cx: &mut Context) {
729− if let Some((pos, breakpoint)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
744+ if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) {
730745 let path = match doc!(cx.editor).path() {
731746 Some(path) => path.clone(),
732747 None => return,