package ocaml-lsp-server
Install
Dune Dependency
Authors
-
AAndrey Popp <8mayday@gmail.com>
-
RRusty Key <iam@stfoo.ru>
-
LLouis Roché <louis@louisroche.net>
-
OOleksiy Golovko <alexei.golovko@gmail.com>
-
RRudi Grinberg <me@rgrinberg.com>
-
SSacha Ayoun <sachaayoun@gmail.com>
-
Ccannorin <cannorin@gmail.com>
-
UUlugbek Abdullaev <ulugbekna@gmail.com>
-
Thibaut Mattio
-
MMax Lantas <mnxndev@outlook.com>
Maintainers
Sources
sha256=919b98027cbc56359dabe8a911d3d24d1706cea8cd04e8173a2d1d3b06f9d846
sha512=68898112f13b7ee13040933ed95597e59f83e42ac9d6ead375baa2d1248b1614b5b80ae5e0d839f7f5a8372fd1f47e6bf308d331ca1df90cb4b9927825f89635
Description
An LSP server for OCaml.
Published: 16 Jul 2022
README
OCaml-LSP
OCaml-LSP is a language server for OCaml that implements Language Server Protocol (LSP).
Installation
We recommend to install the language server via a package manager such as opam or esy.
Opam
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.
Esy
To add the language server to an esy project, run in terminal:
$ esy add @opam/ocaml-lsp-server
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 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
Usage
Once 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.
Features
The server supports the following LSP requests:
[x]
textDocument/completion
[x]
completionItem/resolve
[x]
textdocument/hover
[ ]
textDocument/signatureHelp
[x]
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
[x]
workspace/symbol
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 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.
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 ocamlformat-rpc package.
Debugging
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 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)
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
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 it 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 makes 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 fewer 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.
Dependencies (20)
-
ocaml
>= "4.14" & < "4.15"
-
ocamlformat-rpc-lib
>= "0.21.0"
-
csexp
>= "1.5"
-
pp
>= "1.1.2"
-
uutf
>= "1.0.2"
-
octavius
>= "1.2.2"
-
omd
>= "1.3.2" & < "2.0.0~alpha1"
- spawn
- dune-build-info
- ordering
- xdg
-
fiber
>= "3.1.1"
- stdune
- dyn
-
chrome-trace
>= "3.3.0"
- dune-rpc
-
ppx_yojson_conv_lib
>= "v0.14"
-
re
>= "1.5.0"
- yojson
-
dune
>= "3.0"
Dev Dependencies (1)
-
odoc
with-doc
Used by (27)
- ambient-context
- coap
- coap-core
- coap-server-lwt
- html_of_jsx
- jsonschema2atd
- melange-fest
- melange-jest
-
melange-json
>= "1.1.0"
- melange-numeral
-
melange-radix-icons
>= "0.1.0"
-
melange-recharts
< "4.0.3"
- melange-webapi
-
mqtt
>= "0.2.2"
-
opentelemetry
>= "0.6"
- pancake
- ppx_deriving_jsonschema
- quickjs
- reason-react
- red-black-tree
- reshowcase
- server-reason-react
- signal
-
spectrum
< "0.2.0"
- sqids
- styled-ppx
- universal-portal
Conflicts
None