Skip to content

Provide R language features through webR when native R is unavailable - #2004

Open
renkun-ken wants to merge 6 commits into
mainfrom
codex/webr-runtime
Open

renkun-ken wants to merge 6 commits into
mainfrom
codex/webr-runtime

Conversation

@renkun-ken

Copy link
Copy Markdown
Member

Summary

When r.lsp.enabled is on and the extension cannot resolve native R, open R documents receive language features from a dedicated webR worker. r.lsp.runtime can also select native R or webR explicitly. Native sessions continue to use their configured R installation.

The worker supplies completion, hover, signatures, cross-document navigation and rename for open buffers, Outline, semantic tokens, document formatting, syntax diagnostics and an in-process lint rule. The first use downloads a pinned runtime, package library and embedded server modules. Subsequent sessions reuse verified cached assets. No project text is sent to the package servers.

This is the base of the vscode-R stack for #2003. It uses the public Wasm binary with the matching embedded server sources pinned from languageserver #905, which builds on #903.

Verification

  • Exercised ordinary extension activation with an unavailable R executable in an isolated desktop VS Code profile. Go to Definition crossed two unsaved documents, and Outline reflected an incremental edit.
  • Verified all 36 remote asset checksums, real Wasm provider responses, cache repair and concurrent installation, cancellation of queued requests, typechecking, formatting and lint.
  • The opt-in editor test is documented in CONTRIBUTING.md. Open-buffer analysis has its own workspace scope. Closed-file indexing and native project libraries remain available through native R.

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

  1. "src/webr/nodeRuntime.ts": The cache signature only includes file paths and sizes, so same-size file corruption goes undetected. Subsequent startup attempts would reuse the corrupted runtime. Please validate the cached file contents or provide a cache invalidation and recovery mechanism when runtime initialization fails, with a regression test.

  2. "src/languageService.ts": "startWithRetry()" handles initial startup failures, but "CloseAction.DoNotRestart" leaves no recovery path after an initialized webR worker fails. Please provide a retry mechanism without requiring a window reload, similar to the browser implementation in #2006.

  3. "r.lsp.runtime" has resource scope, but with "r.lsp.multiServer = false" (the default), the shared language server uses the first workspace folder's runtime preference. Please document this limitation or reconsider the configuration scope.

  4. Loading R source files from an unmerged languageserver commit introduces availability and compatibility risks. Please replace this temporary mechanism with a published Wasm build providing "run_embedded()" before releasing the feature. This does not need to block merging this PR.

@renkun-ken

Copy link
Copy Markdown
Member Author

Thanks for the review. Commit 03dfb3a addresses the cache, retry and configuration findings.

  1. Cache validation now hashes the contents of the runtime binaries and lazy filesystem assets. A regression flips a byte in R.wasm without changing its size and verifies that the installer publishes a fresh generation. Existing sessions can keep their original generation.
  2. An initialized desktop webR language client now offers Retry if its worker disconnects. A real VS Code test closed the JSON-RPC connection after initialization, restarted the worker through Retry, and received a response without a window reload. It also checks that a late Retry cannot resurrect a disposed client.
  3. The language-service guide documents how the default single source client takes its runtime preference from the first workspace folder. Multi-server mode is available for per-folder source runtimes. Session-owned notebooks have their own runtime selection in Make Interactive notebooks follow their session’s language runtime #2007.
  4. The loader now prefers the embedded entry point exported by a published package when available. The current published Wasm build (0.3.22, b4f2dff) still lacks that export. The contributor guide records the release prerequisite: pin and test the published Wasm build that includes the embedded API, then remove the interim source overlay. That artifact change remains outstanding before release.

Typechecking, bundling, formatting and lint passed, along with the focused cache tests and all 17 desktop initialization, cancellation and retry tests.

@renkun-ken

Copy link
Copy Markdown
Member Author

An uncached browser run reproduced the availability concern in the review. After R-universe published the build containing the fix for languageserver #902, the previous Wasm archive started returning HTTP 404. Existing caches had masked the failure.

f0b52b9 includes the official R-universe Wasm archive built from beef692 in the VSIX. Both extension hosts read its bytes from the installed extension and verify the pinned SHA-256. The new binary includes the symbol fix, so the previous package load-order workaround has been removed.

The combined browser workbench suite passed from a fresh profile, including open-document navigation, changing diagnostics without reloading, installing and completing packages, viewers, and editing session files. The remaining release prerequisite is a published languageserver Wasm build exporting the session-aware run_embedded() API. Once published, that build can replace the bundled archive and the development R source overlay can be removed. Upstream review response

@renkun-ken
renkun-ken requested a review from eitsupi November 29, 2026 00:45

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