Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to R Console will be documented in this file.

## Unreleased

### Added

- Added a `sess` IPC proxy for vscode-R 3.0 session integration, allowing R Console to forward vscode-R session traffic while requesting workspace and runtime member completions from the current embedded R session.

### Changed

- Runtime `$`, `@`, and data-frame bracket completion in vscode-R 3.0 `sess` mode now uses the active console session through `sess` JSON-RPC.

## [0.4.1] - 2026-07-11

### Added
Expand Down
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ Use `R Console: Manage Persistent Sessions...` to manage running R Console sessi

R Console reads several settings from [vscode-R](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r):

| Setting | Purpose |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `r.rpath.windows` | R executable path on Windows for R Console startup |
| `r.rpath.mac` | R executable path on macOS for R Console startup |
| `r.rpath.linux` | R executable path on Linux for R Console startup |
| `r.rterm.option` | Extra arguments passed to R |
| `r.sessionWatcher` | Enables the [vscode-R](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r) session watcher bridge |
| `r.bracketedPaste` | Enables bracketed paste mode |
| `r.lsp.args` | Extra arguments passed when starting`languageserver` |
| `r.lsp.use_stdio` | Uses stdio instead of a loopback socket for the console LSP client when supported |
| `r.alwaysUseActiveTerminal` | Controls whether the new console is immediately focused |
| Setting | Purpose |
| --- | --- |
| `r.rpath.windows` | R executable path on Windows for R Console startup |
| `r.rpath.mac` | R executable path on macOS for R Console startup |
| `r.rpath.linux` | R executable path on Linux for R Console startup |
| `r.rterm.option` | Extra arguments passed to R |
| `r.sessionWatcher` | Enables the [vscode-R](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r) session watcher or console-scoped JSON-RPC bridge |
| `r.bracketedPaste` | Enables bracketed paste mode |
| `r.lsp.args` | Extra arguments passed when starting `languageserver` |
| `r.lsp.use_stdio` | Uses stdio instead of a loopback socket for the console LSP client when supported |
| `r.alwaysUseActiveTerminal` | Controls whether the new console is immediately focused |

If `r.rpath.*` is set, an ambient `R_HOME` does not override it. If `r.rpath.*` is unset, ambient `R_HOME` is used before `PATH`.

Expand All @@ -95,22 +95,15 @@ R Console also contributes its own settings:

## Dependency Model

- [vscode-R](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r) is a hard dependency. R Console uses the same configured R binary.
- [vscode-R](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r) is a hard dependency. R Console uses the same configured R binary, session bootstrap, session watcher, and supported JSON-RPC session protocol.
- R's `languageserver` package is optional at runtime but required for language-server completion.
- The bundled R backend is required at runtime. If the bundled backend for the current target is missing, the console does not fall back to a separate backend.

> [!WARNING]
> Future compatibility change
>
> Only official vscode-R 2.8.x releases are currently supported. Newer vscode-R builds are moving to a WebSocket and JSON-RPC 2.0 architecture.
>
> A future R Console update will support both vscode-R architectures once the new architecture is officially released.
- The bundled `R_CONSOLE_HOST` sidecar is required at runtime. If the bundled binary for the current target is missing, the console does not fall back to a separate backend.

## Acknowledgements

R Console is built on the broader VS Code, Rust, and R ecosystems, and on the work of open-source projects that informed the extension. In particular:

- [vscode-R](https://github.com/REditorSupport/vscode-R) - R Console depends on [vscode-R](https://github.com/REditorSupport/vscode-R) for configuration, session bootstrap, session watching, and the surrounding VS Code R workflow.
- [vscode-R](https://github.com/REditorSupport/vscode-R) - R Console depends on vscode-R for configuration, session bootstrap, session watching, the supported JSON-RPC session protocol, and the surrounding VS Code R workflow.
- [arf](https://github.com/eitsupi/arf) - The embedded-R host design was heavily informed by arf's Rust-based approach to loading and embedding R, platform-specific console initialization, callback wiring, event/input-handler pumping, and backend architecture.
- [Ark](https://github.com/posit-dev/ark) - The native R frontend model, nested-input handling, ReadConsole recovery concepts, and generic R event-loop integration were important references for the backend design.
- [rchitect](https://github.com/randy3k/rchitect) - Rchitect was a reference for embedding R from a non-R host process, including R home/shared-library discovery and callback/FFI boundary concepts.
Expand Down
124 changes: 89 additions & 35 deletions docs/IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ is used as a dependency.

| Project | What is referenced or used | Where it appears here |
| --- | --- | --- |
| [`vscode-R`](https://github.com/REditorSupport/vscode-R) | Used directly for R executable settings, `R/session/init.R`, watcher files, attach/session metadata, and optional session-server member completion. | `src/Terminal/options.ts`, `resources/r/console-profile.R`, `src/Runtime/sessionWatcher.ts` |
| [`vscode-R`](https://github.com/REditorSupport/vscode-R) | Used for R executable settings and the JSON-RPC session protocol used for attach metadata, workspace data, and member completion. | `src/Terminal/options.ts`, `resources/r/console-profile.R`, `src/Runtime/sessionWatcher.ts`, `src/Runtime/sessProxy.ts` |
| [`arf`](https://github.com/eitsupi/arf) | Reference for Rust embedded-R host structure, dynamic R loading, platform-specific R initialization, callback wiring, generic event/input-handler pumping, and interrupt state handling. | `sidecar/pty-host/src/host.rs` |
| [Ark](https://github.com/posit-dev/ark) | Reference for native R frontend concepts, `ReadConsole` recovery after interrupts/nested input, nested-input separation, and generic R event/finalizer pumping while waiting for input. | `sidecar/pty-host/src/host.rs` |
| [`rchitect`](https://github.com/randy3k/rchitect) | Reference for embedding R from a non-R host process, R home/shared-library discovery, and callback/FFI boundary patterns. | `sidecar/pty-host/src/host.rs`, `src/Terminal/options.ts` |
Expand Down Expand Up @@ -427,8 +427,10 @@ The console depends on `vscode-R`, but it does not own or manage the
Implementation files:

- [`src/Terminal/options.ts`](../src/Terminal/options.ts)
- [`src/Terminal/rTerminal/runtime.ts`](../src/Terminal/rTerminal/runtime.ts)
- [`resources/r/console-profile.R`](../resources/r/console-profile.R)
- [`src/Runtime/sessionWatcher.ts`](../src/Runtime/sessionWatcher.ts)
- [`src/Runtime/sessProxy.ts`](../src/Runtime/sessProxy.ts)

### 3.1 Startup Settings From `vscode-R`

Expand All @@ -454,22 +456,56 @@ The same selected R executable is used for:
- the embedded backend
- the console-owned `languageserver` process

### 3.2 Startup Bootstrap From `vscode-R`

The console requires:

- `REditorSupport.r/R/session/init.R`

`options.ts` resolves the installed `REditorSupport.r` extension path through
the VS Code extension API. Startup is rejected if `init.R` is missing.
### 3.2 Startup Bootstrap

When `r.sessionWatcher` is enabled, startup chooses one vscode-R session
integration:

- `sess`: pipe-based architecture exposed by vscode-R's `r.connectToSession`
command. `rTerminal/runtime.ts` asks vscode-R for the current attach command,
reads the generated attach script, extracts its `pipe_path`, starts a
console-owned `SessProxy`, and contributes the proxy pipe path as `SESS_PIPE`
to the embedded R launch.
- `legacy`: legacy file-based watcher architecture. `R Console` sources vscode-R's
`R/session/init.R` and uses `VSCODE_WATCHER_DIR`.

In `sess` mode, vscode-R owns the IPC server and package installation/update
policy. The `sess` R package may be bundled with vscode-R or installed as a
regular R package; R Console does not use its filesystem location for
architecture detection. The transport is a Unix socket on macOS/Linux or a
Windows named pipe. Messages are JSON-RPC 2.0 objects framed as
newline-delimited JSON. R Console does not target the obsolete
WebSocket/port-token `sess` transport.

The `SessProxy` is a transparent IPC proxy. The embedded R session connects to
the console-owned proxy pipe, and the proxy connects to vscode-R's real pipe.
Raw newline-delimited JSON-RPC messages are forwarded in both directions. R
Console observes workspace responses and injects its own `workspace` and
`completion` requests when the console needs session data. It does not call
vscode-R internal APIs and does not use VS Code's global completion command for
runtime completion.

The proxy is scoped to the embedded backend runtime session and is indexed by
the backend session id while connected. Startup uses
`sess::connect(pipe_path = ...)` against the proxy pipe; the `sess` package
performs the normal attach handshake, which is forwarded to vscode-R. When a
console terminal gains focus, R Console sends a lightweight
`sess::notify_client("attach", ...)` refresh from the already-connected R
session so vscode-R can make that session active; VS Code custom
pseudoterminals do not provide a real terminal process id for vscode-R's
terminal-focus switcher.

The backend launch environment includes:

- `VSCODE_INIT_R`
- `VSCODE_WATCHER_DIR`
- `R_PROFILE_USER_OLD`
- `VSC_R_EXECUTABLE`

Depending on the selected session integration, it also includes:

- `SESS_PIPE`
- `VSCODE_WATCHER_DIR`
- `VSCODE_INIT_R`

At launch time, `rTerminal/runtime.ts` also sets:

- `R_PROFILE_USER` to this extension's `console-profile.R`
Expand All @@ -482,45 +518,54 @@ At launch time, `rTerminal/runtime.ts` also sets:

1. restores and sources the user's original profile through
`R_PROFILE_USER_OLD`
2. sources `VSCODE_INIT_R`
3. for R 4.6 compatibility, bridges vscode-R's legacy global `.First.sys`
deferred attach hook through `.First` when `VSCODE_INIT_R` installs it,
preserving user `.First()` startup logic before vscode-R attach
2. in `sess` mode, calls the installed `sess` package when it already exposes
the current `pipe_path` API
3. in `legacy` mode, runs vscode-R's legacy `init.R`
4. installs the console pager
5. locks the prompt options used by the embedded console contract

### 3.3 Session Watcher Metadata
### 3.3 Session Metadata

`SessionWatcher` reads files produced by `vscode-R` under
`VSCODE_WATCHER_DIR`.
In `legacy` mode, `SessionWatcher` reads the file-based `request.log`,
`workspace.lock`, and `workspace.json` files.

It watches:
In `sess` mode, session metadata flows through the proxy between R and vscode-R.
The R side sends JSON-RPC notifications such as `attach` and
`workspace_updated`; vscode-R sends JSON-RPC requests such as `workspace` and
`completion`. R Console may also inject `workspace` and `completion` requests
to the R-side socket and consumes the matching responses itself.

- root `request.lock`
- root `request.log`
- session `workspace.lock`
- session `workspace.json`
- the attached session directory until workspace state appears
Notifications consumed from R:

From `request.log`, it reads:
- `attach`
- `detach`
- `workspace_updated`

- attach/detach commands
- R session tempdir
- R session pid
- optional session server host/port/token
Requests sent to R:

From `workspace.json`, it reads:
- `workspace`
- `completion`

The `workspace` response provides:

- search path
- loaded namespaces
- global environment summary

The watcher can auto-pin to the first fresh attach event when the backend pid is
not known yet. Once pinned, it ignores attach events from other R sessions.
The `completion` response provides runtime `$` and `@` members for an
expression. Console data-frame bracket completion uses the same runtime
completion request with the data object expression, because vscode-R 3.0
workspace summaries do not carry column/member names.

For reconnect in `sess` mode, `R Console` writes the current `{ pipe }` to
`~/.vscode-R/sessions/{PID}.json`. The R-side bridge can read that file after
a window reload or terminal detach and reconnect to the replacement vscode-R IPC
server. The console still persists and restores its own Rust backend session;
the discovery file is only the metadata bridge.

### 3.4 Metadata Consumers

The console consumes watcher metadata for:
In `legacy` mode, the console consumes watcher metadata for:

- display pid selection
- search-path aware completion
Expand All @@ -529,8 +574,17 @@ The console consumes watcher metadata for:
available
- attached package and namespace sync into the console-owned language server

This integration is read-only with respect to `vscode-R` sessions. The console
does not create, replace, restore, or stop `vscode-R` sessions.
In `sess` mode, vscode-R owns the broader session metadata stream. `R Console`
owns only the console-side proxy and completion routing needed for the embedded
console. Runtime `$`, `@`, and data-frame bracket completion are requested from
the current embedded R session through the `sess` JSON-RPC `completion` method.
Workspace snapshots are cached from forwarded or console-injected `workspace`
responses and are used for search-path/package synchronization and top-level
workspace completions.

This integration is read-only with respect to broader `vscode-R` session
features. The console does not create, replace, restore, or stop vscode-R plot,
data, help, browser, httpgd, or addin sessions.

### 3.5 Completion And Language Server

Expand Down
2 changes: 1 addition & 1 deletion docs/MANUALTEST.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Run:

```{r startup-and-prompt}
sessionInfo()
Sys.getenv(c("R_HOME", "R_PROFILE_USER", "VSCODE_INIT_R", "VSC_R_SESSION_CWD"))
Sys.getenv(c("R_HOME", "R_PROFILE_USER", "SESS_PIPE", "VSC_R_SESSION_CWD"))
getOption("prompt")
getOption("continue")
getOption("menu.graphics")
Expand Down
Loading
Loading