@@ -321,147 +321,154 @@ impl Application {
321 pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
321 pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
322 use crate::commands::dap::{breakpoints_changed, resume_application, select_thread_id};
322 use crate::commands::dap::{breakpoints_changed, resume_application, select_thread_id};
323 use helix_dap::{events, Event};
323 use helix_dap::{events, Event};
324− let debugger = match self.editor.debugger.as_mut() {
325− Some(debugger) => debugger,
329 match payload {
325 match payload {
330− Payload::Event(ev) => match ev {
326+ Payload::Event(ev) => {
327+ let debugger = match self.editor.debugger.as_mut() {
328+ Some(debugger) => debugger,
331− Event::Stopped(events::Stopped {
332+ Event::Stopped(events::Stopped {
332− thread_id,
333+ thread_id,
333− description,
334+ description,
336− all_threads_stopped,
337+ all_threads_stopped,
339− let all_threads_stopped = all_threads_stopped.unwrap_or_default();
340+ let all_threads_stopped = all_threads_stopped.unwrap_or_default();
341− if all_threads_stopped {
342+ if all_threads_stopped {
342− if let Ok(threads) = debugger.threads().await {
343+ if let Ok(threads) = debugger.threads().await {
343− for thread in threads {
344+ for thread in threads {
344− fetch_stack_trace(debugger, thread.id).await;
345+ fetch_stack_trace(debugger, thread.id).await;
349+ thread_id.unwrap_or_default(),
348− thread_id.unwrap_or_default(),
353− } else if let Some(thread_id) = thread_id {
354+ } else if let Some(thread_id) = thread_id {
354− debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
355+ debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
356− // whichever thread stops is made "current" (if no previously selected thread).
357+ // whichever thread stops is made "current" (if no previously selected thread).
357− select_thread_id(&mut self.editor, thread_id, false).await;
358+ select_thread_id(&mut self.editor, thread_id, false).await;
360− let scope = match thread_id {
361+ let scope = match thread_id {
361− Some(id) => format!("Thread {}", id),
362+ Some(id) => format!("Thread {}", id),
362− None => "Target".to_owned(),
363+ None => "Target".to_owned(),
365− let mut status = format!("{} stopped because of {}", scope, reason);
366+ let mut status = format!("{} stopped because of {}", scope, reason);
366− if let Some(desc) = description {
367+ if let Some(desc) = description {
367− status.push_str(&format!(" {}", desc));
368+ status.push_str(&format!(" {}", desc));
369− if let Some(text) = text {
370+ if let Some(text) = text {
370− status.push_str(&format!(" {}", text));
371+ status.push_str(&format!(" {}", text));
372− if all_threads_stopped {
373+ if all_threads_stopped {
373− status.push_str(" (all threads stopped)");
374+ status.push_str(" (all threads stopped)");
376− self.editor.set_status(status);
377+ self.editor.set_status(status);
378− Event::Continued(events::Continued { thread_id, .. }) => {
381− .insert(thread_id, "running".to_owned());
382− if debugger.thread_id == Some(thread_id) {
383− resume_application(debugger)
385− }
379+ Event::Continued(events::Continued { thread_id, .. }) => {
386− Event::Thread(_) => {
380+ debugger
387− // TODO: update thread_states, make threads request
381+ .thread_states
388− }
382+ .insert(thread_id, "running".to_owned());
389− Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => match &reason[..] {
383+ if debugger.thread_id == Some(thread_id) {
390− "new" => {
384+ resume_application(debugger)
391− if let Some(source) = breakpoint.source {
394− .entry(source.path.unwrap()) // TODO: no unwraps
398− verified: breakpoint.verified,
399− message: breakpoint.message,
400− line: breakpoint.line.unwrap().saturating_sub(1), // TODO: no unwrap
401− column: breakpoint.column,
402− ..Default::default()
406− "changed" => {
387+ Event::Thread(_) => {
407− for breakpoints in self.editor.breakpoints.values_mut() {
388+ // TODO: update thread_states, make threads request
408− if let Some(i) = breakpoints.iter().position(|b| b.id == breakpoint.id)
410− breakpoints[i].verified = breakpoint.verified;
411− breakpoints[i].message = breakpoint.message.clone();
412− breakpoints[i].line = breakpoint.line.unwrap().saturating_sub(1); // TODO: no unwrap
413− breakpoints[i].column = breakpoint.column;
390+ Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => {
393+ if let Some(source) = breakpoint.source {
396+ .entry(source.path.unwrap()) // TODO: no unwraps
400+ verified: breakpoint.verified,
401+ message: breakpoint.message,
402+ line: breakpoint.line.unwrap().saturating_sub(1), // TODO: no unwrap
403+ column: breakpoint.column,
404+ ..Default::default()
409+ for breakpoints in self.editor.breakpoints.values_mut() {
411+ breakpoints.iter().position(|b| b.id == breakpoint.id)
413+ breakpoints[i].verified = breakpoint.verified;
414+ breakpoints[i].message = breakpoint.message.clone();
415+ breakpoints[i].line =
416+ breakpoint.line.unwrap().saturating_sub(1); // TODO: no unwrap
417+ breakpoints[i].column = breakpoint.column;
417− "removed" => {
421+ "removed" => {
418− for breakpoints in self.editor.breakpoints.values_mut() {
422+ for breakpoints in self.editor.breakpoints.values_mut() {
419− if let Some(i) = breakpoints.iter().position(|b| b.id == breakpoint.id)
424+ breakpoints.iter().position(|b| b.id == breakpoint.id)
421− breakpoints.remove(i);
426+ breakpoints.remove(i);
431+ warn!("Unknown breakpoint event: {}", reason);
426− warn!("Unknown breakpoint event: {}", reason);
429− Event::Output(events::Output {
435+ Event::Output(events::Output {
430− category, output, ..
436+ category, output, ..
432− let prefix = match category {
438+ let prefix = match category {
433− Some(category) => {
439+ Some(category) => {
434− if &category == "telemetry" {
440+ if &category == "telemetry" {
443+ format!("Debug ({}):", category)
437− format!("Debug ({}):", category)
439− None => "Debug:".to_owned(),
445+ None => "Debug:".to_owned(),
442− log::info!("{}", output);
448+ log::info!("{}", output);
443− self.editor.set_status(format!("{} {}", prefix, output));
449+ self.editor.set_status(format!("{} {}", prefix, output));
445− Event::Initialized => {
446− // send existing breakpoints
447− for (path, breakpoints) in &mut self.editor.breakpoints {
448− // TODO: call futures in parallel, await all
449− let _ = breakpoints_changed(debugger, path.clone(), breakpoints);
451+ Event::Initialized => {
452+ // send existing breakpoints
453+ for (path, breakpoints) in &mut self.editor.breakpoints {
454+ // TODO: call futures in parallel, await all
455+ let _ = breakpoints_changed(debugger, path.clone(), breakpoints);
451− // TODO: fetch breakpoints (in case we're attaching)
457+ // TODO: fetch breakpoints (in case we're attaching)
453− if debugger.configuration_done().await.is_ok() {
459+ if debugger.configuration_done().await.is_ok() {
454− self.editor
460+ self.editor
455− .set_status("Debugged application started".to_owned());
461+ .set_status("Debugged application started".to_owned());
456− }; // TODO: do we need to handle error?
462+ }; // TODO: do we need to handle error?
459− log::warn!("Unhandled event {:?}", ev);
465+ log::warn!("Unhandled event {:?}", ev);
460− return; // return early to skip render
466+ return; // return early to skip render
463 Payload::Response(_) => unreachable!(),
470 Payload::Response(_) => unreachable!(),
464− Payload::Request(_) => todo!(),
471+ Payload::Request(request) => unimplemented!("{:?}", request),
466 self.render();
473 self.render();