Skip to content

Experimental ReScript Language Server in OCaml#8425

Draft
aspeddro wants to merge 11 commits into
rescript-lang:masterfrom
aspeddro:lsp
Draft

Experimental ReScript Language Server in OCaml#8425
aspeddro wants to merge 11 commits into
rescript-lang:masterfrom
aspeddro:lsp

Conversation

@aspeddro
Copy link
Copy Markdown
Contributor

@aspeddro aspeddro commented May 14, 2026

Very experimental, WIP!!

This branch introduces a standalone OCaml LSP server (rescript-language-server) built on top of the existing analysis library. 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

  • New lsp/ package split into lsp/bin (entrypoint) and lsp/src (library), with its own opam file (rescript-language-server.opam). Depends on lsp (>= 1.22.0), eio/eio_main, and the in-tree analysis library.

Parsing from source (not just files)

To make analysis work on unsaved editor buffers, compiler/syntax/src/res_driver.{ml,mli} gains a parse_implementation_from_source variant on both parsing_engine and print_engine, taking ~source:string instead of ~filename:string. CompletionFrontEnd.completionWithParser1 is 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 representative Hover.res fixture against expected/Hover.res.expected.

Status / what's not here yet

Only initialize, shutdown, textDocument/hover, and basic didOpen/didClose are 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/.cmi files are loaded from whatever rescript build has 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.exe over stdin. This PR keeps the LSP on the OCaml side and uses the analysis library directly. Useful as a comparison point for the architecture discussion.

- 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.
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.

1 participant