Syaiful Bahri

OCaml.nvim

Lua

OCaml.nvim is a Neovim plugin I started developing because I wanted a better experience when working with OCaml projects.

OCaml tools like ocaml-lsp-server, ocamlformat, and dune are often managed by a sandbox, such as Opam or Esy. Project dependencies and tool versions are managed within these sandboxes to ensure consistency and isolation. This is usually great for development, but it poses challenges for editor integration.

I always found myself manually sourcing the sandbox environment before launching Neovim to ensure the tools were available. This process is tedious and error-prone, especially when switching between projects with different sandboxes.

In VS Code, the OCaml Platform extension handles this automatically by detecting the sandbox and launching the language server within it, allowing users to easily select the correct sandbox when opening a project.

This is what OCaml.nvim aims to achieve for Neovim users. It automatically detects the sandbox type (Opam or Esy) when opening an OCaml project and configures the language server and other tools to run within that sandbox.

If it can’t find a sandbox, it falls back to the global environment, which is often the case for Nix users.

Over time, I’ve added more features to the plugin, including useful commands for interacting with OCaml LSP and Merlin, as well as filetype support for ReasonML, Menhir, and MLX.

For example, you can summon odoc documentation directly from the editor without hovering over the symbol:

You can also select the AST node enclosing the cursor position:

Check out the GitHub repository for more information. Feel free to open issues or contribute!