Skip to content

Commit

Permalink
WIP Fix thread status not syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Jan 14, 2025
1 parent c11e30e commit 36f2de8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 77 deletions.
65 changes: 62 additions & 3 deletions crates/collab/src/tests/debug_panel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,72 @@ async fn test_debug_panel_remote_button_presses(
cx_a.run_until_parked();
cx_b.run_until_parked();

local_debug_item.update(cx_a, |debug_panel_item, cx| {
assert_eq!(
debugger_ui::debugger_panel::ThreadStatus::Running,
debug_panel_item.thread_state().read(cx).status,
);
});

remote_debug_item.update(cx_b, |debug_panel_item, cx| {
assert_eq!(
debugger_ui::debugger_panel::ThreadStatus::Running,
debug_panel_item.thread_state().read(cx).status,
);
});

client
.fake_event(dap::messages::Events::Continued(dap::ContinuedEvent {
thread_id: 1,
all_threads_continued: None,
.fake_event(dap::messages::Events::Stopped(dap::StoppedEvent {
reason: dap::StoppedEventReason::Pause,
description: None,
thread_id: Some(1),
preserve_focus_hint: None,
text: None,
all_threads_stopped: None,
hit_breakpoint_ids: None,
}))
.await;

client
.on_request::<StackTrace, _>(move |_, _| {
Ok(dap::StackTraceResponse {
stack_frames: Vec::default(),
total_frames: None,
})
})
.await;

cx_a.run_until_parked();
cx_b.run_until_parked();

local_debug_item.update(cx_a, |debug_panel_item, cx| {
assert_eq!(
debugger_ui::debugger_panel::ThreadStatus::Stopped,
debug_panel_item.thread_state().read(cx).status,
);
});

remote_debug_item.update(cx_b, |debug_panel_item, cx| {
assert_eq!(
debugger_ui::debugger_panel::ThreadStatus::Stopped,
debug_panel_item.thread_state().read(cx).status,
);
});

client
.on_request::<dap::requests::Continue, _>(move |_, _| {
Ok(dap::ContinueResponse {
all_threads_continued: Some(true),
})
})
.await;

local_debug_item.update(cx_a, |this, cx| {
this.continue_thread(cx);
});

cx_a.run_until_parked();
cx_b.run_until_parked();

local_debug_item.update(cx_a, |debug_panel_item, cx| {
assert_eq!(
Expand Down
1 change: 0 additions & 1 deletion crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@ impl DebugPanel {
self.handle_debug_adapter_update(debug_adapter_update, cx);
}
project::dap_store::DapStoreEvent::UpdateThreadStatus(thread_status_update) => {
dbg!("In debug panel handle thread status update");
self.handle_thread_status_update(thread_status_update, cx);
}
_ => {}
Expand Down
21 changes: 0 additions & 21 deletions crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,27 +622,6 @@ impl DebugPanelItem {
debug_panel_item.update_thread_state_status(ThreadStatus::Stopped, cx);
})
.log_err();
} else {
this.update(&mut cx, |debug_panel_item, cx| {
debug_panel_item.dap_store.update(cx, |dap_store, _| {
if let Some((client, project_id)) = dap_store
.upstream_client()
.as_ref()
.or(dap_store.downstream_client())
{
dbg!("Sending Update Thread Status");
let update_thread_status = proto::UpdateThreadStatus {
project_id: *project_id,
client_id: debug_panel_item.client_id.to_proto(),
thread_id: debug_panel_item.thread_id,
status: proto::DebuggerThreadStatus::Running.into(),
};

client.send(update_thread_status).log_err();
}
})
})
.log_err();
}
})
.detach();
Expand Down
72 changes: 37 additions & 35 deletions crates/project/src/dap_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ pub trait DapCommand: 'static + Sized + Send + std::fmt::Debug {
&self,
_dap_store: WeakModel<DapStore>,
_client_id: &DebugAdapterClientId,
response: Result<Self::Response>,
_cx: &mut AsyncAppContext,
) {
) -> Result<Self::Response> {
response
}

fn client_id_from_proto(request: &Self::ProtoRequest) -> DebugAdapterClientId;
Expand All @@ -47,7 +49,7 @@ pub trait DapCommand: 'static + Sized + Send + std::fmt::Debug {
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments;

fn response_from_dap(
self,
&self,
message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response>;
}
Expand Down Expand Up @@ -128,7 +130,7 @@ impl DapCommand for NextCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -200,7 +202,7 @@ impl DapCommand for StepInCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -270,7 +272,7 @@ impl DapCommand for StepOutCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -340,7 +342,7 @@ impl DapCommand for StepBackCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -368,30 +370,30 @@ impl DapCommand for ContinueCommand {
&self,
dap_store: WeakModel<DapStore>,
client_id: &DebugAdapterClientId,
response: Result<Self::Response>,
cx: &mut AsyncAppContext,
) {
dbg!("In handle continue command response");
dap_store
.update(cx, |this, cx| {
if let Some((client, project_id)) = this.downstream_client() {
dbg!("Found downstream client");
let thread_message = proto::UpdateThreadStatus {
project_id: *project_id,
client_id: client_id.to_proto(),
thread_id: self.args.thread_id,
status: proto::DebuggerThreadStatus::Running.into(),
};

cx.emit(crate::dap_store::DapStoreEvent::UpdateThreadStatus(
thread_message.clone(),
));

client.send(thread_message).log_err();
} else {
dbg!("Did not find downstream client");
}
})
.log_err();
) -> Result<Self::Response> {
if response.is_ok() {
dap_store
.update(cx, |this, cx| {
if let Some((client, project_id)) = this.downstream_client() {
let thread_message = proto::UpdateThreadStatus {
project_id: *project_id,
client_id: client_id.to_proto(),
thread_id: self.args.thread_id,
status: proto::DebuggerThreadStatus::Running.into(),
};

cx.emit(crate::dap_store::DapStoreEvent::UpdateThreadStatus(
thread_message.clone(),
));

client.send(thread_message).log_err();
}
})
.log_err();
}
response
}

fn client_id_from_proto(request: &Self::ProtoRequest) -> DebugAdapterClientId {
Expand Down Expand Up @@ -425,7 +427,7 @@ impl DapCommand for ContinueCommand {
}

fn response_from_dap(
self,
&self,
message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(message)
Expand Down Expand Up @@ -497,7 +499,7 @@ impl DapCommand for PauseCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -565,7 +567,7 @@ impl DapCommand for DisconnectCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -629,7 +631,7 @@ impl DapCommand for TerminateThreadsCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -689,7 +691,7 @@ impl DapCommand for TerminateCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down Expand Up @@ -753,7 +755,7 @@ impl DapCommand for RestartCommand {
}

fn response_from_dap(
self,
&self,
_message: <Self::DapRequest as dap::requests::Request>::Response,
) -> Result<Self::Response> {
Ok(())
Expand Down
28 changes: 11 additions & 17 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,10 +1092,15 @@ impl DapStore {
return Task::ready(Err(anyhow!("Could not find client: {:?}", client_id)));
};

cx.background_executor().spawn(async move {
let client_id = client_id.clone();

let task = cx.spawn(|this, mut cx| async move {
let args = request.to_dap();
request.response_from_dap(client.request::<R::DapRequest>(args).await?)
})
let response = request.response_from_dap(client.request::<R::DapRequest>(args).await?);
request.handle_response(this, &client_id, response, &mut cx)
});

cx.background_executor().spawn(async move { task.await })
}

fn send_proto_client_request<R: DapCommand>(
Expand All @@ -1106,11 +1111,9 @@ impl DapStore {
request: R,
cx: &mut ModelContext<Self>,
) -> Task<Result<R::Response>> {
let client_id = client_id.clone();
cx.spawn(|this, mut cx| async move {
let message = request.to_proto(&client_id, upstream_project_id);
let message = request.to_proto(&client_id, upstream_project_id);
cx.background_executor().spawn(async move {
let response = upstream_client.request(message).await?;
request.handle_response(this, &client_id, &mut cx);
request.response_from_proto(response)
})
}
Expand Down Expand Up @@ -1681,17 +1684,8 @@ impl DapStore {
envelope: TypedEnvelope<proto::UpdateThreadStatus>,
mut cx: AsyncAppContext,
) -> Result<()> {
this.update(&mut cx, |this, cx| {
let is_remote = this.as_remote().is_some();

this.update(&mut cx, |_, cx| {
cx.emit(DapStoreEvent::UpdateThreadStatus(envelope.payload));

dbg!("In handle update thread status");
if is_remote {
dbg!("As remote");
} else {
dbg!("As local");
}
})
}

Expand Down

0 comments on commit 36f2de8

Please sign in to comment.