Building rescript lsp to run in webworker

I’m interested in getting the rescript lsp to run in the browser in a webworker. (Previously did this with another toy LSP that was written in Rust).

I figure, if the Rescript compiler can run in the browser; how much worse can the LSP be.

Can anyone point me at directions on how the current rescript LSP is built? Google results is constantly pointing me at the vscode extension.

The rescript-vscode repository contains the LSP. It consists of a binary (known as the analysis binary) written in OCaml and a bit of TypeScript glue code.

One would need to use js_of_ocaml to create a JS bundle, similar to the playground and then somehow cobble it together with the TS part. Depending on your goals, you could also just use the analysis binary directly, as it has a very simple interface. However, having a real LSP is probably much more useful. It could enable us having an extension version for web editors.

Personally, I would love to have the analysis binary working in the playground itself, so you can explore the standard library easily thanks to autocompletion.

  1. Thank you for your detailed + informative response.

  2. I’m largely motivated by Try Eio and want to see if we can get the same with ReScript (which tends to compile faster than jsoo in my experience). Do we have the same goal in mind ?

Try-Eio also does not use any LSP from what I can see. It utilizes merlin-js instead. So the equivalent would be to use just the analysis binary compiled to JS via JSOO, I think.

Yes, I think you also just want the playground (or something like it) to support autocomplete and possibly other features.

Maybe you can start from there: rescript-compiler/ at master · rescript-lang/rescript-compiler · GitHub

Note: As of now there is no Code evaluation in the ReScript playground, but there are two open PRs where this was attempted:

Good call, to the best of my knowledge, it s using merlin-js, not any LSP. I got the two confused up.

On the editor side, do you have any advice on Monaco vs CodeMirror or something else? Approaches I’ve played with in the past:

Monaco: only played with JS/TS support, and it was toggling some switch, not actual code I wrote

CodeMirror: I got some codemirror lsp package (forgot which one) to rip out websockets and use postMessage to webworkers “work”, but it was very slow for completions

Vim / Others: could not get it to build directly on wasm, despite demos like GitHub - rhysd/vim.wasm: Vim editor ported to WebAssembly

If you have strategies for in-browser LSP/editor support, I’m curious to hear them as well.

I did not practically tinker with it, but I’d still suggest to use CodeMirror, as it is also used by the ReScript playground. Have a look at’s assessment of it: Replit - Betting on CodeMirror

I don’t know from where the slowness comes, but the asynchronous nature of LSP could be the culprit. This may be another benefit of hooking up the analysis binary directly.