Open dbuenzli opened 5 years ago
I was thinking as well that it would be nice to use merlin in utop for completion. I remember talking briefly about it with @let-def once. IIRC, we concluded that there was no fundamental blocker.
This is somewhat orthogonal to the ideas in this issue, but I recently played with reimplementing completion using compiler-libs
: https://github.com/nojb/down/commit/4c7d77fca535c0e7013d846dd0dd26ecfd84f101 (it is a proof of concept, so not complete and a little rough around the edges).
Upsides:
Downsides:
.cmi
s need to have been produced with -keep-docs
or one needs to use .cmt
files (not done in the proof of concept)(*) is probably a blocker for an external project such as this, but it would disappear if this code was ever upstreamed into OCaml itself :)
Cheers!
- Depends on compiler-libs (=> one need to build a non-expunged toplevel) (*)
I would love for the expunge process to go. I can appreciate and understand its idea but since we need to improve ocaml
outside of the system it has rather lead to code I would have liked not to have written. However as I noted there it's not necessarily about compiler libs but providing the right bits in Toploop
.
The other problem is that AFAIR loading compiler-libs
in ocamlnat
is a no-go. Not sure if something has changed on that front since them.
A propos @nojb if these things are in the ocaml
executable anyways it may be possible to expose bits from upstream in the Toploop
API. Even if not used by ocaml
itself, this can be benificial for other contexts (e.g. js_of_ocaml
topevels).
The other problem is that AFAIR loading
compiler-libs
inocamlnat
is a no-go. Not sure if something has changed on that front since them.
But it seems ocamlnat
is not expunged:
> ocamlnat
OCaml version 4.14.2 - native toplevel
Enter #help;; for help.
Down v0.3.0-7-ge3a4f38 loaded. Type Down.help () for more info.
Omod v0.0.4-3-gb0d2684 loaded. Type Omod.help () for more info.
# Config.version;;
- : string = "4.14.2"
As mentioned in the manual completion support is rather crude at the moment.
Here are a few directions that could be taken:
Patch
#directory
directives viaTopdirs
to collect which directories are included and pass corresponding-I
arguments toocp-index
. This doesn't however allow us to determine which modules areopen
ed and we miss those-I
option that may have been specified on theocaml
invocation. Best for this would be to solve point 2. in this issue upstream as this would have benefits for other projects aswell (ocamlfind
,utop
,omod
).Along with working on the various points in https://github.com/ocaml/ocaml/issues/7589, try to convince merlin authors to provide support for toplevel sessions via the cli. @pqwy mentioned almost getting to something with
ocamlmerlin single complete-prefix
, but that "it falls short because it heavily assumes you are editing a file in a project".In general it seems better to isolate completion via the cli and try to improve the
Toploop
API so that compiler-libs is not needed (also using compiler-libs inocamlnat
is a no-go). This allowsdown
to work for the rest (readline, history, sessions) even though the underlying completion engine may not have been updated for the latest version of the compiler.