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

Diagnostics incorrect for build directories other than _build #1433

Open
MoritzHamann opened this issue Dec 29, 2024 · 2 comments
Open

Diagnostics incorrect for build directories other than _build #1433

MoritzHamann opened this issue Dec 29, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@MoritzHamann
Copy link

I'm running a continuous dune build in the _build_lsp directory (via dune build -w --build-dir=_build_lsp) in order to be able to run other dune commands in the default _build directory.

From the logs I can see that ocamllsp recognises the active dune instance in this directory (for RPC)

Connected to dune /path/to/project (/path/to/project/_build_lsp/.rpc/dune)
client 0: connecting...
client 0: connected to dune at unix:///path/to/project/_build_lsp/.rpc/dune

however if there is no _build folder, the diagnostics give me an error along the following

No config found for file lib/some_file.ml. Try calling 'dune build'.

Indeed running dune build (and creating the up to date _build directory) will silence the notification.

Minimal example for reproduction

dune init project lsptest && cd lsptest
touch lib/some_file.ml
dune build -w --build-dir=_build_lsp

Then open lib/some_file.ml from an editor supporting LSP.

@voodoos
Copy link
Collaborator

voodoos commented Jan 6, 2025

I think the mismatch here is due to the fact that OCaml-LSP does not use the RPC to gets Merlin configuration, but starts a specialized configuration server: dune ocaml-merlin. In your case that server should also be started with the correct argument. Unfortunately this is not configurable right now.

The RPC would be the ideal way to get configuration from Dune, but until that happens there might be a simple workaround: the build dir can be set via an environment variable: DUNE_BUILD_DIR. Can you try starting your editor / ocaml-lsp in an environment where this variable has the correct value ? (DUNE_BUILD_DIR=_build_lsp)

@voodoos voodoos added the enhancement New feature or request label Jan 6, 2025
@MoritzHamann
Copy link
Author

Yes this works like a charm! Thanks for the quick solution.

Also, for anyone reading this in the future and using Neovim as their editor, setting the environment variable can be achieved (at least with lspconfig) by adding the cmd_env key to the ocamllsp config:

lsp_config['ocamllsp'].setup({
    cmd_env = {DUNE_BUILD_DIR = '_build_lsp'},
    --- ...
})

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

No branches or pull requests

2 participants