Troubleshooting LSP server & VS Code extension

Is there some guide on how to troubleshoot LSP server with VS code extension?

In one of my projects (ppx), vs code is unable to show most of the types, complains about ppxlib.metaquot extension points being unknown, etc. It works fine on other projects and I’m trying to figure out what’s the issue here. Project in question builds just fine, has local switch (like other projects do), dune clean && dune build with consecutive restart of LSP server does not seem to change anything.

ocaml-lsp-server 1.4.1
dune 2.8.2
OCaml Platform v1.8.4

I’m not qualified to help but can you reproduce the issue with the latest version of ocaml-lsp-server?

And also update to the latest version of:

  • dot-merlin-reader
  • ppxlib
  • dune

It’s a real shame that this corner of tooling has so many moving parts. I’m well aware of frustrating it can be for users and always on the look out on how to simplify this.

I’ve updated dot-merlin-reader and dune to versions 4.1 and 2.9.1 correspondingly.

I can’t easily update LSP server as it tries to pull in OCaml 4.12 ocaml-lsp-server >= 1.5.0 → ocaml >= 4.12, project is using 4.08 currently. Also I can’t update ppxlib as it requies Jane Street libs 0.14, the project is using 0.13…

The problem is still there. Is there any way to troubleshoot this? Some logs maybe? Something should be wrong in my environment.

Actually things work ouf of the box for my colleague with the following versions:

dune 2.9.0
dot-merlin-reader 4.1
ppxlib 0.13.0
ocaml-lsp-server 1.4.1
vscode 1.57.1
ocaml platform 1.8.4

I have about the same:

dune 2.9.1
dot-merlin-reader 4.1
ppxlib 0.13.0
ocaml-lsp-server 1.4.1
vscode 1.60.0
ocaml platform 1.8.4

Something is wrong with my setup but I don’t know how to debug this.

Do you have some weird paths in your project? E.g. containing spaces for example.

Path is perfectly obvious, - is the most interesting character used in folder names, overall length is 32 symbols. Projects in the same parent folder work just fine.

I noticed one weird thing though - when selecting sandbox the list of options includes an esy sandbox for my project, along with opam one. I tried esy on this project long time ago, and revertedit back to opam workflow, but this menu item is still there in vs code, although I don’t have any esy specific files in the project. I select opam sandbox though.

Is the project you work on publicly available ? It would be easier to give you debugging directions if we knew more about it.

You can try, after running dune build to query merlin manually and check that the configuration is correct:

ocamlmerlin single dump-configuration -filename some_source.ml < path/to/some_source.ml

1 Like

Unfortunately the project is a proprietary codebase. To make things more interesting - source file is in ReasonML. What would be the command for ReasonML source file?

Looks like ReasonML sources just work out of the box (which is awesome!), I’ve glanced at config and noticed some weird thing - in .ocaml.ppx[0] workdir seems correct, but workval references ppx.exe from another project somehow? Why is that?
I also see the following on stderr:
sh: 1: /home/vagrant/git/microservices/other-project/_build/default/.ppx/6c576912eb9e97e8b9374cad21f986b5/ppx.exe: not found

This definitely looks wrong but I’m not sure where from this can come.

merlin.build_path and merlin.source_path also list a bunch of folders from another project. Opam switch that I use is local one, opam switch tells me that the current switch is located in my current project folder, yet merlin gets other project from somewhere.

I’ve removed the local switch in another project along with _build directory, but it is still being referenced in the project that has the issue. I’m using opam 2.1 if that matters.

Okay, I managed to resolve this. When I vendored my current project (which is a library) into another project (which is a service) via a symlink, something created .merlin files right in the source tree. As I had those .gitignore’d, git status didn’t show me those when I was checking for extra files being left somewhere. Those .merlin files were referencing that another project, this is highly confusing and hard to debug… I’ve removed those and now things are back to normal. Thanks @vds for configuration pointer, that really helped.

3 Likes