ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.62k stars 401 forks source link

Merlin does not work when enabled in a non-default build context #4125

Closed TheLortex closed 3 years ago

TheLortex commented 3 years ago

Expected Behavior

When using (merlin) to enable merlin in a non-default build context, merlin should work.

Actual Behavior

Merlin/ocaml lsp don't work. dune ocaml-merlin --dump-config=$(pwd) returns nothing. It looks like the merlin files are correctly generated in the chosen build context directory. However dune ocaml-merlin --dump-config seems to always look for the files in the default context.

Reproduction

Use a cross-compilation dune-workspace file:

(lang dune 2.0)

(context (default))

(context
 (opam
  (name cross)
  (switch default)
  (merlin)))

Specifications

voodoos commented 3 years ago

I have a fix in voodoos/dune.git#merlin-github4125. Would be great if you could test it.

TheLortex commented 3 years ago

Thank you, the fix works for me !

dboris commented 1 week ago

Hello, I am experiencing this issue with the current version of dune (3.16.0). Using the dune-workspace from the reproduction above, dune ocaml merlin dump-config outputs nothing, and

dune ocaml dump-dot-merlin
No merlin configuration found.

I'm not sure how to run the test in the dune distribution to verify the fix: _build/default/test/blackbox-tests/test-cases/merlin/github4125.t/run.t How is this supposed to be run?

voodoos commented 1 week ago

Hello, I am experiencing this issue with the current version of dune (3.16.0). Using the dune-workspace from the reproduction above, dune ocaml merlin dump-config outputs nothing, and

dune ocaml dump-dot-merlin
No merlin configuration found.

This command should be run from within a directory with source files and a dune file. Is that the case in your tests ?

I'm not sure how to run the test in the dune distribution to verify the fix: _build/default/test/blackbox-tests/test-cases/merlin/github4125.t/run.t How is this supposed to be run?

To run the test github4125.t you can simply call it by it's name: dune build @github4125 (there is an alias generated for each test)

dboris commented 1 week ago

Running dune build @github4125 outputs nothing. Is that a good or a bad sign?

I was running dune ocaml dump-dot-merlin in the project root, where I have a dune-project file but no dune file. If I run it inside a subdirectory with code and a dune file, it does work. However, the dumped .merlin contains tags INDEX and SOURCE_ROOT, which ocamllsp doesn't accept. I am using vscode with the official ocaml platform extension.

My problem is setting up vscode in a cross-compilation setting, where some libraries are available in the target context, eg simulator.ios, but not in the native context, eg simulator. Maybe you have some suggestion how to set it up given the following dune-workspace? https://github.com/dboris/camlkit-starter-nostoryboard/blob/master/dune-workspace

voodoos commented 1 week ago

I was running dune ocaml dump-dot-merlin in the project root, where I have a dune-project file but no dune file. If I run it inside a subdirectory with code and a dune file, it does work. However, the dumped .merlin contains tags INDEX and SOURCE_ROOT, which ocamllsp doesn't accept. I am using vscode with the official ocaml platform extension.

All recent versions of ocaml-lsp-server, since 1.14, should simply ignore unknown configuration directives, can you upgrade yours ?

My problem is setting up vscode in a cross-compilation setting, where some libraries are available in the target context, eg simulator.ios, but not in the native context, eg simulator. Maybe you have some suggestion how to set it up given the following dune-workspace? https://github.com/dboris/camlkit-starter-nostoryboard/blob/master/dune-workspace

Dune lets you choose one context for merlin support, I don't think mixing artifacts from different contexts is possible.

dboris commented 1 week ago

I have ocaml-lsp-server 1.17.0 and it is complaining about these tags.

Is there a way to instruct dune to use the target cross-compilation context, not the native one, for its lsp-server integration?

If I use dot-merlin-reader with a manually crafted .merlin file, I have a partially working solution. I suspect the "Unbound module XXX" ocamllsp errors may be due to the way dune prefixes the files, as in: _build/simulator.ios/CamlLib/.CamlLib.eobjs/byte/duneexeCamlLib.cmi Is there a way to disable the dune__exe__ prefix? I am building an executable, not a library, so (wrapped false) does not work.

voodoos commented 1 week ago

I have ocaml-lsp-server 1.17.0 and it is complaining about these tags.

That's very surprising, are you sure you are running the lsp server you expect to be running ? (In vscode you can select the opam switch via a button in the bottom status bar).

Is there a way to instruct dune to use the target cross-compilation context, not the native one, for its lsp-server integration?

I am not very knowledgeable in that domain but I would expect adding (merlin) to the context of your choice should instruct Dune to write Merlin configuration specific to that context. (https://dune.readthedocs.io/en/stable/reference/dune-workspace/context.html#context)