Skip to content

feat: offer rstudioapi from the vscode-R-managed tool library - #1909

Merged
eitsupi merged 2 commits into
REditorSupport:mainfrom
eitsupi:feat/rstudioapi-tool-library
Oct 26, 2026
Merged

eitsupi merged 2 commits into
REditorSupport:mainfrom
eitsupi:feat/rstudioapi-tool-library

Conversation

@eitsupi

@eitsupi eitsupi commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

As a step towards #1859, this PR removes the rstudioapi package from the R package dependencies of sess. Like jgd in #1907, vscode-R now offers to install it into the vscode-R-managed tool library when RStudio API emulation needs it. User and project libraries are not modified.

Why rstudioapi is still needed

sess only calls rstudioapi:: inside the emulated functions, which it patches into the rstudioapi namespace when rstudioapi is loaded. sess itself therefore works without it. However, because the managed sess library currently installs and loads rstudioapi, packages that check requireNamespace("rstudioapi") (for example usethis) and console calls such as rstudioapi::navigateToFile() reach the emulation even in isolated libraries such as renv projects. To keep this behavior, vscode-R prepares rstudioapi before sess::connect() and loads it eagerly.

rstudioapi has no Depends, Imports, or LinkingTo in any CRAN release and needs no compilation, so it meets the tool library requirements. The minimum version is 0.4.0, the first release that exports all the document position and range helpers used by the emulation.

Behavior

  • sess lists rstudioapi in Suggests instead of Imports, and the managed sess installation no longer installs or preloads it.
  • When r.session.emulateRStudioAPI is enabled, terminal startup and manual attach use a compatible rstudioapi that is already loaded or in the normal libraries, then the tool library copy. Otherwise, they offer installation.
  • The offer appears at most once per VS Code window session. Don't ask again is remembered for the current minimum version, as with jgd and the "auto" plot backend.
  • Declining, failures, or offline repositories print one short message. Emulation stays enabled and applies whenever rstudioapi is loaded later. A loaded rstudioapi is never replaced.
  • When no offer can be shown, R uses an existing compatible copy without querying repositories. When emulation is disabled, nothing is prepared.

Consent

Package consent requests now carry a prompt policy (always or once) instead of the plot backend, and the prompt state and Don't ask again are tracked per package. A jgd and an rstudioapi request in the same startup are therefore independent. The behavior of jgd is unchanged, including its stored Don't ask again choice. Minimum versions of tool packages are defined in one place and passed to R.

The jgd preparation helper is generalized and renamed to R/prepare-tools.R.

Experimental R Interactive still installs rstudioapi for its private runtime and is otherwise unchanged.

Move rstudioapi from sess Imports to Suggests. When RStudio API emulation
is enabled and no compatible rstudioapi is available, terminal startup and
manual attach offer to install it into the managed tool library, at most
once per extension host session, and load it before sess connects.

Consent requests now carry a prompt policy instead of the plot backend,
and prompt state and Don't ask again are tracked per package. The
private R Interactive runtime still installs rstudioapi.
@eitsupi
eitsupi marked this pull request as ready for review October 25, 2026 23:43
@eitsupi
eitsupi requested a review from renkun-ken October 25, 2026 23:43

@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.

Reviewed 2ad61f5. No actionable findings.

The terminal and manual-attach paths prepare rstudioapi before sess starts emulation, and declining or failing preparation preserves the hook for a later namespace load. The per-package prompt state keeps jgd and rstudioapi decisions independent and preserves the existing jgd dismissal key. I also checked the archived CRAN rstudioapi 0.4.0 release: it exports the document position/range helpers used by sess and has no required package dependencies or compilation.

Validation on macOS:

  • Extension build and TypeScript compilation passed.
  • 15 focused Node tests passed, including private-library loading and renv isolation.
  • 91 VS Code tests passed across terminal, session, and consent-persistence suites.
  • All six R bootstrap/tool-preparation suites passed; the optional-rstudioapi runtime-hook test passed all 7 checks.

All six GitHub CI checks are green at the reviewed head.

@eitsupi
eitsupi merged commit bca6f7c into REditorSupport:main Oct 26, 2026
11 of 12 checks passed
@eitsupi
eitsupi deleted the feat/rstudioapi-tool-library branch October 26, 2026 03:23
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