Repository navigation
Add an embedded language server for open R documents - #905
renkun-ken wants to merge 8 commits into
Conversation
eitsupi
left a comment
There was a problem hiding this comment.
Review by ChatGPT:
-
"R/embedded.R": Go to Definition on string literals. "embedded_definition()" passes "rootPath = """ to "definition_reply()", which can call "with_wd(rootPath, ...)" when resolving a string literal as a file path. This results in a "setwd("")" error. Please disable filesystem-based definition lookup in embedded mode rather than passing an invalid working directory.
-
Partial rename across open documents. Renaming a global binding can silently leave references in closed files unchanged, potentially breaking the project. Given the existing safeguards against incomplete rename operations, please consider restricting such renames or explicitly notifying users of their limited scope. Implementing closed-file indexing is not required for this PR.
-
Missing "prepareRename" capability. The embedded server implements "textDocument/prepareRename" but advertises only "renameProvider = TRUE". Please advertise "prepareProvider = TRUE" when the client supports it, consistent with the existing capability negotiation in "R/capabilities.R".
-
Workspace folder changes. Workspace folders are captured during initialization but subsequent additions and removals are not handled. This can leave document isolation inconsistent with the current workspace configuration. Please either handle these changes or document that the host must restart the embedded server when workspace folders change.
-
Configuration support. Most existing language server settings are not synchronized in embedded mode, and formatting is hardcoded to styler. Please document which settings are supported and which are ignored. Full configuration parity is not required for this PR.
|
Thanks for the review. The five findings are addressed in 9eb1f28.
|
9eb1f28 to
71e71b3
Compare
eitsupi
left a comment
There was a problem hiding this comment.
Review by ChatGPT:
The previous review findings have been addressed. The embedded language server is within the scope of the languageserver package, and there are precedents for this approach, notably Postgres Language Server and Tombi, which provide APIs for embedding language servers in browser environments.
Keeping run_embedded() in languageserver rather than implementing it in vscode-R or a separate R package is appropriate, given its reliance on internal language providers and data structures. The API itself is independent of webR and VS Code, making it potentially useful to other hosts.
One longer-term concern is the duplication of LSP dispatch, lifecycle management, capability negotiation, document synchronization, and configuration handling between the native and embedded servers. I suggest gradually extracting a shared, transport-independent language server core, with differences in execution environments, task scheduling, and filesystem access handled separately. This would reduce the risk of behavioral divergence and the maintenance burden when introducing new language features.
Also, since run_embedded() constructs and returns a stateful dispatcher rather than running a message loop, a name such as create_embedded_server() might describe its semantics more accurately.
Neither suggestion needs to block this PR. The current implementation is a reasonable starting point, and a larger refactoring can be considered separately.
renkun-ken
left a comment
There was a problem hiding this comment.
I would fix the two rename cases before merging. A rename in one notebook can propose edits in a different workspace folder, and a rename in an untitled buffer can target the generated read-only source of stats::lm. The inline comments include reproductions for both, plus the completion, diagnostics, formatting, and document-lifetime issues.
All 81 assertions in test-embedded.R passed on native R 4.6.1, and all 16 GitHub checks passed on 71e71b3. I also exercised the dispatcher in webR 0.6.1 / R 4.6.0 using the PR’s R modules over the published Wasm package. I verified parse-snapshot retention separately with a native R finalizer.
|
Addressed all eight findings from the review in
I replayed the review cases on native R 4.6.1 and on webR 0.6.1 with R 4.6.0, using the published Wasm package and the pinned R modules. In VS Code for the Web, two real Jupyter notebooks in different folders verified both directions of Go to Definition and the exact reference and rename targets. The session-aware follow-up #907 and the vscode-R integration now consume the fixes. The full native package check on this revision passed 24,499 assertions, with two optional |
Summary
Add
run_embedded()for editors hosting R in a dedicated worker. The host supplies complete JSON-RPC messages and forwards the returned replies. Buffer text and versioned edits stay in memory. The server reuses the package's parsers and language providers and can run without native R subprocesses or a mounted project tree.This covers completion, hover, signatures, definitions, references, rename, Outline, folding and semantic tokens for open documents. Pull diagnostics report syntax errors and optionally spacing diagnostics with lintr. Full-document formatting is available when styler is installed.
Stacked on #903. The integration is tracked in vscode-R #2003.
Verification