Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Merlin with unusual OCaml packages? #1659

Open
MdeLv opened this issue Aug 6, 2023 · 3 comments
Open

How to use Merlin with unusual OCaml packages? #1659

MdeLv opened this issue Aug 6, 2023 · 3 comments

Comments

@MdeLv
Copy link

MdeLv commented Aug 6, 2023

I use a few special Ocaml packages that do not follow the usual Ocaml way.

For instance, Ocsigen makes a specific compilation for _server and _client sides.
There are .cmi, .cmo, .cmx, .cmt and .type.mli for the _server side.
There are .cmi, .cmo, .js for the _client side.

From the specification of a .merlin file, I tried to point to the correctly compiled interfaces (with vs code + extension ocaml-platform + opam package ocaml-lsp-server) to get Merlin support.

I started with something like:

$ cat .merlin
S        # nothing ? (one root dir with all files)
B _client
B _server
PKG   # todo

But as I don't exactly know the unusual structure of the pointed files, and how exactly Merlin handles the usual stuff, I'm blind.
It doesn't work.

Can you give a hint about the right way to inform Merlin of the available and correct (although unusual) compiled interfaces (I understand Merlin requires)?
Thanks.

@voodoos
Copy link
Collaborator

voodoos commented Aug 8, 2023

I am not familiar with Ocsigen build system, but I would. It looks like support is not great.
The following configuration is proposed on a an open eliom issue:

It is not possible to have Merlin understand the structure of an eliom file made of both client and server parts. > Nevertheless, it is still possible to have Merlin only consider the server parts (and so the shared parts) of your files. Here is an example of configuration that is more or less satisfying:

PKG lwt_ppx
PKG eliom.server
PKG eliom.ppx.server
PKG ppx_deriving.show
PKG ppx_deriving.ord
PKG ppx_deriving.sexp
PKG ocsigen-toolkit.server
PKG ocsigen-start.server
PKG pgocaml_ppx
SUFFIX .eliom .eliomi
S .
B _server

Note again that this configuration will entirely skip the client part of your eliom files. Moreover, it is not possible to switch to the client version of this configuration. Once the server parts have been compiled, eliomc hands over to js_of_eliom the type annotations of variables defined on the server side and used on the client side. Currently, Merlin cannot be made aware of the existence of those type annotations

@MdeLv
Copy link
Author

MdeLv commented Aug 8, 2023

Hi,
Thanks for your quick feedback.

Presently, I can handle the client side with some templates.
The server side is my priority to be able to navigate:

  • in server side modules.
  • in my usual OCaml .ml[i] modules.
    The .ml[i] can sure be renamed in .eliom but I would like to reuse existing .ml files and the Makefile.options targets .ml files:
    SERVER_FILES := $(wildcard *.eliomi *.eliom *.ml) \

I tried your sound .merlin file.
I make cleaned+recompiled.
It looks that I get only the usual autocompletion from editor buffer (e.g. Test_container.eliom).
But not yet those never used before (e.g. Test_handler.eliom)

I'm using vscode +extension ocaml-platform + opam package ocaml-lsp-server.
I created a new program with package calendar: Merlin (and autocompletion) works correctly : I can go to definition.

Is there a way to see exactly what is happening when using Merlin and autocompletion? (Merlin log file, lsp-server log file or any other tool)

This is a great chance to much more understand these Ocaml toolings.
Thanks.

@voodoos
Copy link
Collaborator

voodoos commented Aug 16, 2023

In fact, your issue might be due to ocaml-lsp-server ignoring the .merlin config all together.

There is a --fallback-read-dot-merlin flag that should be passed to the server, but I am not sure of the best way to do it. @anmonteiro, it looks like you used that flag for melange, do you happen to now the best way to set it in vscode ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants