Support thread previews

pull/574/head
Dmitry Sharshakov 3 years ago
parent bb26c589b4
commit b6c58ea23e
No known key found for this signature in database
GPG Key ID: 471FD32E15FD8473

@ -3,8 +3,9 @@ use crate::{
commands, commands,
compositor::Compositor, compositor::Compositor,
job::Callback, job::Callback,
ui::{FilePicker, Picker, Prompt, PromptEvent}, ui::{FilePicker, Prompt, PromptEvent},
}; };
use dap::StackFrame;
use helix_core::Selection; use helix_core::Selection;
use helix_dap::{self as dap, Client}; use helix_dap::{self as dap, Client};
use helix_lsp::block_on; 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 thread_states = debugger.thread_states.clone();
let picker = Picker::new( let mut top_frames: HashMap<isize, StackFrame> = HashMap::new();
true, 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, threads,
move |thread| { move |thread| {
format!( format!(
@ -125,6 +135,25 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
.into() .into()
}, },
move |editor, thread, _action| callback_fn(editor, thread), 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)) cx.push_layer(Box::new(picker))
} }

Loading…
Cancel
Save