aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands/dap.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-12-02 01:21:28 +0000
committerBlaž Hrastnik2021-12-02 01:22:17 +0000
commit54f8e5c9c3c3295b7756adde504f403d36965734 (patch)
tree875ed4a5b303125104f706039b169b83df8cb537 /helix-term/src/commands/dap.rs
parent573cb399261f9ab8f799dcf82a40220dcc6539e4 (diff)
dap: Fix an off-by-one and move the function over to commands/dap
Diffstat (limited to 'helix-term/src/commands/dap.rs')
-rw-r--r--helix-term/src/commands/dap.rs23
1 files changed, 19 insertions, 4 deletions
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,