Skip to content

Handle comm_open data and fire positron.session_init hooks#1088

Open
jennybc wants to merge 6 commits intomainfrom
feature/session-init-hook
Open

Handle comm_open data and fire positron.session_init hooks#1088
jennybc wants to merge 6 commits intomainfrom
feature/session-init-hook

Conversation

@jennybc
Copy link
Member

@jennybc jennybc commented Mar 6, 2026

Addresses posit-dev/positron#9763
Addresses #697

Companion PR in positron: posit-dev/positron#12312

See Positron PR for all discussion at this point.

jennybc and others added 5 commits March 18, 2026 17:09
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Add `comm_open_data` field to `CommSocket` so handlers can access initial state from the frontend. On UI comm open, register the `console_width` and fire session init hooks with `start_type` as the input.
@jennybc jennybc force-pushed the feature/session-init-hook branch from cadcf8b to 532f304 Compare March 19, 2026 01:30
@jennybc jennybc changed the title Support session init hooks Handle comm_open data and fire positron.session_init hooks Mar 19, 2026
Copy link
Contributor

@lionel- lionel- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a few style comments

self.ui_comm_tx = Some(UiCommSender::new(ui_comm_tx));

// Set initial console width from the comm_open data, if provided.
if let Some(width) = comm_open_data.get("console_width").and_then(|v| v.as_i64()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we'd try to deserialise from a struct defined in ark/ui/ui_comm.rs with serde_json::from_value().

Comment on lines +29 to +34
if let Err(err) = harp::exec::RFunction::from(".ps.rpc.setConsoleWidth")
.param("width", RObject::from(width as i32))
.call()
{
log::warn!("Failed to set initial console width: {err:?}");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: you can use the .log_err() method to collapse this to a single call chain.

let start_type = comm_open_data
.get("start_type")
.and_then(|v| v.as_str())
.unwrap_or("new");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the struct approach you can define default values in the struct directly.

)
}

#' @export
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported on the search path? Exporting should generally be a last resort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants