Skip to content

An OCaml companion for Eglot

License

Notifications You must be signed in to change notification settings

emacsmirror/ocaml-eglot

 
 

Repository files navigation

Warning

ocaml-eglot is highly experimental and at a very early stage of development. While we're very happy to collect user feedback, don't overwhelm your OCaml development environment just yet.

ocaml-eglot

ocaml-eglot is a lightweight Emacs minor mode designed to enhance the experience of writing OCaml code by leveraging the Eglot Language Server Protocol (LSP) client. This tool specifically caters to the OCaml ecosystem by implementing canonical custom requests and commands exposed by the ocaml-lsp-server.

ocaml-eglot bridges the gap between generic LSP support and the specific needs of OCaml developers. Its tight coupling with Eglot ensures a lightweight experience without sacrificing the advanced features made available by ocaml-lsp-server. Its aim is to offer a user experience as close as possible to that offered by the Emacs mode Merlin.

Features

Browsing errors

Eglot relies on Flymake for error diagnosis. OCaml-eglot offers two functions for quickly navigating through errors:

  • ocaml-eglot-error-next (C-c C-x): jump to the next error
  • ocaml-eglot-error-prev (C-c C-c): jump to the previous error

Error navigation example

Jump to definition

Eglot relies on Xref to index cross-references. OCaml-eglot provides a shortcut to quickly jump to the definition:

  • ocaml-eglot-locate (C-c C-l): jump to definition

Jump to definition example

Infer Interface

Used to infer the type of an interface file. If the buffer is not empty, a prompt will ask for confirmation to overwrite the buffer contents:

  • ocaml-eglot-infer-interface: infer the interface for the current implementation file

Infer Interface example

Find Alternate file

OCaml-eglot allows you to quickly switch from the implementation file to the interface file and vice versa. If the interface file does not exist, a prompt can be used to generate it (using type inference, based on ocaml-eglot-infer-inteface):

  • ocaml-eglot-alternate-file (C-c C-a): switch from the implementation file to the interface file and vice versa

Find Alternate File example

Get Documentation

Although the Hover primitive in the LSP protocol can be used to conveniently display value documentation, it is also possible to query for it specifically:

  • ocaml-eglot-document (C-c C-d): documents the expression below the cursor.
  • ocaml-eglot-document-identifier: enables you to enter an identifier (present in the environment) and return its documentation.

Get Documentation Example

Construct Expression

Enables you to navigate between the different typed-holes (_) in a document and interactively substitute them:

  • ocaml-eglot-hole-next: jump to the next hole
  • ocaml-eglot-hole-prev: jump to the previous hole
  • ocaml-eglot-construct: open up a list of valid substitutions to fill the hole

Construct Example

If the ocaml-eglot-construct command is prefixed by an argument, ie: C-u M-x ocaml-eglot-construct, the command will also search for valid candidates in the current environment:

Construct with prefix-arg Example

Source Browsing

OCaml-eglot allows you to navigate semantically in a buffer, passing from an expression to the parent let, the parent module, the parent fun and the parent match expression. It is also possible to navigate between pattern matching cases:

  • ocaml-eglot-jump: jumps to the referenced expression

Construct with prefix-arg Example

Search for values

Search for values using a by polarity query or a type expression. A polarity query prefixes the function arguments with - and the return with +. For example, to search for a function of this type: int -> string. Search for -int +string. Searching by polarity does not support type parameters. A search by type (modulo isomorphisms) uses a query closer to what you would write to describe a type. For example, to find the function int_of_string_opt, search for string -> int option:

  • ocaml-eglot-search searches for a value by its type or polarity (the search type is defined by the input query)

Search Example

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 96.3%
  • Makefile 3.7%