Experimental ReScript Language Server in OCaml#8425
Draft
aspeddro wants to merge 11 commits into
Draft
Conversation
- Move Io, Chan, and listen infrastructure to server.ml - Simplify on_request to take a packed request directly - Add basic hover response with markdown content - Rename public executable to rescript-language-server
- Add `parse_implementation_from_source` to parsing/print engine types and all engine implementations, enabling parsing from a string source rather than a filename - Use `parse_implementation_from_source` in CompletionFrontEnd - Rename package from `rescript-lsp` to `rescript-language-server` - Refactor LSP server with typed state, document store, and diagnostics - Add hover support via completion backend integration
Move LSP modules under lsp/src/ with a thin lsp/bin/ entry point, add a configuration module, and introduce a tests/lsp_tests workspace exercising hover end-to-end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch introduces a standalone OCaml LSP server (
rescript-language-server) built on top of the existinganalysislibrary. It's a separate, OCaml-side exploration alongside the Rust/rewatch-based experiment in #8243 — the two share the same goal (a real LSP server for ReScript) but approach it from different ends of the toolchain.What's here
lsp/package split intolsp/bin(entrypoint) andlsp/src(library), with its own opam file (rescript-language-server.opam). Depends onlsp(>= 1.22.0),eio/eio_main, and the in-treeanalysislibrary.Parsing from source (not just files)
To make analysis work on unsaved editor buffers,
compiler/syntax/src/res_driver.{ml,mli}gains aparse_implementation_from_sourcevariant on bothparsing_engineandprint_engine, taking~source:stringinstead of~filename:string.CompletionFrontEnd.completionWithParser1is switched over to it so completion (and hover-via-completion) can run on the live document text.Tests
tests/lsp_tests/adds a dune-driven integration test (test.ml) that boots the server against a real ReScript workspace (basic-workspace/) and snapshots hover responses for a representativeHover.resfixture againstexpected/Hover.res.expected.Status / what's not here yet
Only
initialize,shutdown,textDocument/hover, and basicdidOpen/didCloseare implemented. the rest of the analysis endpoints (completion, signature help, definition, references, rename, document symbols, code lens, inlay hints, semantic tokens, code actions, formatting) aren't wired up yet. Diagnostics aren't published. There's no build integration —.cmt/.cmifiles are loaded from whateverrescript buildhas already produced.Relationship to #8243
#8243 collapses the build watcher and LSP into a single Rust process in rewatch, shelling out to
rescript-editor-analysis.exeover stdin. This PR keeps the LSP on the OCaml side and uses theanalysislibrary directly. Useful as a comparison point for the architecture discussion.