Warning
This plugin is in early development and may not work as expected. Breaking changes may occur without notice.
A comprehensive Neovim plugin for OCaml development with intelligent sandbox detection, LSP integration, and comprehensive filetype support.
- 🎯 Smart LSP Integration: Automatic detection and setup of
ocamllsp
with sandbox support - 📦 Sandbox Detection: Supports esy projects with automatic command resolution
- 🎨 Multiple Filetypes: Support for OCaml, Reason, and various OCaml file formats
- 🔧 Automatic Formatting: Integration with
ocamlformat
andocamlformat-mlx
via conform.nvim - 🌳 TreeSitter Integration: Enhanced syntax highlighting and code understanding
- ⚡ Performance: Efficient client reuse and project detection
Extension | Language | Description |
---|---|---|
.ml |
ocaml |
OCaml implementation files |
.mli |
ocaml.interface |
OCaml interface files |
.mll |
ocaml.ocamllex |
OCaml lexer files |
.mly |
ocaml.menhir |
Menhir parser files |
.mlx |
ocaml.mlx |
OCaml JSX files |
.t |
ocaml.cram |
Cram test files |
.re |
reason |
Reason implementation files |
.rei |
reason |
Reason interface files |
- Neovim 0.11+
ocamllsp
language server installed- TreeSitter OCaml parsers
lazy.nvim (Recommended)
{
"ocaml/ocaml.nvim",
dependencies = {
"nvim-treesitter/nvim-treesitter",
},
}
use {
"ocaml/ocaml.nvim",
requires = { "nvim-treesitter/nvim-treesitter" },
}
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'ocaml/ocaml.nvim'
This plugin manages the OCaml LSP server automatically. If you're using
nvim-lspconfig, you MUST
disable the ocamllsp
server to avoid conflicts:
-- ❌ DO NOT enable ocamllsp in lspconfig when using this plugin
require("lspconfig").ocamllsp.setup({
autostart = false, -- Set this to false!
})
-- ✅ OR better yet, don't configure it at all in lspconfig
This plugin provides intelligent sandbox detection (esy, opam, global) and will automatically start the appropriate LSP server with the correct configuration.
The plugin works out of the box with sensible defaults. For advanced configuration:
---@type ocaml.Opts
vim.g.ocamlnvim = {
lsp = {
-- Enable/disable automatic LSP attachment
auto_attach = true,
-- Custom on_attach function
on_attach = function(client_id, bufnr)
-- Set up keymaps, autocommands, etc.
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = bufnr })
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
-- ... more LSP keymaps
end,
},
}
The plugin automatically detects your project type and starts the appropriate LSP server:
- Esy Projects: Detects
esy.json
orpackage.json
withesy
field → usesesy -P ocamllsp
- Opam Projects: Detects
*.opam
files → uses local opam sandbox if present, otherwise falls back to globalocamllsp
- Dune Projects: Detects
dune-project
/dune-workspace
→ usesocamllsp
- Global: Falls back to global
ocamllsp
All plugin commands are available as subcommands under :OCaml
:
:OCaml lsp start " Start LSP server
:OCaml lsp stop " Stop LSP server
:OCaml lsp restart " Restart LSP server
:OCaml ts install_reason " Install Reason TreeSitter parser
:OCaml ts install_mlx " Install MLX TreeSitter parser
The plugin automatically configures formatters for conform.nvim:
- OCaml files →
ocamlformat
- MLX files →
ocamlformat-mlx
The plugin searches for these files to determine project root and type:
📁 Project Root Detection (in order of precedence):
├── dune-project # Dune project
├── dune-workspace # Dune workspace
├── package.json # Esy project (with esy field)
├── esy.json # Esy project
├── *.opam # Opam package
├── _build/ # Build directory
└── .git/ # Git repository
# Run all tests
busted
# Run with coverage
busted --coverage
# Lint code
luacheck .
# Format code
stylua .
# Enter development shell
nix develop
# Run all checks
nix flake check
# Build plugin
nix build
This plugin is in early development. Contributions are welcome!
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Run tests:
busted
- Submit a pull request
MIT License - see LICENSE for details.
- Inspired by haskell-tools.nvim LSP architecture
- Built for the OCaml community with ❤️