Skip to content

Commit ab33926

Browse files
authored
Util for getting active request (#1110)
I'm preparing to do some work to add more metadata to the execute request, and am adding this to make it easy to inspect it. <img width="809" height="737" alt="image" src="https://github.com/user-attachments/assets/bea0ff60-6b92-4e55-99ab-fd5bb8a1f2fa" />
1 parent d276183 commit ab33926

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

crates/ark/src/console/console_repl.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,11 @@ impl Console {
721721
}
722722
}
723723

724+
/// Get the active execute request, if any.
725+
pub(crate) fn get_active_execute_request(&self) -> Option<&ExecuteRequest> {
726+
self.active_request.as_ref().map(|req| &req.request)
727+
}
728+
724729
/// Get the current execution context if an active request exists.
725730
/// Returns (execution_id, code) tuple where execution_id is the Jupyter message ID.
726731
pub(crate) fn get_execution_context(&self) -> Option<(String, String)> {
@@ -2790,3 +2795,16 @@ unsafe extern "C-unwind" fn ps_get_virtual_document(uri: SEXP) -> anyhow::Result
27902795
None => Ok(RObject::null().sexp),
27912796
}
27922797
}
2798+
2799+
/// Returns the currently active execute request as an R named list,
2800+
/// or NULL if no execute request is in flight.
2801+
#[harp::register]
2802+
pub unsafe extern "C-unwind" fn ps_get_active_request() -> anyhow::Result<SEXP> {
2803+
let Some(req) = Console::get().get_active_execute_request() else {
2804+
return Ok(libr::R_NilValue);
2805+
};
2806+
2807+
let json = serde_json::to_value(req)?;
2808+
let r_obj = RObject::try_from(json)?;
2809+
Ok(r_obj.sexp)
2810+
}

crates/ark/src/modules/positron/utils.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
ark_version
5757
}
5858

59+
# Return the active (in flight) execute_request data structure; useful for
60+
# inspecting what metadata has been sent from the front end.
61+
#
62+
# Internal utility; invoke with: `.ps.internal(active_request())`
63+
active_request <- function() {
64+
.ps.Call("ps_get_active_request")
65+
}
66+
5967
# Sleep that doesn't check for interrupts to test an unresponsive runtime.
6068
#' @export
6169
.ps.deep_sleep <- function(secs) {

0 commit comments

Comments
 (0)