on master help sign in
dap: Fix an off-by-one and move the function over to commands/dap
54f8e5cBlaž Hrastnik
helix-term/src/commands.rs−17
@@ -1897,7 +1897,6 @@ mod cmd {
1897 use super::*;
1897 use super::*;
1898
1898
1899 use helix_view::editor::Action;
1899 use helix_view::editor::Action;
1900− use helix_view::editor::Breakpoint;
1901 use ui::completers::{self, Completer};
1900 use ui::completers::{self, Completer};
1902
1901
1903 #[derive(Clone)]
1902 #[derive(Clone)]
@@ -2562,22 +2561,6 @@ mod cmd {
2562 Ok(())
2561 Ok(())
2563 }
2562 }
2564
2563
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−
2581 fn debug_start(
2564 fn debug_start(
2582 cx: &mut compositor::Context,
2565 cx: &mut compositor::Context,
2583 args: &[&str],
2566 args: &[&str],
helix-term/src/commands/dap.rs+19−4
@@ -1,6 +1,5 @@
1use super::{align_view, Align, Context, Editor};
1use super::{align_view, Align, Context, Editor};
2use crate::{
2use crate::{
3− commands,
4 compositor::Compositor,
3 compositor::Compositor,
5 job::Callback,
4 job::Callback,
6 ui::{self, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
5 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
161 cx.push_layer(Box::new(picker))
160 cx.push_layer(Box::new(picker))
162}
161}
163
162
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+
164// -- DAP
179// -- DAP
165
180
166pub fn dap_start_impl(
181pub fn dap_start_impl(
@@ -381,7 +396,7 @@ fn debug_parameter_prompt(
381 });
396 });
382 cx.jobs.callback(callback);
397 cx.jobs.callback(callback);
383 } else {
398 } else {
384− commands::dap_start_impl(
399+ dap_start_impl(
385 cx.editor,
400 cx.editor,
386 Some(&config_name),
401 Some(&config_name),
387 None,
402 None,
@@ -679,7 +694,7 @@ pub fn dap_disable_exceptions(cx: &mut Context) {
679
694
680// TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets
695// TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets
681pub fn dap_edit_condition(cx: &mut Context) {
696pub 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) {
683 let path = match doc!(cx.editor).path() {
698 let path = match doc!(cx.editor).path() {
684 Some(path) => path.clone(),
699 Some(path) => path.clone(),
685 None => return,
700 None => return,
@@ -726,7 +741,7 @@ pub fn dap_edit_condition(cx: &mut Context) {
726}
741}
727
742
728pub fn dap_edit_log(cx: &mut Context) {
743pub 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) {
730 let path = match doc!(cx.editor).path() {
745 let path = match doc!(cx.editor).path() {
731 Some(path) => path.clone(),
746 Some(path) => path.clone(),
732 None => return,
747 None => return,