on master help sign in
Fetch stack traces for all threads when debugger sets all_thread_stopped flag
c9cd06eDmitry Sharshakov
helix-term/src/application.rs+14−3
@@ -3,7 +3,9 @@ use helix_dap::Payload;
3use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
3use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
4use helix_view::{theme, Editor};
4use helix_view::{theme, Editor};
5
5
6+use crate::{
6−use crate::{args::Args, compositor::Compositor, config::Config, job::Jobs, ui};
7+ args::Args, commands::fetch_stack_trace, compositor::Compositor, config::Config, job::Jobs, ui,
8+};
7
9
8use log::error;
10use log::error;
9use std::{
11use std::{
@@ -273,7 +275,16 @@ impl Application {
273 all_threads_stopped,
275 all_threads_stopped,
274 ..
276 ..
275 }) => {
277 }) => {
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+ }
276− if let Some(thread_id) = thread_id {
287+ } else if let Some(thread_id) = thread_id {
277 debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
288 debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
278
289
279 // whichever thread stops is made "current" (if no previously selected thread).
290 // whichever thread stops is made "current" (if no previously selected thread).
@@ -292,7 +303,7 @@ impl Application {
292 if let Some(text) = text {
303 if let Some(text) = text {
293 status.push_str(&format!(" {}", text));
304 status.push_str(&format!(" {}", text));
294 }
305 }
295− if all_threads_stopped.unwrap_or_default() {
306+ if all_threads_stopped {
296 status.push_str(" (all threads stopped)");
307 status.push_str(" (all threads stopped)");
297 }
308 }
298
309
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
45 }
45 }
46
46
47 debugger.thread_id = Some(thread_id);
47 debugger.thread_id = Some(thread_id);
48+ fetch_stack_trace(debugger, thread_id).await;
48
49
49− // fetch stack trace
50+ let frame = debugger.stack_frames[&thread_id].get(0).cloned();
50− // TODO: handle requesting more total frames
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) {
51 let (frames, _) = match debugger.stack_trace(thread_id).await {
57 let (frames, _) = match debugger.stack_trace(thread_id).await {
52 Ok(frames) => frames,
58 Ok(frames) => frames,
53 Err(_) => return,
59 Err(_) => return,
54 };
60 };
55 debugger.stack_frames.insert(thread_id, frames);
61 debugger.stack_frames.insert(thread_id, frames);
56− debugger.active_frame = Some(0); // TODO: check how to determine this
62+ debugger.active_frame = Some(0);
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}
63}
63
64
64pub fn jump_to_stack_frame(editor: &mut Editor, frame: &helix_dap::StackFrame) {
65pub fn jump_to_stack_frame(editor: &mut Editor, frame: &helix_dap::StackFrame) {