Page
Library
Module
Module type
Parameter
Class
Class type
Source
OCaml-LSP is a language server for OCaml that implements Language Server Protocol (LSP).
This project contains an implementation of a language server for OCaml and a standalone library implementing LSP.
We recommend to install the language server via a package manager such as opam or esy.
To install the language server in the currently used opam switch:
$ opam install ocaml-lsp-serverNote: 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-serverThis project uses submodules to handle dependencies. This is done so that users who install 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 allOnce ocaml-lsp-server is installed, the executable is called ocamllsp. For now, the server can only be used through the standard input (stdin) and output (stdout) file descriptors.
For an example of usage of the server in a VS Code extension, see OCaml Platform Extension implementation here.
The server supports the following LSP requests:
textDocument/completioncompletionItem/resolvetextdocument/hovertextDocument/signatureHelptextDocument/declarationtextDocument/definitiontextDocument/typeDefinitiontextDocument/implementationtextDocument/codeLenstextDocument/documentHighlighttextDocument/documentSymboltextDocument/referencestextDocument/documentColortextDocument/colorPresentationtextDocument/formattingtextDocument/rangeFormattingtextDocument/onTypeFormattingtextDocument/prepareRenametextDocument/foldingRangetextDocument/selectionRangeworkspace/symbolNote that degrees of support for each LSP request are varying.
OCaml-LSP is dependent on external tools (OCamlFormat for OCaml and refmt for 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.
# clone repo with submodules
git clone --recursive git@github.com:ocaml/ocaml-lsp.git
# if you already cloned, pull submodules
git submodule update --init --recursive
# create local switch (or use global one) and install dependencies
opam switch create . ocaml-base-compiler.4.12.0 --with-test
# don't forget to set your environment to use the local switch
eval ($opam env)
# build
make all
# the ocamllsp executable can be found at _build/default/ocaml-lsp-server/src/main.exeTo run tests execute:
$ make testNote that tests require Node.js and [Yarn][https://yarnpkg.com/lang/en/] installed.
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 infeasible to upgrade the lsp server and merlin independently.
The implementation of the lsp protocol itself was taken from facebook's hack
Previously, this lsp server was a part of merlin, until it was realized that the lsp protocol covers a wider scope than merlin.
Note that the comparisons below make no claims of being objective and may be entirely out of date: