on master help sign in
Support thread previews
b6c58eaDmitry Sharshakov
helix-term/src/commands/dap.rs+32−3
@@ -3,8 +3,9 @@ use crate::{
3 commands,
3 commands,
4 compositor::Compositor,
4 compositor::Compositor,
5 job::Callback,
5 job::Callback,
6− ui::{FilePicker, Picker, Prompt, PromptEvent},
6+ ui::{FilePicker, Prompt, PromptEvent},
7};
7};
8+use dap::StackFrame;
8use helix_core::Selection;
9use helix_core::Selection;
9use helix_dap::{self as dap, Client};
10use helix_dap::{self as dap, Client};
10use helix_lsp::block_on;
11use helix_lsp::block_on;
@@ -111,8 +112,17 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
111 }
112 }
112
113
113 let thread_states = debugger.thread_states.clone();
114 let thread_states = debugger.thread_states.clone();
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+
114− let picker = Picker::new(
125+ let picker = FilePicker::new(
115− true,
116 threads,
126 threads,
117 move |thread| {
127 move |thread| {
118 format!(
128 format!(
@@ -125,6 +135,25 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
125 .into()
135 .into()
126 },
136 },
127 move |editor, thread, _action| callback_fn(editor, thread),
137 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+ },
128 );
157 );
129 cx.push_layer(Box::new(picker))
158 cx.push_layer(Box::new(picker))
130}
159}