on master help sign in
dap: Allow switching between stack frames
c63ad60Blaž Hrastnik
helix-term/src/commands.rs+1
@@ -318,6 +318,7 @@ impl Command {
318 dap_variables, "List variables",
318 dap_variables, "List variables",
319 dap_terminate, "End debug session",
319 dap_terminate, "End debug session",
320 dap_switch_thread, "Switch current thread",
320 dap_switch_thread, "Switch current thread",
321+ dap_switch_stack_frame, "Switch stack frame",
321 shell_pipe, "Pipe selections through shell command",
322 shell_pipe, "Pipe selections through shell command",
322 shell_pipe_to, "Pipe selections into shell command, ignoring command output",
323 shell_pipe_to, "Pipe selections into shell command, ignoring command output",
323 shell_insert_output, "Insert output of shell command before each selection",
324 shell_insert_output, "Insert output of shell command before each selection",
helix-term/src/commands/dap.rs+50−1
@@ -1,5 +1,5 @@
1use super::{align_view, Align, Context, Editor};
1use super::{align_view, Align, Context, Editor};
2−use crate::ui::Picker;
2+use crate::ui::{FilePicker, Picker};
3use helix_core::Selection;
3use helix_core::Selection;
4use helix_dap::{self as dap, Client};
4use helix_dap::{self as dap, Client};
5use helix_lsp::block_on;
5use helix_lsp::block_on;
@@ -461,3 +461,52 @@ pub fn dap_switch_thread(cx: &mut Context) {
461 block_on(select_thread_id(editor, thread.id, true));
461 block_on(select_thread_id(editor, thread.id, true));
462 })
462 })
463}
463}
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 {
499 "t" => dap_terminate,
499 "t" => dap_terminate,
500 "s" => { "Switch"
500 "s" => { "Switch"
501 "t" => dap_switch_thread,
501 "t" => dap_switch_thread,
502− // f = stack frame
502+ "f" => dap_switch_stack_frame,
503 // sl, sb
503 // sl, sb
504 },
504 },
505 },
505 },