package menhirformat
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=c860cd3fe92e15a9a205bc44bb0656cc
sha512=c58ba5d6ec279884560447e4866e7d7765f0983cfc4e8589ff20aa695b6931fd9279a2019080963c240f63fdd2232d6ab9adee8cffae2af512262492cb411c05
Description
A formatter for Menhir and ocamllex code. It takes care of indentation and whitespace in your lexer and parser rules and it calls ocamlformat to format the OCaml code of their semantic actions.
README
Menhir LSP
menhir-lsp is a Language Server for the OCaml dialects Menhir and Ocamllex. Its goal is to provide first-class language support for their syntaxes in client editors. A client for VS Code is available through the Menhir VS Code extension.
Implemented Features
The server supports the following set of LSP feautres in .mll and .mly files:
- Find References
- Jump to Definition
- Hover
- Document Symbols
- Completion
- Code Actions
- Rename
- Selection Range
- Document Formatting
Moreover, menhir-lsp provides document symbols and folding ranges in Menhir .messages databases that store syntax error messages of your parsers. More info in the extension's README.
Installation & Usage
Install the server through opam:
opam install menhir-lspThe server alone doesn't do much, to do its job it needs a client that speaks the Language Server Protocol running in your editor. If you use VS Code proceed by installing the Menhir extension, then open a document with the .mly or .mll file extension. The LSP client will launch the server and communicate with it automatically.
Many features are available out of the box in any workspace, but to get the most out of menhir-lsp - project-wide hover types, references, completions, etc. - make sure your workspace is a dune project and you declare your parser and lexer modules in the menhir and ocamllex stanzas of your libraries respectively.
For integration with other editors, please refer to their documentation on how to register a LSP client.
Manual installation
Run these commands if you encounter a problem with the opam package or you'd like to hack on the server:
git clone https://github.com/dalps/menhir-lsp.git && cd menhir-lsp
dune installYou can also download a copy of the binary from the lateset release on GitHub. Put it under a folder that's under your PATH and the client should be able to run it just as well.
Development
The server's code lives in the bin directory. It relies on Linol, an OCaml package that simplifies the development of Language Servers, and the visitors OCaml syntax plugin, for automating AST traversals.
It is also based on the original codebases of both Menhir and Ocamllex, whose parsers I modified in order to annotate their ASTs with source locations and make error recovery possible.
Additional references: ocaml-lsp, atd-lsp, catala-lsp. These were huge help material for implementing common LSP tasks in OCaml.
Editor support
Currently only VS Code is supported, but not everyone uses VS Code. If you think this is useful and would like to have menhir-lsp work in your preferred editor, please consider contributing a new client / extension / adapter through a PR. I'm planning to maintain only the VS Code client since that it is my daily editor.
Issues for bugs / missing features are welcome.
License
GNU General Public License v2.0 only
Dependencies (12)
-
cmdliner
>= "2.1.1" -
re
>= "1.14.0" -
ocamlformat-rpc-lib
>= "0.23.0" -
ppx_deriving_yojson
>= "3.10.0" -
pprint
>= "20230830" -
menhir
>= "20250912" -
ordering
>= "3.20.2" -
containers
>= "3.6" - visitors
-
linol
>= "0.10" -
ocaml
>= "4.14" -
dune
>= "3.20"
Dev Dependencies (4)
-
odoc
with-doc -
ppx_inline_test
with-test -
ppx_expect
with-test -
alcotest
with-test
Used by (1)
-
menhir-lsp
>= "0.5.0"
Conflicts
None