aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands/dap.rs
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-09-05 10:39:27 +0000
committerDmitry Sharshakov2021-09-05 10:39:27 +0000
commitb6c58ea23e5970aef0247c5f3f05970de52a758f (patch)
treef1046d2d6fc70617b0dd7b8acf0e0a0141ba6ad4 /helix-term/src/commands/dap.rs
parentbb26c589b4bf6aa30b0d14c3c5ee0d3dc6af0ca8 (diff)
Support thread previews
Diffstat (limited to 'helix-term/src/commands/dap.rs')
-rw-r--r--helix-term/src/commands/dap.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 235ee78e..ab65dd49 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -3,8 +3,9 @@ use crate::{
commands,
compositor::Compositor,
job::Callback,
- ui::{FilePicker, Picker, Prompt, PromptEvent},
+ ui::{FilePicker, Prompt, PromptEvent},
};
+use dap::StackFrame;
use helix_core::Selection;
use helix_dap::{self as dap, Client};
use helix_lsp::block_on;
@@ -111,8 +112,17 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
}
let thread_states = debugger.thread_states.clone();
- let picker = Picker::new(
- true,
+ let mut top_frames: HashMap<isize, StackFrame> = HashMap::new();
+ for thread in threads.clone() {
+ if let Some(frame) = block_on(debugger.stack_trace(thread.id))
+ .ok()
+ .and_then(|(bt, _)| bt.get(0).cloned())
+ {
+ top_frames.insert(thread.id, frame);
+ }
+ }
+
+ let picker = FilePicker::new(
threads,
move |thread| {
format!(
@@ -125,6 +135,25 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
.into()
},
move |editor, thread, _action| callback_fn(editor, thread),
+ move |_editor, thread| {
+ if let Some(frame) = top_frames.get(&thread.id) {
+ 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),
+ )),
+ )
+ })
+ } else {
+ None
+ }
+ },
);
cx.push_layer(Box::new(picker))
}