aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands/dap.rs33
-rw-r--r--helix-term/src/ui/editor.rs29
2 files changed, 30 insertions, 32 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 441348f6..c9bee70f 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -392,22 +392,25 @@ fn debug_parameter_prompt(
pub fn dap_toggle_breakpoint(cx: &mut Context) {
// TODO: accept line instead of current selection
let (view, doc) = current!(cx.editor);
- let text = doc.text().slice(..);
- let pos = doc.selection(view.id).primary().cursor(text);
-
- let breakpoint = helix_dap::SourceBreakpoint {
- line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
- ..Default::default()
- };
-
let path = match doc.path() {
- Some(path) => path,
+ Some(path) => path.clone(),
None => {
cx.editor
.set_error("Can't set breakpoint: document has no path".to_string());
return;
}
};
+ let text = doc.text().slice(..);
+ let pos = doc.selection(view.id).primary().cursor(text);
+ let line = text.char_to_line(pos);
+ dap_toggle_breakpoint_impl(cx, path, line);
+}
+
+pub fn dap_toggle_breakpoint_impl(cx: &mut Context, path: std::path::PathBuf, line: usize) {
+ let breakpoint = helix_dap::SourceBreakpoint {
+ line: line + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
+ ..Default::default()
+ };
// TODO: need to map breakpoints over edits and update them?
// we shouldn't really allow editing while debug is running though
@@ -429,16 +432,8 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) {
let request = debugger.set_breakpoints(path.clone(), breakpoints);
match block_on(request) {
Ok(Some(breakpoints)) => {
- // TODO: avoid this clone here
- let old_breakpoints = std::mem::replace(&mut debugger.breakpoints, breakpoints.clone());
- for bp in breakpoints {
- if !old_breakpoints.iter().any(|b| b.message == bp.message) {
- if let Some(msg) = &bp.message {
- cx.editor.set_status(format!("Breakpoint set: {}", msg));
- break;
- }
- }
- }
+ // TODO: handle breakpoint.message
+ debugger.breakpoints = breakpoints;
}
Err(e) => cx
.editor
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index de2281c6..0e243271 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -985,14 +985,19 @@ impl EditorView {
if let Some((coords, view_id)) = result {
editor.tree.focus = view_id;
- let doc = editor
- .documents
- .get_mut(&editor.tree.get(view_id).doc)
- .unwrap();
- if let Ok(pos) = doc.text().try_line_to_char(coords.row) {
- doc.set_selection(view_id, Selection::point(pos));
- commands::dap_toggle_breakpoint(cxt);
+ let view = editor.tree.get(view_id);
+ let doc = editor.documents.get_mut(&view.doc).unwrap();
+
+ let path = match doc.path() {
+ Some(path) => path.clone(),
+ None => {
+ return EventResult::Ignored;
+ }
+ };
+ let line = coords.row + view.offset.row;
+ if line < doc.text().len_lines() {
+ commands::dap_toggle_breakpoint_impl(cxt, path, line);
return EventResult::Consumed(None);
}
}
@@ -1087,12 +1092,10 @@ impl EditorView {
if let Some((coords, view_id)) = result {
cxt.editor.tree.focus = view_id;
- let doc = cxt
- .editor
- .documents
- .get_mut(&cxt.editor.tree.get(view_id).doc)
- .unwrap();
- if let Ok(pos) = doc.text().try_line_to_char(coords.row) {
+ let view = cxt.editor.tree.get(view_id);
+ let doc = cxt.editor.documents.get_mut(&view.doc).unwrap();
+ let line = coords.row + view.offset.row;
+ if let Ok(pos) = doc.text().try_line_to_char(line) {
doc.set_selection(view_id, Selection::point(pos));
if modifiers == crossterm::event::KeyModifiers::ALT {
commands::Command::dap_edit_log.execute(cxt);