From b6c58ea23e5970aef0247c5f3f05970de52a758f Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sun, 5 Sep 2021 13:39:27 +0300 Subject: [PATCH] Support thread previews --- helix-term/src/commands/dap.rs | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 235ee78ee..ab65dd49e 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 = 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)) }