OCaml-LSP is a language server for OCaml that implements Language Server
To install the language server in the currently used opam switch:
$ opam install ocaml-lsp-server
Note: you will need to install
ocaml-lsp-server in every switch where you would like
to use it.
To add the language server to an esy project, run in terminal:
$ esy add @opam/ocaml-lsp-server
This project uses submodules to handle dependencies. This is done so that users
ocaml-lsp-server into their sandbox will not share dependency
constraints on the same packages that
ocaml-lsp-server is using.
$ git clone --recurse-submodules http://github.com/ocaml/ocaml-lsp.git $ cd ocaml-lsp $ make install
ocaml-lsp-server is installed, the executable is called
now, the server can only be used through the standard input (
stdout) file descriptors.
For an example of usage of the server in a VS Code extension, see OCaml
Platform Extension implementation
The server supports the following LSP requests:
Note that degrees of support for each LSP request are varying.
Integration with other tools
Source file formatting: OCamlFormat & Refmt
OCaml-LSP is dependent on external tools (OCamlFormat for OCaml and
Reason) for formatting source files. You should have the necessary tool
(OCamlFormat and/or Refmt) installed in your opam switch or esy project to have
formatting support. Note, however, that OCaml-LSP requires presence of
OCamlFormat configuration file, called
.ocamlformat, in the project root to
be able to format source files in your project.
Formatting code on hover
When you hover the cursor over OCaml code, the extension shows you the type of
the symbol. To get nicely formatted types, install
If you use Visual Studio Code, please see OCaml Platform extension
page for a detailed guide
on how to report and debug problems.
If you use another code editor and use OCaml-LSP, you should be able to set the
server trace to
verbose using your editor's LSP client and watch the trace
for errors such as logged exceptions.
Contributing to project
# clone repo with submodules git clone --recursive email@example.com:ocaml/ocaml-lsp.git # if you already cloned, pull submodules git submodule update --init --recursive # create local switch (or use global one) opam switch create . ocaml-base-compiler.4.14.0 # don't forget to set your environment to use the local switch eval $(opam env) # install dependencies make install-test-deps # build make all # the ocamllsp executable can be found at _build/default/ocaml-lsp-server/bin/main.exe
To run tests execute:
$ make test
Relationship to Other Tools
The lsp server uses merlin under the hood, but users are not required to have
merlin installed. We vendor merlin because we currently heavily depend on some
implementation details of merlin that make it infeasible to upgrade the lsp
server and merlin independently.
The implementation of the lsp protocol itself was taken from
Previously, this lsp server was a part of merlin, until it was realized that
the lsp protocol covers a wider scope than merlin.
Comparison to other LSP Servers for OCaml
Note that the comparisons below makes no claims of being objective and may be
entirely out of date:
This server supports
reason. However, this project does not
use merlin which means that it supports fewer versions of OCaml and offers less
"smart" functionality - especially in the face of sources that do not yet
This project is extremely similar in the functionality it provides because it
also reuses merlin on the backend. The essential difference is that this
project is written in typescript, while our server is in OCaml. We feel that
it's best to use OCaml to maximize the contributor pool.
Andrey Popp <firstname.lastname@example.org>
Rusty Key <email@example.com>
Louis Roché <firstname.lastname@example.org>
Oleksiy Golovko <email@example.com>
Rudi Grinberg <firstname.lastname@example.org>
Sacha Ayoun <email@example.com>
Ulugbek Abdullaev <firstname.lastname@example.org>
Max Lantas <email@example.com>