on master help sign in
dap: Allow switching between stack frames
commitc63ad60c31cb51481b227c1d610d3eb7b2f95529 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 3 Sep 2021, 17:25 (5 years ago) parent7b61c63
3 files changed+52−2
helix-term/src/commands.rs+1 helix-term/src/commands/dap.rs+50−1 helix-term/src/keymap.rs+1−1
helix-term/src/commands.rs+1
@@ -318,6 +318,7 @@ impl Command {
318318 dap_variables, "List variables",
319319 dap_terminate, "End debug session",
320320 dap_switch_thread, "Switch current thread",
321+ dap_switch_stack_frame, "Switch stack frame",
321322 shell_pipe, "Pipe selections through shell command",
322323 shell_pipe_to, "Pipe selections into shell command, ignoring command output",
323324 shell_insert_output, "Insert output of shell command before each selection",
helix-term/src/commands/dap.rs+50−1
@@ -1,5 +1,5 @@
11use super::{align_view, Align, Context, Editor};
2−use crate::ui::Picker;
2+use crate::ui::{FilePicker, Picker};
33use helix_core::Selection;
44use helix_dap::{self as dap, Client};
55use helix_lsp::block_on;
@@ -461,3 +461,52 @@ pub fn dap_switch_thread(cx: &mut Context) {
461461 block_on(select_thread_id(editor, thread.id, true));
462462 })
463463}
464+pub fn dap_switch_stack_frame(cx: &mut Context) {
465+ let debugger = match &mut cx.editor.debugger {
466+ Some(debugger) => debugger,
467+ None => return,
468+ };
469+
470+ let thread_id = match debugger.thread_id {
471+ Some(thread_id) => thread_id,
472+ None => {
473+ cx.editor
474+ .set_error(format!("No thread is currently active"));
475+ return;
476+ }
477+ };
478+
479+ let frames = debugger.stack_frames[&thread_id].clone();
480+
481+ let picker = FilePicker::new(
482+ frames,
483+ |frame| frame.name.clone().into(), // TODO: include thread_states in the label
484+ move |editor, frame, _action| {
485+ let debugger = match &mut editor.debugger {
486+ Some(debugger) => debugger,
487+ None => return,
488+ };
489+ // TODO: this should be simpler to find
490+ let pos = debugger.stack_frames[&thread_id]
491+ .iter()
492+ .position(|f| f.id == frame.id);
493+ debugger.active_frame = pos;
494+ },
495+ move |_editor, frame| {
496+ frame
497+ .source
498+ .as_ref()
499+ .and_then(|source| source.path.clone())
500+ .map(|path| {
501+ (
502+ path,
503+ Some((
504+ frame.line.saturating_sub(1),
505+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
506+ )),
507+ )
508+ })
509+ },
510+ );
511+ cx.push_layer(Box::new(picker))
512+}
helix-term/src/keymap.rs+1−1
@@ -499,7 +499,7 @@ impl Default for Keymaps {
499499 "t" => dap_terminate,
500500 "s" => { "Switch"
501501 "t" => dap_switch_thread,
502− // f = stack frame
502+ "f" => dap_switch_stack_frame,
503503 // sl, sb
504504 },
505505 },