Dromedary for OCaml

Setup

Dromedary runs the OCaml tools of your opam switch. You need opam, a switch, and two packages in it: ocaml-lsp-server and ocamlformat.

1. Install opam

Use your system’s package manager, or opam’s own installer. These are the commands from opam’s install page, which lists more systems:

Debian, Ubuntuapt install opam
Fedoradnf install opam
Arch Linuxpacman -S opam
macOS (Homebrew)brew install opam

Or the installer, which downloads opam’s pre-built binary and runs opam init for you:

bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"

After a package manager, set opam up once. This also creates opam’s first switch, with an OCaml compiler:

opam init

2. Choose the switch

A switch is one OCaml compiler with its own packages. Dromedary uses:

  1. the project’s local switch, the _opam folder at the root of the project, when there is one;
  2. otherwise opam’s current switch, the one opam switch show names.

To use another, set the path to ocamllsp on Dromedary’s settings page in the IDE.

A local switch, for one project

From the project’s folder, create the switch and install the project’s dependencies from its .opam files:

cd my-project
opam switch create . ocaml-base-compiler
opam install . --deps-only

opam selects a local switch by itself when you run it inside that folder.

A shared switch, for several projects

List the switches, and pick the one your projects use:

opam switch list
opam switch <name>

3. Install the tools in the switch

With the switch selected (inside the project folder for a local switch):

opam install ocaml-lsp-server ocamlformat

If they are missing when you open an OCaml file, Dromedary shows this command and can run it in the IDE’s terminal when you click its button.

Formatting follows the project’s .ocamlformat file, if it has one. To start one at the project’s root:

echo "profile = default" > .ocamlformat

4. Open the project

Open the project’s folder in your IDE. Dromedary starts ocamllsp when you open an OCaml file.

ocamllsp knows the rest of your project as it was at your last build. Its developers recommend keeping dune running in watch mode in a terminal:

dune build --watch

Help

Something does not work? Write to agent@osidius.com with your IDE and its version, your system, and what opam switch show and opam list ocaml-lsp-server ocamlformat print. We answer within 2 business days for an urgent problem, and within 5 business days otherwise.