|
1 | 1 | # Shared terminal and manual-attach preparation. Installation requires a |
2 | 2 | # single-use grant from the extension process; .libPaths() is never changed. |
| 3 | +vscode_r_with_jgd <- function( |
| 4 | + plot_backend, |
| 5 | + connect, |
| 6 | + jgd_helper = Sys.getenv("VSCODE_R_JGD_HELPER", unset = ""), |
| 7 | + tool_root = Sys.getenv("VSCODE_R_TOOL_ROOT", unset = ""), |
| 8 | + tool_consent_directory = Sys.getenv("VSCODE_R_TOOL_CONSENT_DIRECTORY", unset = ""), |
| 9 | + tool_library_helper = Sys.getenv("VSCODE_R_TOOL_LIBRARY_HELPER", unset = ""), |
| 10 | + tool_consent_helper = Sys.getenv("VSCODE_R_TOOL_CONSENT_HELPER", unset = ""), |
| 11 | + can_prompt = identical(Sys.getenv("VSCODE_R_JGD_CAN_PROMPT", unset = "TRUE"), "TRUE"), |
| 12 | + minimum_version = Sys.getenv("VSCODE_R_JGD_MINIMUM_VERSION", unset = "") |
| 13 | +) { |
| 14 | + if (!is.function(connect)) stop("connect must be a function.", call. = FALSE) |
| 15 | + if (!plot_backend %in% c("jgd", "auto")) { |
| 16 | + return(connect(allow_jgd = TRUE)) |
| 17 | + } |
| 18 | + jgd_setup <- new.env(parent = environment()) |
| 19 | + loaded <- nzchar(jgd_helper) && file.exists(jgd_helper) && |
| 20 | + isTRUE(tryCatch({ |
| 21 | + sys.source(jgd_helper, envir = jgd_setup) |
| 22 | + TRUE |
| 23 | + }, error = function(error) { |
| 24 | + message("vscode-R could not load managed jgd setup resources: ", |
| 25 | + conditionMessage(error)) |
| 26 | + FALSE |
| 27 | + })) |
| 28 | + if (loaded && is.function(jgd_setup$vscode_r_connect_with_jgd)) { |
| 29 | + return(jgd_setup$vscode_r_connect_with_jgd( |
| 30 | + plot_backend, connect, tool_root, tool_consent_directory, |
| 31 | + tool_library_helper, tool_consent_helper, can_prompt, minimum_version |
| 32 | + )) |
| 33 | + } |
| 34 | + message("vscode-R could not load managed jgd setup resources; using the available plot fallback.") |
| 35 | + connect(allow_jgd = FALSE) |
| 36 | +} |
| 37 | + |
3 | 38 | vscode_r_prepare_sess <- function(pkg_path, managed_root, consent_dir, |
4 | 39 | source_helper, installer_helper, |
5 | 40 | timeout_seconds = 180, |
@@ -185,7 +220,22 @@ vscode_r_attach_sess <- function(endpoint, pkg_path, managed_root, consent_dir, |
185 | 220 | setup_timeout_seconds = 300, |
186 | 221 | use_rstudioapi = TRUE, |
187 | 222 | attachment_id = NULL, |
188 | | - auto_activate = TRUE) { |
| 223 | + auto_activate = TRUE, |
| 224 | + tool_root = Sys.getenv("VSCODE_R_TOOL_ROOT", unset = ""), |
| 225 | + tool_consent_directory = Sys.getenv( |
| 226 | + "VSCODE_R_TOOL_CONSENT_DIRECTORY", unset = "" |
| 227 | + ), |
| 228 | + tool_library_helper = Sys.getenv( |
| 229 | + "VSCODE_R_TOOL_LIBRARY_HELPER", unset = "" |
| 230 | + ), |
| 231 | + tool_consent_helper = Sys.getenv( |
| 232 | + "VSCODE_R_TOOL_CONSENT_HELPER", unset = "" |
| 233 | + ), |
| 234 | + jgd_helper = Sys.getenv("VSCODE_R_JGD_HELPER", unset = ""), |
| 235 | + jgd_can_prompt = TRUE, |
| 236 | + jgd_minimum_version = Sys.getenv( |
| 237 | + "VSCODE_R_JGD_MINIMUM_VERSION", unset = "" |
| 238 | + )) { |
189 | 239 | if (!is.null(attachment_id) && |
190 | 240 | !(is.character(attachment_id) && length(attachment_id) == 1L && |
191 | 241 | !is.na(attachment_id) && |
@@ -241,7 +291,15 @@ vscode_r_attach_sess <- function(endpoint, pkg_path, managed_root, consent_dir, |
241 | 291 | args$attachment_id <- attachment_id |
242 | 292 | args$auto_activate <- auto_activate |
243 | 293 | } |
244 | | - do.call(connect, args) |
| 294 | + vscode_r_with_jgd( |
| 295 | + plot_backend, |
| 296 | + function(allow_jgd = TRUE) { |
| 297 | + args$allow_jgd <- allow_jgd |
| 298 | + do.call(connect, args) |
| 299 | + }, |
| 300 | + jgd_helper, tool_root, tool_consent_directory, |
| 301 | + tool_library_helper, tool_consent_helper, jgd_can_prompt, jgd_minimum_version |
| 302 | + ) |
245 | 303 | } |
246 | 304 |
|
247 | 305 | if (profile_process) { |
|
0 commit comments