@@ -19,7 +19,7 @@ use std::collections::HashMap;
1919use std::future::Future;
2020use std::path::PathBuf;
2121
22−use anyhow::bail;
22+use anyhow::{anyhow, bail};
2323
2424// general utils:
2525pub fn dap_pos_to_pos(doc: &helix_core::Rope, line: usize, column: usize) -> Option<usize> {
@@ -99,53 +99,61 @@ pub fn jump_to_stack_frame(editor: &mut Editor, frame: &helix_dap::StackFrame) {
9999 align_view(doc, view, Align::Center);
100100}
101101
102−fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Thread) + 'static) {
102+fn thread_picker(
103+ cx: &mut Context,
104+ callback_fn: impl Fn(&mut Editor, &dap::Thread) + Send + 'static,
105+) {
103106 let debugger = match &mut cx.editor.debugger {
104107 Some(debugger) => debugger,
105108 None => return,
106109 };
107110
108− let threads = match block_on(debugger.threads()) {
109− Ok(threads) => threads,
110− Err(e) => {
111− cx.editor
112− .set_error(format!("Failed to retrieve threads: {}", e));
113− return;
114− }
115− };
116−
117− if threads.len() == 1 {
118− callback_fn(cx.editor, &threads[0]);
119− return;
120− }
111+ let future = debugger.threads();
112+ dap_callback(
113+ cx.jobs,
114+ future,
115+ move |editor: &mut Editor,
116+ compositor: &mut Compositor,
117+ response: dap::requests::ThreadsResponse| {
118+ let threads = response.threads;
119+ if threads.len() == 1 {
120+ callback_fn(editor, &threads[0]);
121+ return;
122+ }
123+ let debugger = match &mut editor.debugger {
124+ Some(debugger) => debugger,
125+ None => return,
126+ };
121127
122− let thread_states = debugger.thread_states.clone();
123− let picker = FilePicker::new(
124− threads,
125− move |thread| {
126− format!(
127− "{} ({})",
128− thread.name,
129− thread_states
130− .get(&thread.id)
131− .map(|state| state.as_str())
132− .unwrap_or("unknown")
133− )
134− .into()
135− },
136− move |cx, thread, _action| callback_fn(cx.editor, thread),
137− move |editor, thread| {
138− let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
139− let frame = frames.get(0)?;
140− let path = frame.source.as_ref()?.path.clone()?;
141− let pos = Some((
142− frame.line.saturating_sub(1),
143− frame.end_line.unwrap_or(frame.line).saturating_sub(1),
144− ));
145− Some((path, pos))
128+ let thread_states = debugger.thread_states.clone();
129+ let picker = FilePicker::new(
130+ threads,
131+ move |thread| {
132+ format!(
133+ "{} ({})",
134+ thread.name,
135+ thread_states
136+ .get(&thread.id)
137+ .map(|state| state.as_str())
138+ .unwrap_or("unknown")
139+ )
140+ .into()
141+ },
142+ move |cx, thread, _action| callback_fn(cx.editor, thread),
143+ move |editor, thread| {
144+ let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
145+ let frame = frames.get(0)?;
146+ let path = frame.source.as_ref()?.path.clone()?;
147+ let pos = Some((
148+ frame.line.saturating_sub(1),
149+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
150+ ));
151+ Some((path, pos))
152+ },
153+ );
154+ compositor.push(Box::new(picker));
146155 },
147156 );
148− cx.push_layer(Box::new(picker))
149157}
150158
151159fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> {