Hi fellow camelers , 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
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
andvim
modes for Merlin.)
What the feature does…
Returns every usages of types, values, constructors and labels in ml
and mli
files in the workspace
Returns direct usages of modules (like M
in include M
)
Can be called on any such usage of a value or on its definition itself
…what is does not do yet:
Return declarations related to searched values in both ml and mli files. This will come in a second iteration.
Occurrences of modules appearing in paths: like M
and N
in M.N.P
. This will also arrive later.
Renaming is experimental and not as smart as one would expect (with regard to punning and other syntactic tricks).
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:
Interaction with PPX might give unexpected results depending on the specifics of the PPX.
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:
Setup
You can find detailed setup instruction in the custom opam repository. In short:
-
Add the repository to your opam installation:
opam repo add index https://github.com/voodoos/opam-repository-index.git
-
Create a switch (global or local) with the
+index
ocaml variant:
opam switch create --repositories=default,index 4.14.2+index
-
Install
merlin
,ocaml-lsp
and the indexer:
opam install indexing-tools
-
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