on master help sign in
Make thread_picker non-blocking
dc8df7bBlaž Hrastnik
helix-dap/src/client.rs+4−5
@@ -209,7 +209,7 @@ impl Client {
209 }
209 }
210
210
211 /// Execute a RPC request on the debugger.
211 /// Execute a RPC request on the debugger.
212− fn call<R: crate::types::Request>(
212+ pub fn call<R: crate::types::Request>(
213 &self,
213 &self,
214 arguments: R::Arguments,
214 arguments: R::Arguments,
215 ) -> impl Future<Output = Result<Value>>
215 ) -> impl Future<Output = Result<Value>>
@@ -248,7 +248,7 @@ impl Client {
248 }
248 }
249 }
249 }
250
250
251− async fn request<R: crate::types::Request>(&self, params: R::Arguments) -> Result<R::Result>
251+ pub async fn request<R: crate::types::Request>(&self, params: R::Arguments) -> Result<R::Result>
252 where
252 where
253 R::Arguments: serde::Serialize,
253 R::Arguments: serde::Serialize,
254 R::Result: core::fmt::Debug, // TODO: temporary
254 R::Result: core::fmt::Debug, // TODO: temporary
@@ -384,9 +384,8 @@ impl Client {
384 Ok((response.stack_frames, response.total_frames))
384 Ok((response.stack_frames, response.total_frames))
385 }
385 }
386
386
387− pub async fn threads(&self) -> Result<Vec<Thread>> {
387+ pub fn threads(&self) -> impl Future<Output = Result<Value>> {
388− let response = self.request::<requests::Threads>(()).await?;
388+ self.call::<requests::Threads>(())
389− Ok(response.threads)
390 }
389 }
391
390
392 pub async fn scopes(&self, frame_id: usize) -> Result<Vec<Scope>> {
391 pub async fn scopes(&self, frame_id: usize) -> Result<Vec<Scope>> {
helix-term/src/application.rs+2−2
@@ -340,8 +340,8 @@ impl Application {
340 let all_threads_stopped = all_threads_stopped.unwrap_or_default();
340 let all_threads_stopped = all_threads_stopped.unwrap_or_default();
341
341
342 if all_threads_stopped {
342 if all_threads_stopped {
343− if let Ok(threads) = debugger.threads().await {
343+ if let Ok(response) = debugger.request::<dap::requests::Threads>(()).await {
344− for thread in threads {
344+ for thread in response.threads {
345 fetch_stack_trace(debugger, thread.id).await;
345 fetch_stack_trace(debugger, thread.id).await;
346 }
346 }
347 select_thread_id(
347 select_thread_id(
helix-term/src/commands/dap.rs+48−40
@@ -19,7 +19,7 @@ use std::collections::HashMap;
19use std::future::Future;
19use std::future::Future;
20use std::path::PathBuf;
20use std::path::PathBuf;
21
21
22−use anyhow::bail;
22+use anyhow::{anyhow, bail};
23
23
24// general utils:
24// general utils:
25pub fn dap_pos_to_pos(doc: &helix_core::Rope, line: usize, column: usize) -> Option<usize> {
25pub 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) {
99 align_view(doc, view, Align::Center);
99 align_view(doc, view, Align::Center);
100}
100}
101
101
102+fn thread_picker(
103+ cx: &mut Context,
102−fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Thread) + 'static) {
104+ callback_fn: impl Fn(&mut Editor, &dap::Thread) + Send + 'static,
105+) {
103 let debugger = match &mut cx.editor.debugger {
106 let debugger = match &mut cx.editor.debugger {
104 Some(debugger) => debugger,
107 Some(debugger) => debugger,
105 None => return,
108 None => return,
106 };
109 };
107
110
108− let threads = match block_on(debugger.threads()) {
111+ let future = debugger.threads();
109− Ok(threads) => threads,
112+ dap_callback(
110− Err(e) => {
113+ cx.jobs,
111− cx.editor
114+ future,
112− .set_error(format!("Failed to retrieve threads: {}", e));
115+ move |editor: &mut Editor,
113− return;
116+ compositor: &mut Compositor,
114− }
117+ response: dap::requests::ThreadsResponse| {
115− };
118+ let threads = response.threads;
116−
117− if threads.len() == 1 {
119+ if threads.len() == 1 {
118− callback_fn(cx.editor, &threads[0]);
120+ callback_fn(editor, &threads[0]);
119− return;
121+ return;
120− }
122+ }
123+ let debugger = match &mut editor.debugger {
124+ Some(debugger) => debugger,
125+ None => return,
126+ };
121
127
122− let thread_states = debugger.thread_states.clone();
128+ let thread_states = debugger.thread_states.clone();
123− let picker = FilePicker::new(
129+ let picker = FilePicker::new(
124− threads,
130+ threads,
125− move |thread| {
131+ move |thread| {
126− format!(
132+ format!(
127− "{} ({})",
133+ "{} ({})",
128− thread.name,
134+ thread.name,
129− thread_states
135+ thread_states
130− .get(&thread.id)
136+ .get(&thread.id)
131− .map(|state| state.as_str())
137+ .map(|state| state.as_str())
132− .unwrap_or("unknown")
138+ .unwrap_or("unknown")
133− )
139+ )
134− .into()
140+ .into()
135− },
141+ },
136− move |cx, thread, _action| callback_fn(cx.editor, thread),
142+ move |cx, thread, _action| callback_fn(cx.editor, thread),
137− move |editor, thread| {
143+ move |editor, thread| {
138− let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
144+ let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
139− let frame = frames.get(0)?;
145+ let frame = frames.get(0)?;
140− let path = frame.source.as_ref()?.path.clone()?;
146+ let path = frame.source.as_ref()?.path.clone()?;
141− let pos = Some((
147+ let pos = Some((
142− frame.line.saturating_sub(1),
148+ frame.line.saturating_sub(1),
143− frame.end_line.unwrap_or(frame.line).saturating_sub(1),
149+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
144− ));
150+ ));
145− Some((path, pos))
151+ Some((path, pos))
152+ },
153+ );
154+ compositor.push(Box::new(picker));
146 },
155 },
147 );
156 );
148− cx.push_layer(Box::new(picker))
149}
157}
150
158
151fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> {
159fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpoint)> {