From 1c2d4996154fa0dea565e1c9b94b870a6653897a Mon Sep 17 00:00:00 2001 From: Randy Lai Date: Sat, 2 May 2026 19:39:17 -0700 Subject: [PATCH 1/2] fix(session): enable reconnection for managed terminals in profile.R --- R/profile.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/profile.R b/R/profile.R index 0a9b081f..341cc11b 100644 --- a/R/profile.R +++ b/R/profile.R @@ -26,8 +26,6 @@ local({ if (requireNamespace("sess", quietly = TRUE)) { sess::sess_app( - port = as.integer(Sys.getenv("SESS_PORT")), - token = Sys.getenv("SESS_TOKEN"), use_rstudioapi = as.logical(Sys.getenv("SESS_RSTUDIOAPI", "TRUE")), use_httpgd = as.logical(Sys.getenv("SESS_USE_HTTPGD", "TRUE")) ) From ee2053d417c1cd00f77a1fd23b35b31702c173ba Mon Sep 17 00:00:00 2001 From: Randy Lai Date: Sat, 2 May 2026 19:45:48 -0700 Subject: [PATCH 2/2] refactor(session): rename sess_app to connect in sess package --- R/profile.R | 2 +- sess/DESCRIPTION | 2 +- sess/NAMESPACE | 2 +- sess/R/server.R | 8 ++++---- sess/man/{sess_app.Rd => connect.Rd} | 12 +++++++----- src/session.ts | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) rename sess/man/{sess_app.Rd => connect.Rd} (64%) diff --git a/R/profile.R b/R/profile.R index 341cc11b..627450e2 100644 --- a/R/profile.R +++ b/R/profile.R @@ -25,7 +25,7 @@ local({ }) if (requireNamespace("sess", quietly = TRUE)) { - sess::sess_app( + sess::connect( use_rstudioapi = as.logical(Sys.getenv("SESS_RSTUDIOAPI", "TRUE")), use_httpgd = as.logical(Sys.getenv("SESS_USE_HTTPGD", "TRUE")) ) diff --git a/sess/DESCRIPTION b/sess/DESCRIPTION index 812a9656..46e0e0f1 100644 --- a/sess/DESCRIPTION +++ b/sess/DESCRIPTION @@ -16,4 +16,4 @@ Imports: methods, rstudioapi, svglite -RoxygenNote: 7.3.3 +Config/roxygen2/version: 8.0.0 diff --git a/sess/NAMESPACE b/sess/NAMESPACE index b4d6a57d..0bad13cd 100644 --- a/sess/NAMESPACE +++ b/sess/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(connect) export(notify_client) export(register_hooks) export(request_client) -export(sess_app) diff --git a/sess/R/server.R b/sess/R/server.R index 727ee37f..8e189b2b 100644 --- a/sess/R/server.R +++ b/sess/R/server.R @@ -7,7 +7,7 @@ #' be enabled? Defaults to TRUE. #' @param use_httpgd Logical. Should httpgd be used for plotting if available? Defaults to TRUE #' @export -sess_app <- function(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpgd = TRUE) { +connect <- function(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpgd = TRUE) { # Initialize state .sess_env$server <- NULL .sess_env$ws <- NULL @@ -55,7 +55,7 @@ sess_app <- function(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpg cat(sprintf("\r%s\n\n%s", msg, prompt)) } - connect <- function() { + do_connect <- function() { url <- sprintf("ws://127.0.0.1:%s/?token=%s", port, token) ws <- websocket::WebSocket$new( url, @@ -152,7 +152,7 @@ sess_app <- function(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpg token <<- config$token }, error = function(e) NULL) } - connect() + do_connect() }, 5) }) @@ -164,7 +164,7 @@ sess_app <- function(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpg } # Connect to VS Code - connect() + do_connect() # Register runtime hooks if (is.na(use_rstudioapi)) use_rstudioapi <- TRUE diff --git a/sess/man/sess_app.Rd b/sess/man/connect.Rd similarity index 64% rename from sess/man/sess_app.Rd rename to sess/man/connect.Rd index 59967e1c..c88d9c82 100644 --- a/sess/man/sess_app.Rd +++ b/sess/man/connect.Rd @@ -1,17 +1,19 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/server.R -\name{sess_app} -\alias{sess_app} +\name{connect} +\alias{connect} \title{Start the client R IPC connection} \usage{ -sess_app(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpgd = TRUE) +connect(port = NULL, token = NULL, use_rstudioapi = TRUE, use_httpgd = TRUE) } \arguments{ -\item{port}{Integer. The port of the VS Code WebSocket server. If NULL, it will use SESS_PORT env var.} +\item{port}{Integer. The port of the VS Code WebSocket server. +If NULL, it will use SESS_PORT env var.} \item{token}{String. The authentication token. If NULL, it will use SESS_TOKEN env var.} -\item{use_rstudioapi}{Logical. Should the rstudioapi emulation layer be enabled? Defaults to TRUE.} +\item{use_rstudioapi}{Logical. Should the rstudioapi emulation layer +be enabled? Defaults to TRUE.} \item{use_httpgd}{Logical. Should httpgd be used for plotting if available? Defaults to TRUE} } diff --git a/src/session.ts b/src/session.ts index 90f8ab62..1b0a730b 100644 --- a/src/session.ts +++ b/src/session.ts @@ -1016,7 +1016,7 @@ export async function sessionRequest(server: SessionServer, data: Record { const { port, token } = await getGlobalSessionServer(); - const command = `sess::sess_app(port=${port}, token="${token}")`; + const command = `sess::connect(port=${port}, token="${token}")`; void vscode.env.clipboard.writeText(command); void vscode.window.showInformationMessage(`R command copied to clipboard: ${command}`); }