Skip to content

feat: offer to install jdv in the managed tool library on View() - #2017

Open
eitsupi wants to merge 2 commits into
feat/interactive-jdv-dispatch-addressfrom
feat/jdv-on-demand-install
Open

eitsupi wants to merge 2 commits into
feat/interactive-jdv-dispatch-addressfrom
feat/jdv-on-demand-install

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

View() uses jdv only when a compatible jdv is already installed in a library the R session can see. Projects isolated with renv, or users who never installed jdv, always get the sess data viewer.

When no compatible jdv is available, an explicit View() now offers to install jdv in the vscode-R managed tool library, through the same file-based consent that jgd and rstudioapi use. This applies to View() in the terminal and in an Interactive cell, including the code that a Workspace root item runs.

  • The selection order matches jgd: an already loaded namespace, then a compatible copy on .libPaths(), then the managed tool library, and only then an offer to install. The managed copy is loaded with loadNamespace(lib.loc = ...); the tool library is never added to .libPaths() and the user's libraries are never written. An already loaded older jdv is not replaced, and R asks for a restart. An unloaded older copy in a project library can be superseded by the managed copy for that R process.
  • The consent uses the once policy. A declined offer is remembered for the R session, so later View() calls neither ask again nor query the repositories; a compatible jdv installed separately is still picked up. A declined or failed installation prints the reason and keeps the sess data viewer.
  • R: Create R Terminal sessions set up jdv before connecting, so they find a managed jdv or offer to install it like attached terminals.
  • In an Interactive session, installation is offered only while a window controls the session and can answer the consent. Without one, View() keeps the sess data viewer instead of waiting for an answer, so a detached session does not stall its queue.
  • The View() call that installs jdv does not follow the variable: base R cannot tell, after the value is evaluated, whether it was an ordinary binding or a promise that call forced. The next View() follows it. The data viewer docs note this.
  • Short requests from the editor, such as opening a nested Workspace item, never start an installation; without jdv they keep the sess data viewer.
  • Arrow input without nanoarrow is ruled out before jdv is selected, so it never triggers an installation. nanoarrow is not installed in the tool library, because it could mask the version the user intends to use.
  • Opening a nested Workspace item in an Interactive session now requires control of the session and uses the controlling window's jdv listener. Errors from Workspace open requests are now shown where the item was clicked instead of being dropped.

@eitsupi
eitsupi added this pull request to stack #2016 November 30, 2026 16:24
@eitsupi eitsupi changed the title feat: offer to install jdv in the managed tool library on View() feat: offer to install jdv in the managed tool library on View() Nov 30, 2026
@eitsupi eitsupi added this to the 3.6.0 milestone Nov 30, 2026
@eitsupi
eitsupi force-pushed the feat/jdv-on-demand-install branch from 9720774 to 2916762 Compare November 30, 2026 16:34

@renkun-ken renkun-ken left a comment

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.

I tested the managed install fixture, the normal terminal profile, and a persistent Interactive session with a local package repository. The fixture passed, but R: Create R Terminal missed the new setup and a detached cell could block the execution queue waiting for an install decision. I also found three cases in package selection and first-use behavior. The red Windows check comes from #2014’s frame-splitting test and is reported there.

Comment thread R/attach_sess.R Outdated
args$auto_activate <- auto_activate
}
if (exists(".configure_jdv_tools", envir = ns, inherits = FALSE)) {
get(".configure_jdv_tools", envir = ns)(list(

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.

Configure jdv for terminals started by the extension. R/profile.R calls vscode_r_prepare_sess() and then connect() directly, so a normal R: Create R Terminal never reaches this block. I started R through that profile with a successful protocol-v3 attachment and a compatible jdv already in the managed library. jdv_tools was NULL, and View(data.frame(a = 1:2)) opened the sess viewer. This path also cannot offer installation when jdv is missing. Please initialize jdv on the profile path as well and exercise it with the managed library outside .libPaths(). The current fixture calls .configure_jdv_tools() itself.

Comment thread sess/R/handlers.R Outdated
as.character(.jdv_min_version),
can_prompt = install &&
.ipc_json_string(config$consent_directory) &&
dir.exists(config$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.

Skip install consent when the Interactive controller has detached. ToolConsentService.stop() leaves this generation’s directory on disk, so dir.exists() stays true after the last window disconnects. I started a cell, queued a second cell, detached the controller, and let the first reach View() against a local package repository. R wrote a .request with no service left to answer it. The second cell remained queued until I supplied a decline. In normal use that wait can last 180 seconds. Gate the offer on a live controller or service, and let detached execution fall back promptly.

Comment thread sess/R/hooks.R Outdated
!isTRUE(.sess_env$answering_request)
# The value is needed to rule out Arrow input without nanoarrow before
# offering installation. A newly installed jdv has no pre-force binding.
if (jdv_ready || (can_install && .jdv_supported(install = TRUE, prepare = prepare))) {

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.

Avoid resolving the package again after a declined offer. On two consecutive View() calls in the same R process, declining the first still led the second to call available.packages() and write a second consent request. The editor suppresses the repeat prompt, but only after R has queried the repository. Each call can incur the configured 30-second repository timeout before showing the fallback. Remember the declined offer for the session while continuing to check for a compatible copy the user installs separately.

Comment thread sess/R/hooks.R Outdated
if (jdv_enabled) {
# Resolve the caller's binding before forcing x. Forcing an unreadable
# promise can change whether jdv considers it safe to follow.
jdv_ready <- .jdv_supported(prepare = prepare)

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.

Check Arrow eligibility before loading the managed namespace. I tested an Arrow reader with nanoarrow absent, an unloaded older project jdv, and a compatible managed jdv. View() used the fallback, but this early .jdv_supported() call had already loaded the managed jdv. Subsequent project code then resolved that version for the rest of the R process. The current missing-nanoarrow test also lacks a managed copy, so it misses the side effect. Keep this fallback path free of jdv selection and loading.

Comment thread sess/R/hooks.R Outdated
# The value is needed to rule out Arrow input without nanoarrow before
# offering installation. A newly installed jdv has no pre-force binding.
if (jdv_ready || (can_install && .jdv_supported(install = TRUE, prepare = prepare))) {
if (.jdv_show(x, title_key, if (!arrow) binding, address = short_open$address)) {

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.

Preserve variable tracking on the call that installs jdv. On R 4.6 with tracking enabled, I checked the registration for two consecutive calls to View(df). The first call approved installation and registered the ordinary variable with no binding. The second registered the same variable with tracking enabled. A user who keeps that first panel open therefore misses later reassignments. Please preserve enough pre-evaluation binding information for an ordinary bound variable to track on first use, while keeping delayed or active bindings safe.

When no compatible jdv is available, an explicit View() in the terminal or in
an Interactive cell, including the code that a Workspace root item runs, now
offers to install jdv in the vscode-R managed tool library through the same
file-based consent as jgd and rstudioapi. The installed copy is loaded with
loadNamespace(lib.loc = ...) without adding the tool library to .libPaths().
A compatible copy in the user's libraries is still preferred, and an already
loaded older jdv asks for a restart instead of being replaced.

Short requests from the editor, such as opening a nested Workspace item,
never start an installation. Without jdv they keep the sess data viewer, as
does a declined or failed installation. Arrow input without nanoarrow is
ruled out before jdv is selected, so it never triggers an installation.

Opening a nested Workspace item in an Interactive session now requires
control of the session and uses the controlling window's jdv listener.
Errors from that request are shown where the item was clicked.
@eitsupi
eitsupi force-pushed the feat/jdv-on-demand-install branch from 2916762 to 0e8d2c2 Compare December 1, 2026 12:34
The terminal profile now configures jdv before connecting, so View() in
an R: Create R Terminal session finds a managed jdv or offers to install
it. An Interactive session offers installation only while the controlling
editor refreshes a consent marker, and stops waiting if it disappears, so
a detached controller no longer holds the queue. A declined offer is
remembered for the R session, and Arrow input without nanoarrow falls
back before jdv is selected or loaded.

The View() call that installs jdv does not track the variable, since
base R cannot tell an ordinary binding from a promise that call forced;
the next View() does. The code and the viewer docs note this.
@eitsupi
eitsupi marked this pull request as ready for review December 1, 2026 13:08
@eitsupi
eitsupi requested a review from renkun-ken December 1, 2026 13:08

@renkun-ken renkun-ken left a comment

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.

The terminal profile now finds managed jdv, and the new checks for detached sessions, remembered declines, and Arrow input without nanoarrow passed. I also verified that the initial View which installs jdv has the documented tracking limitation. Two other cases remain on 044b3ee: a first View with jdv already installed, and on-demand installation in a terminal that reconnects after a window reload.

Comment thread sess/R/handlers.R
!nzchar(as.character(expression)) ||
!isTRUE(track) ||
!.jdv_supported()
!isNamespaceLoaded("jdv")

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.

Keep the first View(df) live when compatible jdv is already installed. In a fresh R 4.6.1 session with jdv 0.1.0 on .libPaths(), View(df) followed by reassignment produced only generation 1. The same sequence on the base commit produced generations 1 and 2. The namespace is still unloaded when this check runs, so the first view registers without a binding. No installation or consent is involved. The documented exception for the call that installs jdv can stay separate. Please test the first direct View(df) before a Workspace open or anything else loads the namespace.

Comment thread R/attach_sess.R
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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants