[ANN][PREVIEW] Play with project-wide occurrences for OCaml!

Hi fellow camelers :wave:, I am very pleased to announce that every one can now try the upcoming project-wide occurrences feature for Merlin and OCaml-LSP.

This feature involves changes to multiple packages such as ocaml, merlin, ocaml-lsp and dune so we decided to prepare a custom opam repository to make it easy for adventurous people to install the feature, play with it, and most-importantly… break it ! We hope you will have as much fun querying around your codebases as we do :slight_smile:

Requirements for this preview:

  • Have projects compatible with OCaml 4.14.2.
  • These projects build with Dune. (The tools themselves are build-system agnostic, but this preview only include rules for Dune.)
  • You use an LSP-based editor plugin. (We do plan to bring basic support to the vanilla emacs and vim modes for Merlin.)

What the feature does…

:white_check_mark: Returns every usages of types, values, constructors and labels in ml and mli files in the workspace
:white_check_mark: Returns direct usages of modules (like M in include M)
:white_check_mark: Can be called on any such usage of a value or on its definition itself

…what is does not do yet:

:x: Return declarations related to searched values in both ml and mli files. This will come in a second iteration.
:x: Occurrences of modules appearing in paths: like M and N in M.N.P. This will also arrive later.
:warning: Renaming is experimental and not as smart as one would expect (with regard to punning and other syntactic tricks).
:warning: Right now, the dune rules are all-or-nothing, this means that the index will only be created for the entire workspace. If part of the workspace fail to build the index won’t be built.

…and known caveats:

:warning: Interaction with PPX might give unexpected results depending on the specifics of the PPX.
:warning: Values whose definition cannot be determined statically (like items of a first-class module) won’t be searched project-wide. For the same reason, walues coming from libraries that do not install their cmt files won’t be searched project-wide.

Demo

In the following demo, the feature is used to rename a symbol in Merlin. Since the name appears in one declaration, this last occurrence still needs to be replaced by hand for the build to succeed:

references_and_rename_x264(3)

Setup

You can find detailed setup instruction in the custom opam repository. In short:

  1. Add the repository to your opam installation:
    opam repo add index https://github.com/voodoos/opam-repository-index.git

  2. Create a switch (global or local) with the +index ocaml variant:
    opam switch create --repositories=default,index 4.14.2+index

  3. Install merlin, ocaml-lsp and the indexer:
    opam install indexing-tools

  4. Build the index with your project:
    dune build @ocaml-index @your-usual-target-maybe-install-or-all --watch

References and renaming queries should return result on the entire workspace.

Feedback

Please do not hesitate to share any feedback on the feature here or by opening an issue on the repository :slightly_smiling_face:

35 Likes