R Console is a VS Code extension that runs R inside a custom pseudoterminal. It combines a TypeScript console frontend, a Rust PTY sidecar that can re-exec itself into session-host mode, and a console-scoped language server client.
-
Terminal layer owns the pseudoterminal implementation, input buffer, cursor movement, multiline editing, history, rendering, prompt handling, and screen replay.
-
Language layer owns completion-context analysis, local parse heuristics, virtual documents, and the console-specific LSP bridge.
-
Runtime layer owns the PTY/session control protocol, bundled binary resolution, and the optional vscode-R session watcher bridge.
-
Rust sidecar
sidecar/pty-host/builds one binary:R_CONSOLE_PTY_HOSTowns the PTY/ConPTY and forwards stdout, stderr, resize, and control messages.- When
VSC_R_SESSION_HOSTis set,R_CONSOLE_PTY_HOSTre-execs itself in an internal session-host mode that embeds R, wires the console callbacks, and emits prompt, busy, input-request, and parse-status events back to the extension.
- Custom R console hosted in the VS Code terminal area.
- Multiline editing with local history navigation and reverse search.
- Auto-matching brackets and quotes.
- Bracketed paste handling.
- Parser-backed completeness checks before submission.
- Console-scoped completion, signature help, and semantic-token styling through
languageserver. - Session watcher integration with vscode-R for search-path data, global-environment data, and runtime
$/@member completion. - Screen replay when the terminal UI is recreated after a cancelled close or a reattach.
- Cross-platform PTY backend for macOS, Linux, and Windows.
- VS Code 1.85.0 or later.
- Node.js 24.x for the extension build and packaging scripts.
- R 4.5.x installed and configured through vscode-R settings. The current runtime rejects other R major/minor versions.
- vscode-R.
- The R package
languageserverif you want completion, signature help, and semantic highlighting. - Rust/Cargo only if you are building the sidecar binaries from source.
npm install
npm run compile
npm run build:sidecar
npm run stage:sidecarcompile type-checks the extension and bundles the extension host entrypoint into dist/extension.js.
stage:sidecar copies the current platform's R_CONSOLE_PTY_HOST into bundled/bin/.
npm run packageThis produces a target-specific VSIX for the current host platform, for example vscode-r-console-0.1.0-win32-x64.vsix.
vscode:prepublish still prepares the production bundle and stages the current platform binary into bundled/bin/.
The GitHub release workflow packages and publishes four target-specific builds: win32-x64, linux-x64, darwin-x64, and darwin-arm64.
R Console reads several settings from vscode-R:
| Setting | Purpose |
|---|---|
r.rterm.windows |
R executable path on Windows |
r.rterm.mac |
R executable path on macOS |
r.rterm.linux |
R executable path on Linux |
r.rterm.option |
Extra arguments passed to R |
r.sessionWatcher |
Enables the vscode-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 |
R Console also contributes its own settings:
| Setting | Default | Purpose |
|---|---|---|
r.console.autoMatch |
true |
Auto-insert matching brackets and quotes |
r.console.tabSize |
2 |
Indentation width |
src/Terminal/contains the console editor, renderer, history manager, terminal-state replay, options, and the mainRTerminalimplementation.src/Language/contains completion logic, the console LSP client, parse heuristics, and the virtual in-memory R document.src/Runtime/contains the backend control protocol, bundled Rust binary resolution, and the session watcher integration.sidecar/pty-host/contains the Rust PTY host and the internal session-host module.
R Console is built on the broader VS Code, Rust, and R tooling ecosystems, and on the work of several open-source projects that shaped the extension. In particular, the following projects informed the current design and implementation:
- vscode-R provides the settings surface this extension reads, the session bootstrap scripts (
R/session/profile.RandR/session/init.R) that the console integrates with, and the watcher/request model that informedSessionWatcher. - arf is the closest reference for the current Rust-side console host implementation. The
sidecar/pty-host/src/session_host/code follows the same Rustlibloadingapproach to loadinglibR, platform-specific callback wiring, Windows support-DLL preloading (Rblas.dll,Riconv.dll,Rlapack.dll,Rgraphapp.dll),R_SetParams/getRUser/GA_initappsetup on Windows, and Unix callback/event integration. - rchitect informed the embedded-R callback model behind the internal session host: the
Rstart/ptr_R_*callback surface,R_ToplevelExec-guarded parse/eval flow, and the Unix event-pump pattern aroundR_PolledEvents,R_checkActivity, andR_runHandlers. - radian informed the multiline editing behaviour, history compatibility, and several input heuristics.
HistoryManagerreads and writes radian-style history entries, andInputStatefollows radian-inspired bracket and newline behaviour. @xterm/headlessmaintains the off-screen terminal buffer that lets the extension replay a styled screen when the UI is reattached.vscode-languageclientpowers the console-scoped LSP client used with the Rlanguageserverpackage.portable-ptyprovides the cross-platform PTY/ConPTY layer used byR_CONSOLE_PTY_HOST.libloadingmakes it possible for the internal session-host mode inR_CONSOLE_PTY_HOSTto dynamically load the R shared library and bind the embedded-console callbacks.- Built on the VS Code Extension API.
This extension's source code was written with assistance from Codex (GPT-5.3-Codex and GPT-5.4). The overall feature design and logic decisions are mine; GPT models were used to generate and iterate on the implementation.
MIT