dap: Fix an off-by-one and move the function over to commands/dap

pull/574/head
Blaž Hrastnik 3 years ago
parent 573cb39926
commit 54f8e5c9c3

@ -1897,7 +1897,6 @@ mod cmd {
use super::*; use super::*;
use helix_view::editor::Action; use helix_view::editor::Action;
use helix_view::editor::Breakpoint;
use ui::completers::{self, Completer}; use ui::completers::{self, Completer};
#[derive(Clone)] #[derive(Clone)]
@ -2562,22 +2561,6 @@ mod cmd {
Ok(()) 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( fn debug_start(
cx: &mut compositor::Context, cx: &mut compositor::Context,
args: &[&str], args: &[&str],

@ -1,6 +1,5 @@
use super::{align_view, Align, Context, Editor}; use super::{align_view, Align, Context, Editor};
use crate::{ use crate::{
commands,
compositor::Compositor, compositor::Compositor,
job::Callback, job::Callback,
ui::{self, FilePicker, Picker, Popup, Prompt, PromptEvent, Text}, 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)) 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 // -- DAP
pub fn dap_start_impl( pub fn dap_start_impl(
@ -381,7 +396,7 @@ fn debug_parameter_prompt(
}); });
cx.jobs.callback(callback); cx.jobs.callback(callback);
} else { } else {
commands::dap_start_impl( dap_start_impl(
cx.editor, cx.editor,
Some(&config_name), Some(&config_name),
None, 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 // 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) { 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() { let path = match doc!(cx.editor).path() {
Some(path) => path.clone(), Some(path) => path.clone(),
None => return, None => return,
@ -726,7 +741,7 @@ pub fn dap_edit_condition(cx: &mut Context) {
} }
pub fn dap_edit_log(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() { let path = match doc!(cx.editor).path() {
Some(path) => path.clone(), Some(path) => path.clone(),
None => return, None => return,

Loading…
Cancel
Save