on master help sign in
Support thread previews
commitb6c58ea23e5970aef0247c5f3f05970de52a758f authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 5 Sep 2021, 13:39 (5 years ago) parentbb26c58
1 file changed+32−3
helix-term/src/commands/dap.rs+32−3
helix-term/src/commands/dap.rs+32−3
@@ -3,8 +3,9 @@ use crate::{
33 commands,
44 compositor::Compositor,
55 job::Callback,
6− ui::{FilePicker, Picker, Prompt, PromptEvent},
6+ ui::{FilePicker, Prompt, PromptEvent},
77};
8+use dap::StackFrame;
89use helix_core::Selection;
910use helix_dap::{self as dap, Client};
1011use helix_lsp::block_on;
@@ -111,8 +112,17 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
111112 }
112113
113114 let thread_states = debugger.thread_states.clone();
114− let picker = Picker::new(
115− true,
115+ let mut top_frames: HashMap<isize, StackFrame> = HashMap::new();
116+ for thread in threads.clone() {
117+ if let Some(frame) = block_on(debugger.stack_trace(thread.id))
118+ .ok()
119+ .and_then(|(bt, _)| bt.get(0).cloned())
120+ {
121+ top_frames.insert(thread.id, frame);
122+ }
123+ }
124+
125+ let picker = FilePicker::new(
116126 threads,
117127 move |thread| {
118128 format!(
@@ -125,6 +135,25 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
125135 .into()
126136 },
127137 move |editor, thread, _action| callback_fn(editor, thread),
138+ move |_editor, thread| {
139+ if let Some(frame) = top_frames.get(&thread.id) {
140+ frame
141+ .source
142+ .as_ref()
143+ .and_then(|source| source.path.clone())
144+ .map(|path| {
145+ (
146+ path,
147+ Some((
148+ frame.line.saturating_sub(1),
149+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
150+ )),
151+ )
152+ })
153+ } else {
154+ None
155+ }
156+ },
128157 );
129158 cx.push_layer(Box::new(picker))
130159}