docs/03-special-guides/ocaml_setup_guide_for_serena.md
This guide explains how to set up an OCaml project so that Serena can provide code intelligence via ocaml-lsp-server (ocamllsp).
Unlike some other languages, Serena does not download the OCaml language server automatically. You must install it yourself via opam, as OCaml tooling is compiled from source against your specific environment.
Install the following on your system and ensure they are available on PATH:
brew install opamsudo apt install opamsudo dnf install opamInitialize opam if you haven't already:
opam init
eval $(opam env)
Create an opam switch with a compatible OCaml version:
# For cross-file reference support (recommended)
opam switch create serena-ocaml ocaml-base-compiler.5.2.1
eval $(opam env)
# Or for stable OCaml 4.14.x
opam switch create serena-ocaml ocaml-base-compiler.4.14.2
eval $(opam env)
Install the language server and build tools:
opam install ocaml-lsp-server dune
Verify the installation:
opam exec -- ocamllsp --version
opam exec -- ocaml -version
Cross-file reference support (finding all usages of a symbol across your project) requires:
When these requirements are met, Serena automatically builds the cross-file index during startup via dune build @ocaml-index. Without these versions, references are limited to the current file.
*.ml, *.mli) and Reason files (*.re, *.rei).opam exec -- ocamllsp, so your opam environment must be configured.dune build before using Serena for best results.| Problem | Solution |
|---|---|
| "opam not found" | Install opam and add it to PATH |
| "OCaml 5.1.0 is incompatible" | Create a new switch: opam switch create <name> ocaml-base-compiler.5.2.1 |
| "ocaml-lsp-server not found" | opam install ocaml-lsp-server |
| Cross-file refs not working | Ensure OCaml >= 5.2 and ocaml-lsp-server >= 1.23.0; run dune build first |
| Stale index | Rebuild with dune build @ocaml-index |