summaryrefslogtreecommitdiff
path: root/helix-term/src/commands/dap.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-09-03 08:25:11 +0000
committerBlaž Hrastnik2021-09-03 08:25:11 +0000
commitc63ad60c31cb51481b227c1d610d3eb7b2f95529 (patch)
treeb5652e82a60d985f9086cf4d8581281e09db4ff3 /helix-term/src/commands/dap.rs
parent7b61c63ece4384f75fa41f6c052b3d9e506ff3aa (diff)
dap: Allow switching between stack frames
Diffstat (limited to 'helix-term/src/commands/dap.rs')
-rw-r--r--helix-term/src/commands/dap.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 5c415ca4..6b9b06b2 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -1,5 +1,5 @@
use super::{align_view, Align, Context, Editor};
-use crate::ui::Picker;
+use crate::ui::{FilePicker, Picker};
use helix_core::Selection;
use helix_dap::{self as dap, Client};
use helix_lsp::block_on;
@@ -461,3 +461,52 @@ pub fn dap_switch_thread(cx: &mut Context) {
block_on(select_thread_id(editor, thread.id, true));
})
}
+pub fn dap_switch_stack_frame(cx: &mut Context) {
+ let debugger = match &mut cx.editor.debugger {
+ Some(debugger) => debugger,
+ None => return,
+ };
+
+ let thread_id = match debugger.thread_id {
+ Some(thread_id) => thread_id,
+ None => {
+ cx.editor
+ .set_error(format!("No thread is currently active"));
+ return;
+ }
+ };
+
+ let frames = debugger.stack_frames[&thread_id].clone();
+
+ let picker = FilePicker::new(
+ frames,
+ |frame| frame.name.clone().into(), // TODO: include thread_states in the label
+ move |editor, frame, _action| {
+ let debugger = match &mut editor.debugger {
+ Some(debugger) => debugger,
+ None => return,
+ };
+ // TODO: this should be simpler to find
+ let pos = debugger.stack_frames[&thread_id]
+ .iter()
+ .position(|f| f.id == frame.id);
+ debugger.active_frame = pos;
+ },
+ move |_editor, frame| {
+ frame
+ .source
+ .as_ref()
+ .and_then(|source| source.path.clone())
+ .map(|path| {
+ (
+ path,
+ Some((
+ frame.line.saturating_sub(1),
+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
+ )),
+ )
+ })
+ },
+ );
+ cx.push_layer(Box::new(picker))
+}