From 54f8e5c9c3c3295b7756adde504f403d36965734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 2 Dec 2021 10:21:28 +0900 Subject: [PATCH] dap: Fix an off-by-one and move the function over to commands/dap --- helix-term/src/commands.rs | 17 ----------------- helix-term/src/commands/dap.rs | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 6a611edb..9a978c4c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1897,7 +1897,6 @@ mod cmd { use super::*; use helix_view::editor::Action; - use helix_view::editor::Breakpoint; use ui::completers::{self, Completer}; #[derive(Clone)] @@ -2562,22 +2561,6 @@ mod cmd { Ok(()) } - pub fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> { - let (view, doc) = current!(editor); - let text = doc.text().slice(..); - - let pos = doc.selection(view.id).primary().cursor(text); - let line = text.char_to_line(pos) + 1; // 1-indexing in DAP, 0-indexing in Helix - let path = match doc.path() { - Some(path) => path, - None => return None, - }; - editor.breakpoints.get(path).and_then(|breakpoints| { - let i = breakpoints.iter().position(|b| b.line == line); - i.map(|i| (i, breakpoints[i].clone())) - }) - } - fn debug_start( cx: &mut compositor::Context, args: &[&str], diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 00305fe2..d009e84b 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -1,6 +1,5 @@ use super::{align_view, Align, Context, Editor}; use crate::{ - commands, compositor::Compositor, job::Callback, 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 cx.push_layer(Box::new(picker)) } +fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> { + let (view, doc) = current!(editor); + let text = doc.text().slice(..); + + let pos = doc.selection(view.id).primary().cursor(text); + let line = text.char_to_line(pos); + let path = match doc.path() { + Some(path) => path, + None => return None, + }; + editor.breakpoints.get(path).and_then(|breakpoints| { + let i = breakpoints.iter().position(|b| b.line == line); + i.map(|i| (i, breakpoints[i].clone())) + }) +} + // -- DAP pub fn dap_start_impl( @@ -381,7 +396,7 @@ fn debug_parameter_prompt( }); cx.jobs.callback(callback); } else { - commands::dap_start_impl( + dap_start_impl( cx.editor, Some(&config_name), None, @@ -679,7 +694,7 @@ pub fn dap_disable_exceptions(cx: &mut Context) { // TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets pub fn dap_edit_condition(cx: &mut Context) { - if let Some((pos, breakpoint)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) { + if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) { let path = match doc!(cx.editor).path() { Some(path) => path.clone(), None => return, @@ -726,7 +741,7 @@ pub fn dap_edit_condition(cx: &mut Context) { } pub fn dap_edit_log(cx: &mut Context) { - if let Some((pos, breakpoint)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) { + if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) { let path = match doc!(cx.editor).path() { Some(path) => path.clone(), None => return,