Skip to content

Commit

Permalink
Handle ShutdownDebugClient RPC for collab db
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Jan 8, 2025
1 parent c26bbeb commit 430d252
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ CREATE INDEX "index_breakpoints_on_project_id" ON "breakpoints" ("project_id");

CREATE TABLE IF NOT EXISTS "debug_clients" (
id BIGINT NOT NULL,
project_id BIGINT NOT NULL,
project_id INTEGER NOT NULL,
session_id BIGINT NOT NULL,
capabilities INTEGER NOT NULL,
PRIMARY KEY (id, project_id, session_id),
Expand All @@ -461,7 +461,7 @@ CREATE INDEX "index_debug_client_on_project_id" ON "debug_clients" ("project_id"

CREATE TABLE IF NOT EXISTS "debug_panel_items" (
id BIGINT NOT NULL,
project_id BIGINT NOT NULL,
project_id INTEGER NOT NULL,
thread_id BIGINT NOT NULL,
session_id BIGINT NOT NULL,
active_thread_item INTEGER NOT NULL,
Expand All @@ -472,7 +472,7 @@ CREATE TABLE IF NOT EXISTS "debug_panel_items" (
variable_list BYTEA NOT NULL,
stack_frame_list BYTEA NOT NULL,
loaded_source_list BYTEA NOT NULL,
PRIMARY KEY (id, project_id, thread_id),
PRIMARY KEY (id, project_id, session_id, thread_id),
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE,
FOREIGN KEY (id, project_id, session_id) REFERENCES debug_clients (id, project_id, session_id) ON DELETE CASCADE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS "debug_panel_items" (
variable_list BYTEA NOT NULL,
stack_frame_list BYTEA NOT NULL,
loaded_source_list BYTEA NOT NULL,
PRIMARY KEY (id, project_id, thread_id),
PRIMARY KEY (id, project_id, session_id, thread_id),
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE,
FOREIGN KEY (id, project_id, session_id) REFERENCES debug_clients (id, project_id, session_id) ON DELETE CASCADE
);
Expand Down
23 changes: 22 additions & 1 deletion crates/collab/src/db/queries/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,28 @@ impl Database {
.await
}

pub async fn update_debug_client_panel_item(
pub async fn shutdown_debug_client(
&self,
connection_id: ConnectionId,
update: &proto::ShutdownDebugClient,
) -> Result<TransactionGuard<HashSet<ConnectionId>>> {
let project_id = ProjectId::from_proto(update.project_id);
self.project_transaction(project_id, |tx| async move {
debug_clients::Entity::delete_by_id((
update.client_id as i64,
ProjectId::from_proto(update.project_id),
update.session_id as i64,
))
.exec(&*tx)
.await?;

self.internal_project_connection_ids(project_id, connection_id, true, &tx)
.await
})
.await
}

pub async fn set_debug_client_panel_item(
&self,
connection_id: ConnectionId,
update: &proto::SetDebuggerPanelItem,
Expand Down
1 change: 1 addition & 0 deletions crates/collab/src/db/tables/debug_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Model {
pub id: i64,
#[sea_orm(primary_key)]
pub project_id: ProjectId,
#[sea_orm(primary_key)]
pub session_id: i64,
#[sea_orm(column_type = "Integer")]
pub capabilities: i32,
Expand Down
3 changes: 2 additions & 1 deletion crates/collab/src/db/tables/debug_panel_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ pub struct Model {
#[sea_orm(primary_key)]
pub project_id: ProjectId,
#[sea_orm(primary_key)]
pub thread_id: i64,
pub session_id: i64,
#[sea_orm(primary_key)]
pub thread_id: i64,
// Below are fields for a debug panel item
pub active_thread_item: i32,
pub seassion_name: String,
Expand Down
31 changes: 27 additions & 4 deletions crates/collab/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ impl Server {
.add_message_handler(
broadcast_project_message_from_host::<proto::RemoveActiveDebugLine>,
)
.add_message_handler(update_debug_client_panel_item)
.add_message_handler(set_debug_client_panel_item)
.add_message_handler(update_debug_adapter)
.add_message_handler(update_debug_client_capabilities)
.add_message_handler(broadcast_project_message_from_host::<proto::ShutdownDebugClient>);
.add_message_handler(shutdown_debug_client);

Arc::new(server)
}
Expand Down Expand Up @@ -2114,6 +2114,29 @@ async fn update_language_server(
Ok(())
}

/// Notify other participants that a debug client has shutdown
async fn shutdown_debug_client(
request: proto::ShutdownDebugClient,
session: Session,
) -> Result<()> {
let guest_connection_ids = session
.db()
.await
.shutdown_debug_client(session.connection_id, &request)
.await?;

broadcast(
Some(session.connection_id),
guest_connection_ids.iter().copied(),
|connection_id| {
session
.peer
.forward_send(session.connection_id, connection_id, request.clone())
},
);
Ok(())
}

/// Notify other participants that a debug panel item has been updated
async fn update_debug_adapter(request: proto::UpdateDebugAdapter, session: Session) -> Result<()> {
let guest_connection_ids = session
Expand All @@ -2135,14 +2158,14 @@ async fn update_debug_adapter(request: proto::UpdateDebugAdapter, session: Sessi
}

/// Notify other participants that there's a new debug panel item
async fn update_debug_client_panel_item(
async fn set_debug_client_panel_item(
request: proto::SetDebuggerPanelItem,
session: Session,
) -> Result<()> {
let guest_connection_ids = session
.db()
.await
.update_debug_client_panel_item(session.connection_id, &request)
.set_debug_client_panel_item(session.connection_id, &request)
.await?;

broadcast(
Expand Down

0 comments on commit 430d252

Please sign in to comment.