Browsing OCaml source tree with VSCode/merlin?

Hello, is there any proper way to browse/explore the OCaml compiler source tree itself? I tried browsing the tree (having make world.opt done) with VSCode, but I get a lot of type errors.

1 Like

I managed to browse the OCaml source tree with VSCode with the following steps:

  1. Prepare .merlin file (attached below) referring to the all source directories in the tree
  2. Pin your ocaml-lsp-server at 1.8.3 by opam pin ocaml-lsp-server 1.8.3 (as it is the last version that support .merlin)
  3. Clone OCaml repository and check out the same OCaml version as yours (e.g. opam switch create 4.12.1; git checkout 4.12.1)
  4. Build OCaml (./configure && make world)
  5. Open the top folder of the source tree using VSCode (or restart the language server)
  6. Browse the code


content of .merlin:

S ./asmcomp/
# S ./boot/menhir/
S ./bytecomp/
S ./debugger/
S ./driver/
S ./file_formats/
S ./lambda/
S ./lex/
S ./middle_end/
S ./middle_end/closure/
S ./middle_end/flambda/
S ./middle_end/flambda/base_types/
S ./ocamldoc/
S ./ocamltest/
S ./otherlibs/dynlink/
# S ./otherlibs/dynlink/byte/
# S ./otherlibs/dynlink/dynlink_compilerlibs/
# S ./otherlibs/dynlink/native/
S ./otherlibs/str/
S ./otherlibs/systhreads/
S ./otherlibs/unix/
S ./parsing/
S ./stdlib/
S ./tools/
S ./tools/unlabel-patches/
S ./toplevel/
S ./toplevel/byte/
S ./toplevel/native/
S ./typing/
S ./utils/
B ./asmcomp/
B ./asmcomp/debug/
# B ./boot/
B ./bytecomp/
B ./debugger/
B ./driver/
B ./file_formats/
B ./lambda/
B ./lex/
B ./middle_end/
B ./middle_end/closure/
B ./middle_end/flambda/
B ./middle_end/flambda/base_types/
B ./ocamldoc/
B ./ocamldoc/generators/
B ./ocamltest/
B ./otherlibs/bigarray/
B ./otherlibs/dynlink/
# B ./otherlibs/dynlink/byte/
# B ./otherlibs/dynlink/dynlink_compilerlibs/
# B ./otherlibs/dynlink/native/
B ./otherlibs/str/
B ./otherlibs/systhreads/
B ./otherlibs/unix/
B ./parsing/
B ./stdlib/
B ./testsuite/tests/no-alias-deps/
B ./tools/
B ./toplevel/
B ./toplevel/byte/
B ./toplevel/native/
B ./typing/
B ./utils/


Maybe this .merlin file should be contributed to the source tree.

A simpler solution to use merlin is to run dune build @libs in the compiler repository as documented in ocaml/HACKING.adoc at trunk · ocaml/ocaml · GitHub . However, neither merlin nor dune is guaranteed to build on trunk.