Skip to content

Commit

Permalink
expose detach function to R API
Browse files Browse the repository at this point in the history
  • Loading branch information
Tal Hadad committed Aug 2, 2023
1 parent 0d3f446 commit a7abdcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions R/session/init_late.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ source(file.path(dir_init, "vsc.R"), local = .vsc)
exports <- local({
.vsc <- .vsc
.vsc.attach <- .vsc$attach
.vsc.detach <- .vsc$detach
.vsc.view <- .vsc$show_dataview
.vsc.browser <- .vsc$show_browser
.vsc.viewer <- .vsc$show_viewer
Expand Down
16 changes: 10 additions & 6 deletions R/session/vsc.R
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ attach <- function(host = "127.0.0.1", port = NA) {
rstudioapi_util_env$update_addin_registry(addin_registry)
}
if (!is.na(request_tcp_connection)) {
close(request_tcp_connection)
request_tcp_connection <<- NA
detach()
}
if (!is.na(port)) {
request_tcp_connection <<- socketConnection(
Expand Down Expand Up @@ -685,6 +684,14 @@ attach <- function(host = "127.0.0.1", port = NA) {
)
}

detach <- function() {
request("detach")
if (!is.na(request_tcp_connection)) {
close(request_tcp_connection)
request_tcp_connection <<- NA
}
}

path_to_uri <- function(path) {
if (length(path) == 0) {
return(character())
Expand Down Expand Up @@ -965,9 +972,6 @@ reg.finalizer(.GlobalEnv, function(e) {
# TODO: When exiting radian by EOF("CTRL+D") when coonecting to vsc by TCP,
# the TCP connection is getting closed before we're able to call detach...
tryCatch({
.vsc$request("detach")
if (!is.na(request_tcp_connection)) {
close(request_tcp_connection)
}
detach()
}, error = function(e) NULL)
}, onexit = TRUE)

0 comments on commit a7abdcf

Please sign in to comment.