on master help sign in
dap: Extract a thread_states map
commit27c1b3f98b58edf690fda7caa2b14f34d6661598 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 3 Sep 2021, 11:30 (5 years ago) parent5b920c5
3 files changed+22−15
helix-dap/src/client.rs+1 helix-term/src/application.rs+14−9 helix-term/src/commands/dap.rs+7−6
helix-dap/src/client.rs+1
@@ -31,6 +31,7 @@ pub struct Client {
3131 pub breakpoints: HashMap<PathBuf, Vec<SourceBreakpoint>>,
3232 // thread_id -> frames
3333 pub stack_frames: HashMap<usize, Vec<StackFrame>>,
34+ pub thread_states: HashMap<usize, String>,
3435 pub thread_id: Option<usize>,
3536 /// Currently active frame for the current thread.
3637 pub active_frame: Option<usize>,
helix-term/src/application.rs+14−9
@@ -273,10 +273,12 @@ impl Application {
273273 all_threads_stopped,
274274 ..
275275 }) => {
276− debugger.is_running = false;
276+ if let Some(thread_id) = thread_id {
277+ debugger.thread_states.insert(thread_id, reason); // TODO: dap uses "type" || "reason" here
278+ // whichever thread stops is made "current" (if no previously selected thread).
279+ select_thread_id(&mut self.editor, thread_id, false).await;
280+ }
277281
278− // whichever thread stops is made "current" (if no previously selected thread).
279− select_thread_id(&mut self.editor, thread_id.unwrap(), false).await;
280282
281283 let scope = match thread_id {
282284 Some(id) => format!("Thread {}", id),
@@ -296,6 +298,15 @@ impl Application {
296298
297299 self.editor.set_status(status);
298300 }
301+ Event::Continued(events::Continued { thread_id, .. }) => {
302+ debugger.thread_states.remove(&thread_id);
303+ if debugger.thread_id == Some(thread_id) {
304+ resume_application(debugger)
305+ }
306+ }
307+ Event::Thread(_) => {
308+ // TODO: update thread_states, make threads request
309+ }
299310 Event::Output(events::Output {
300311 category, output, ..
301312 }) => {
@@ -315,12 +326,6 @@ impl Application {
315326 self.editor
316327 .set_status("Debugged application started".to_owned());
317328 }
318− Event::Continued(events::Continued { thread_id, .. }) => {
319− // TODO: remove thread from thread-states
320− if debugger.thread_id == Some(thread_id) {
321− resume_application(debugger)
322− }
323− }
324329 ev => {
325330 log::warn!("Unhandled event {:?}", ev);
326331 return; // return early to skip render
helix-term/src/commands/dap.rs+7−6
@@ -19,7 +19,10 @@ pub fn dap_pos_to_pos(doc: &helix_core::Rope, line: usize, column: usize) -> Opt
1919}
2020
2121pub fn resume_application(debugger: &mut Client) {
22− debugger.is_running = true; // TODO: set state running for debugger.thread_id
22+ if let Some(thread_id) = debugger.thread_id {
23+ debugger.thread_states.insert(thread_id, "running".to_string());
24+ debugger.stack_frames.remove(&thread_id);
25+ }
2326 debugger.active_frame = None;
2427 debugger.thread_id = None;
2528}
@@ -302,7 +305,6 @@ pub fn dap_continue(cx: &mut Context) {
302305 return;
303306 }
304307 resume_application(debugger);
305− debugger.stack_frames.remove(&thread_id);
306308 } else {
307309 cx.editor
308310 .set_error("Currently active thread is not stopped. Switch the thread.".into());
@@ -315,6 +317,8 @@ pub fn dap_pause(cx: &mut Context) {
315317 None => return,
316318 };
317319
320+ // TODO: this should instead open a picker to pause a selected thread
321+
318322 if !debugger.is_running {
319323 cx.editor.set_status("Debuggee is not running".to_owned());
320324 return;
@@ -340,7 +344,6 @@ pub fn dap_step_in(cx: &mut Context) {
340344 return;
341345 }
342346 resume_application(debugger);
343− debugger.stack_frames.remove(&thread_id);
344347 } else {
345348 cx.editor
346349 .set_error("Currently active thread is not stopped. Switch the thread.".into());
@@ -360,7 +363,6 @@ pub fn dap_step_out(cx: &mut Context) {
360363 return;
361364 }
362365 resume_application(debugger);
363− debugger.stack_frames.remove(&thread_id);
364366 } else {
365367 cx.editor
366368 .set_error("Currently active thread is not stopped. Switch the thread.".into());
@@ -380,7 +382,6 @@ pub fn dap_next(cx: &mut Context) {
380382 return;
381383 }
382384 resume_application(debugger);
383− debugger.stack_frames.remove(&thread_id);
384385 } else {
385386 cx.editor
386387 .set_error("Currently active thread is not stopped. Switch the thread.".into());
@@ -393,7 +394,7 @@ pub fn dap_variables(cx: &mut Context) {
393394 None => return,
394395 };
395396
396− if debugger.is_running {
397+ if debugger.thread_id.is_none() {
397398 cx.editor
398399 .set_status("Cannot access variables while target is running".to_owned());
399400 return;