1- > [ !WARNING]
2- > ` ocaml-eglot ` is ** highly experimental** and at a very early stage
3- > of development. While we're very happy to collect user feedback,
4- > ** don't overwhelm your OCaml development** environment just yet.
5-
61# ocaml-eglot
72
83** ` ocaml-eglot ` ** is a lightweight
@@ -15,13 +10,58 @@ client. This tool specifically caters to the OCaml ecosystem by
1510implementing canonical custom requests and commands exposed by the
1611[ ** ` ocaml-lsp-server ` ** ] ( https://github.com/ocaml/ocaml-lsp ) .
1712
13+ > [ !WARNING]
14+ > ` ocaml-eglot ` is ** experimental** and at an early stage
15+ > of development. While we're very happy to collect user feedback.
16+
1817` ocaml-eglot ` bridges the gap between generic LSP support and the
1918** specific needs of OCaml developers** . Its tight coupling with Eglot
2019ensures a lightweight experience without sacrificing the advanced
2120features made available by ` ocaml-lsp-server ` . Its aim is to offer a
2221user experience as close as possible to that offered by the Emacs mode
2322[ Merlin] ( https://ocaml.github.io/merlin/editor/emacs/ ) .
2423
24+ ## Installation
25+
26+ ` ocaml-eglot ` is distributed as a [ MELPA
27+ package] ( https://melpa.org/#/ocaml-eglot ) . ` ocaml-eglot ` is only an
28+ interface between ` eglot ` (available _ out of the box_ since `emacs >=
29+ 29.1`) and Emacs, a major mode dedicated to OCaml editing must be
30+ installed (e.g. [ caml-mode] ( https://melpa.org/#/caml ) or
31+ [ tuareg] ( https://melpa.org/#/tuareg ) ). Then, for example, you can use
32+ [ ` use-package ` ] ( https://www.gnu.org/software/emacs/manual/html_node/use-package/Lisp-Configuration.html )
33+ to install OCaml-eglot. You will also need
34+ ` https://ocaml.org/p/ocaml-lsp-server/latest ` in the [ current
35+ switch] ( https://ocaml.org/docs/opam-switch-introduction ) .
36+
37+
38+ Here's an example with Tuareg already installed:
39+
40+ ``` scheme
41+ (use-package ocaml-eglot
42+ :ensure t
43+ :after tuareg
44+ :hook
45+ (tuareg-mode . ocaml-eglot)
46+ (ocaml-eglot . eglot-ensure))
47+ ```
48+
49+ ### Activating ` format-on-save `
50+
51+ Eglot provides a hook to format the buffer on saving:
52+
53+ ``` diff
54+ (use-package ocaml-eglot
55+ :ensure t
56+ :after tuareg
57+ :hook
58+ (tuareg-mode . ocaml-eglot)
59+ - (ocaml-eglot . eglot-ensure))
60+ + (ocaml-eglot . eglot-ensure)
61+ + :config
62+ + (add-hook #'after-save-hook #'eglot-format))
63+ ```
64+
2565## Features
2666
2767### Browsing errors
@@ -122,6 +162,12 @@ project, it requires an index. This index can be created by running
122162
123163![ Occurences example] ( media/occurences.gif )
124164
165+ ### Renaming
166+
167+ Use ` ocaml-eglot-rename ` to rename the symbol under the cursor. Starting with OCaml 5.3 it is possible to rename a symbol across multiple files after building an up-to-date index with ` dune build @ocaml-index ` .
168+
169+ ![ Rename example] ( media/rename.gif )
170+
125171### Infer Interface
126172
127173Used to infer the type of an interface file. If the buffer is not
@@ -218,3 +264,32 @@ option`:
218264 (the search type is defined by the input query)
219265
220266![ Search Example] ( media/search.gif )
267+
268+ ## Comparison of Merlin and OCaml-eglot commands
269+
270+ | ` merlin ` | ` ocaml-eglot ` | Note |
271+ | -----------------------------| ------------------------------------| --------------------------------------------------------------------------------------------------------------|
272+ | ` merlin-error-check ` | — | The functionality is supported by ` eglot ` diagnostics (via LSP). |
273+ | ` merlin-error-next ` | ` ocaml-eglot-error-next ` | |
274+ | ` merlin-error-prev ` | ` ocaml-eglot-error-prev ` | |
275+ | ` merlin-type-enclosing ` | ` ocaml-eglot-type-enclosing ` | |
276+ | ` merlin-type-expr ` | ` ocaml-eglot-type-expression ` | |
277+ | ` merlin-locate ` | ` ocaml-eglot-find-declaration ` | |
278+ | — | ` ocaml-eglot-find-definition ` | Available in Merlin by configuration |
279+ | ❌ | ` ocaml-eglot-find-type-definition ` | |
280+ | ` merlin-locate-ident ` | ❌ | |
281+ | ` merlin-occurences ` | ` ocaml-eglot-occurences ` | |
282+ | ` merlin-project-occurences ` | — | Handle by ` ocaml-eglot-occurences ` (if ` ocaml-version >= 5.2 ` and need an index, ` dune build @ocaml-index ` ) |
283+ | ` merlin-iedit-occurrences ` | ` ocaml-eglot-rename ` | |
284+ | ` merlin-document ` | ` ocaml-eglot-document ` | also ` ocaml-eglot-document-identifier ` |
285+ | ` merlin-phrase-next ` | ` ocaml-eglot-phrase-next ` | |
286+ | ` merlin-phrase-prev ` | ` ocaml-eglot-phrase-prev ` | |
287+ | ` merlin-switch-to-ml ` | ` ocaml-eglot-alternate-file ` | |
288+ | ` merlin-switch-to-mli ` | ` ocaml-eglot-alternate-file ` | |
289+ | ❌ | ` ocaml-eglot-infer-interface ` | It was supported by ` Tuareg ` (and a bit ad-hoc) |
290+ | ` merlin-jump ` | ` ocaml-eglot-jump ` | |
291+ | ` merlin-destruct ` | ` ocaml-eglot-destruct ` | |
292+ | ` merlin-construct ` | ` ocaml-eglot-construct ` | |
293+ | ` merlin-next-hole ` | ` ocaml-eglot-hole-next ` | |
294+ | ` merlin-previous-hole ` | ` ocaml-eglot-hole-prev ` | |
295+ | ` merlin-toggle-view-errors ` | — | An ` eglot ` configuration |
0 commit comments