package ocaml-lsp-server

  1. Overview
  2. Docs
LSP Server for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

ocaml-lsp-server-1.1.0.tbz
sha256=fa0ca1d3c5c3377f798c221381228a65e8f49fece42715d279ebe91f2f4f74c8
sha512=c00ad47478a4ddfebe3798895700d2bececa29a610c7757619f47a5b90ede921afa56efc776df3a1c4a8b2f082898423a5806d00c041dae137da1b57ee487a9b

Description

An LSP server for OCaml.

Published: 15 Oct 2020

README

OCaml-LSP

This project contains an implementation of an LSP server for OCaml and a standalone implementation of the LSP protocol.

Installation

We recommend to install the server via a project such as opam or esy.

Opam

To install the lsp server in a particular opam switch:

$ opam pin add ocaml-lsp-server https://github.com/ocaml/ocaml-lsp.git
$ opam install ocaml-lsp-server

Note that you will need to run install the lsp server in every switch where you'd like to use it.

Esy

To add the lsp server to an esy project, add the following lines to your project's package.json:

  "devDependencies": {
    "@opam/ocaml-lsp-server": "ocaml/ocaml-lsp:ocaml-lsp-server.opam"
  }

Source

This project uses submodules to handle dependencies. This is done so that users who install ocaml-lsp-server into their sandbox will not share constraints on the same dependencies that ocaml-lsp-server is using.

$ git clone --recurse-submodules http://github.com/ocaml/ocaml-lsp.git
$ cd ocaml-lsp
$ make build

Usage

Once ocaml-lsp-server is installed, the executable is called ocamllsp. For now, the server can only be used through the standard file descriptors stdin and stdout.

For an example of usage of the server in a VSCode extension, see here.

Features

The server supports the following queries:

  • [x] textDocument/completion

  • [x] completionItem/resolve

  • [x] textdocument/hover

  • [ ] textDocument/signatureHelp

  • [ ] textDocument/declaration

  • [x] textDocument/definition

  • [x] textDocument/typeDefinition

  • [ ] textDocument/implementation

  • [x] textDocument/codeLens

  • [x] textDocument/documentHighlight

  • [x] textDocument/documentSymbol

  • [x] textDocument/references

  • [ ] textDocument/documentColor

  • [ ] textDocument/colorPresentation

  • [x] textDocument/formatting

  • [ ] textDocument/rangeFormatting

  • [ ] textDocument/onTypeFormatting

  • [x] textDocument/prepareRename

  • [x] textDocument/foldingRange

  • [x] textDocument/selectionRange

  • [ ] workspace/symbol

Note that degrees of support for each LSP request are varying.

Contribution

# 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.09.1 --with-test

# don't forget to set your environment to use the local switch
eval ($opam env)

# build
make build

# install ocamllsp
make lsp-server

Tests

To run tests execute:

$ make test

Note that tests require Node.js and Yarn installed.

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 infeasible to upgrade the lsp server and merlin independently.

History

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.

Comparison to other LSP Servers for OCaml

Note that the comparisons below make no claims of being objective and may be entirely out of date:

  • reason-language-server This server supports bucklescript & reason. However, this project does not use merlin which means that it supports less versions of OCaml and offers less "smart" functionality - especially in the face of sources that do not yet compile.

  • ocaml-language-server 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.