Skip to content

fix: activate R features on demand - #1954

Merged
eitsupi merged 4 commits into
mainfrom
codex/lazy-r-activation
Nov 16, 2026
Merged

eitsupi merged 4 commits into
mainfrom
codex/lazy-r-activation

Conversation

@renkun-ken

@renkun-ken renkun-ken commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Opening an unrelated VS Code window currently activates vscode-R and can start background R language-server and help processes. Remove onStartupFinished and the generic onNotebook:interactive event so activation follows R workspaces/files, R notebooks, restored R webviews, or contributed R commands, terminal profiles, views, and tasks.

Native R Interactive tabs still activate through their persisted R input language, including empty consoles. Background tabs wait until displayed. Update the restoration setting and documentation to explain that saved connections reconnect when R features are used.

Managed R terminals can survive a window reload while vscode-R remains inactive. Document this intentional delay and how to reconnect through an R file or R: Activate R Session. A real reload regression verifies that the terminal/R PID, workspace value, and sess identity are preserved, then that explicit activation establishes a new live connection. The spawned editor wait uses close before ending its log stream so stdout/stderr are drained.

Add pnpm run test:activation and run it in the Linux, macOS, and Windows extension CI jobs. The harness uses fresh profiles without forced activation; persisted-tab checks use ordinary development windows because extension test mode uses in-memory editor storage. Failed activation logs are included in the existing CI artifacts.

The launcher removes inherited ELECTRON_RUN_AS_NODE variables before spawning VS Code, including case variants and empty values that select Node mode on Windows. Subprocess tests cover that environment handling. Parallel session-setup tests use production's 300-second setup budget and read redirected child logs only on failure, so slow Windows source installation and open log handles do not cause false failures.

Closes #1922.

Validation:

  • All 14 hosted CI checks passed on 9dfb20e, including the full Node and extension suites on Linux, macOS, and Windows.
  • Build, type checking, lint, formatting, and activation-harness syntax/lint checks passed.
  • Full base-R attach tests, Arity formatting/linting, and lintr passed after the parallel-fixture fix. Two subprocess environment tests and four activation/restoration cases also passed with an inherited Node-mode flag.
  • All 15 activation cases passed in Linux, macOS, and Windows CI: unrelated/no-folder and Python Interactive windows remain inactive; R/Rmd, R workspace, command, terminal profile, task, and .rnb entry points activate; empty native R inputs restore after full application exits, and persistent R terminals retain their process and workspace across a window reload before reconnecting.
  • Nine targeted cases passed on the minimum supported VS Code 1.101.0, including terminal/task/notebook activation and both native-input restoration paths.
  • The new persistent-terminal reload case passed on VS Code 1.101.0 and 1.145.2. Five focused terminal/Interactive restoration cases also passed with the final logging and marker-publication changes.
  • The existing restores native tabs with execution identities, outputs and draft positions intact integration test passed with the pinned arf 0.7.2-rc.1 runtime.
  • Reinstating the original activation events makes the new no-folder regression case fail as expected: R activates before an R trigger.

Local validation limitation: the focused Run Selection can create a persistent Interactive session and ordinary R exit leaves a restored notice test fails during cleanup with Session agent is disconnected. It reproduces with the original activation events as well as this change. The full hosted extension suites pass on Linux, macOS, and Windows.

@renkun-ken
renkun-ken requested a review from eitsupi November 16, 2026 17:17

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

Review by ChatGPT of a0cc735.

The activation strategy looks sound. Two points remain:

  1. [P2] Verify persistent R terminal restoration. The activation tests explicitly disable terminal.integrated.enablePersistentSessions. After a window reload, VS Code may restore an existing R terminal without triggering onTerminalProfile. If no R document is open, vscode-R may remain inactive and fail to reconnect sess. Please test this scenario or document delayed reconnection as intentional behavior.

  2. [P3] Use close instead of exit for the spawned VS Code process. In scripts/test-activation.cjs, the exit event can occur before stdout/stderr streams have closed. Calling log.end() afterward may race with remaining output. Waiting for close avoids this issue.

No other blocking issues identified. The overall approach and activation regression coverage look appropriate.

@eitsupi
eitsupi merged commit bc1c68e into main Nov 16, 2026
15 checks passed
@eitsupi
eitsupi deleted the codex/lazy-r-activation branch November 16, 2026 23:52
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.

Avoid activating the extension in non-R projects

2 participants