Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:
- uses: ./.github/actions/prepare-test-runtime
- name: Verify terminal profile inheritance
run: Rscript --vanilla R/tests/terminal-profile.R
- name: Verify managed jdv preparation
run: pnpm run test:prepare-jdv
- name: Verify managed jgd preparation
run: pnpm run test:prepare-jgd
- name: Verify managed rstudioapi preparation
Expand Down
27 changes: 27 additions & 0 deletions R/attach_sess.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ vscode_r_with_rstudioapi <- function(
invisible(FALSE)
}

vscode_r_configure_jdv <- function(
ns,
tool_root = Sys.getenv("VSCODE_R_TOOL_ROOT", unset = ""),
consent_directory = Sys.getenv("VSCODE_R_TOOL_CONSENT_DIRECTORY", unset = ""),
library_helper = Sys.getenv("VSCODE_R_TOOL_LIBRARY_HELPER", unset = ""),
consent_helper = Sys.getenv("VSCODE_R_TOOL_CONSENT_HELPER", unset = ""),
prepare_helper = Sys.getenv("VSCODE_R_TOOL_PREPARE_HELPER", unset = "")
) {
if (exists(".configure_jdv_tools", envir = ns, inherits = FALSE)) {
get(".configure_jdv_tools", envir = ns)(list(
tool_root = tool_root,
consent_directory = consent_directory,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Refresh the native terminal’s consent directory after a window reload. The extension creates a new directory per host and removes the old one on shutdown. A surviving R terminal reconnects through discovery without rerunning this configuration. I exercised that reconnect with two local sess endpoints. R attached to the replacement endpoint, but its first View() still checked the retired directory and sent no install request. Updating only the directory made the next View() reach the replacement consent service. Please refresh it as part of reconnect and cover a terminal whose first jdv install offer comes after reload.

library_helper = library_helper,
consent_helper = consent_helper,
prepare_helper = prepare_helper
))
}
}

vscode_r_prepare_sess <- function(
pkg_path,
managed_root,
Expand Down Expand Up @@ -384,6 +403,14 @@ vscode_r_attach_sess <- function(
args$attachment_id <- attachment_id
args$auto_activate <- auto_activate
}
vscode_r_configure_jdv(
ns,
tool_root,
tool_consent_directory,
tool_library_helper,
tool_consent_helper,
tool_prepare_helper
)
vscode_r_with_rstudioapi(
use_rstudioapi,
tool_prepare_helper,
Expand Down
51 changes: 45 additions & 6 deletions R/prepare-tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ vscode_r_connect_with_jgd <- function(
connect(allow_jgd = ready)
}

# Source the tool helpers once, so a caller can reuse them across preparations.
vscode_r_load_tool_helpers <- function(helpers) {
tools <- new.env(parent = environment(vscode_r_load_tool_helpers))
for (helper in helpers) {
sys.source(helper, envir = tools)
}
tools
}

# Select, install if approved, and eagerly load one tool package. Returns TRUE
# when a compatible copy is loaded, otherwise prints a short message and
# returns FALSE so the caller can continue with its fallback. `policy` is the
Expand All @@ -43,7 +52,10 @@ vscode_r_prepare_tool_package <- function(
minimum_version,
support,
fallback,
report_load_failure = TRUE
report_load_failure = TRUE,
tool_environment = vscode_r_load_tool_helpers(helpers),
consent_available = function() TRUE,
on_decline = function() NULL
) {
if (!(is.logical(can_prompt) && length(can_prompt) == 1L && !is.na(can_prompt))) {
stop("can_prompt must be a single non-NA logical value.", call. = FALSE)
Expand All @@ -56,10 +68,6 @@ vscode_r_prepare_tool_package <- function(

tryCatch(
{
tool_environment <- new.env(parent = environment(vscode_r_prepare_tool_package))
for (helper in helpers) {
sys.source(helper, envir = tool_environment)
}
if (!can_prompt) {
# A compatible ordinary or managed copy remains usable without resolving a new plan.
return(!is.null(tool_environment$tool_library_load(package, minimum_version, tool_root)))
Expand All @@ -72,7 +80,9 @@ vscode_r_prepare_tool_package <- function(
policy,
consent_timeout_seconds = 180,
install_timeout_seconds = 300,
resolution_timeout_seconds = 30
resolution_timeout_seconds = 30,
consent_available = consent_available,
on_decline = on_decline
)
if (is.null(prepared)) {
message("vscode-R optional ", package, " installation was not approved; ", fallback, ".")
Expand Down Expand Up @@ -164,3 +174,32 @@ vscode_r_prepare_rstudioapi <- function(
report_load_failure = FALSE
)
}

# Select an available jdv before permitting an explicit View() to ask for installation.
vscode_r_prepare_jdv <- function(
tool_root,
consent_directory,
library_helper,
consent_helper,
minimum_version,
can_prompt,
tool_environment,
consent_available,
on_decline
) {
vscode_r_prepare_tool_package(
"jdv",
"once",
tool_root,
consent_directory,
library_helper,
consent_helper,
can_prompt,
minimum_version,
support = "jdv data viewer",
fallback = "using the available data viewer fallback; install a compatible jdv in your R library",
tool_environment = tool_environment,
consent_available = consent_available,
on_decline = on_decline
)
}
1 change: 1 addition & 0 deletions R/profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ invisible(local({
return(invisible(FALSE))
}

vscode_r_configure_jdv(ns)
plot_backend <- Sys.getenv("SESS_PLOT_BACKEND", "auto")
connect <- get("connect", envir = ns, inherits = FALSE)
use_rstudioapi <- as.logical(Sys.getenv("SESS_RSTUDIOAPI", "TRUE"))
Expand Down
Loading
Loading