on master help sign in
Fetch stack traces for all threads when debugger sets all_thread_stopped flag
commitc9cd06e90400969285eb8ecbb4cfb7abeeef59ca authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 5 Sep 2021, 16:09 (5 years ago) parentbdd636d
2 files changed+23−11
helix-term/src/application.rs+14−3 helix-term/src/commands/dap.rs+9−8
helix-term/src/application.rs+14−3
@@ -3,7 +3,9 @@ use helix_dap::Payload;
33use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
44use helix_view::{theme, Editor};
55
6−use crate::{args::Args, compositor::Compositor, config::Config, job::Jobs, ui};
6+use crate::{
7+ args::Args, commands::fetch_stack_trace, compositor::Compositor, config::Config, job::Jobs, ui,
8+};
79
810use log::error;
911use std::{
@@ -273,7 +275,16 @@ impl Application {
273275 all_threads_stopped,
274276 ..
275277 }) => {
276− if let Some(thread_id) = thread_id {
278+ let all_threads_stopped = all_threads_stopped.unwrap_or_default();
279+
280+ if all_threads_stopped {
281+ if let Ok(threads) = debugger.threads().await {
282+ for thread in threads {
283+ fetch_stack_trace(debugger, thread.id).await;
284+ }
285+ select_thread_id(&mut self.editor, thread_id.unwrap_or(0), false).await;
286+ }
287+ } else if let Some(thread_id) = thread_id {
277288 debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
278289
279290 // whichever thread stops is made "current" (if no previously selected thread).
@@ -292,7 +303,7 @@ impl Application {
292303 if let Some(text) = text {
293304 status.push_str(&format!(" {}", text));
294305 }
295− if all_threads_stopped.unwrap_or_default() {
306+ if all_threads_stopped {
296307 status.push_str(" (all threads stopped)");
297308 }
298309
helix-term/src/commands/dap.rs+9−8
@@ -45,20 +45,21 @@ pub async fn select_thread_id(editor: &mut Editor, thread_id: isize, force: bool
4545 }
4646
4747 debugger.thread_id = Some(thread_id);
48+ fetch_stack_trace(debugger, thread_id).await;
4849
49− // fetch stack trace
50− // TODO: handle requesting more total frames
50+ let frame = debugger.stack_frames[&thread_id].get(0).cloned();
51+ if let Some(frame) = &frame {
52+ jump_to_stack_frame(editor, frame);
53+ }
54+}
55+
56+pub async fn fetch_stack_trace(debugger: &mut Client, thread_id: isize) {
5157 let (frames, _) = match debugger.stack_trace(thread_id).await {
5258 Ok(frames) => frames,
5359 Err(_) => return,
5460 };
5561 debugger.stack_frames.insert(thread_id, frames);
56− debugger.active_frame = Some(0); // TODO: check how to determine this
57−
58− let frame = debugger.stack_frames[&thread_id].get(0).cloned();
59− if let Some(frame) = &frame {
60− jump_to_stack_frame(editor, frame);
61− }
62+ debugger.active_frame = Some(0);
6263}
6364
6465pub fn jump_to_stack_frame(editor: &mut Editor, frame: &helix_dap::StackFrame) {