Inconsistent highlighting on VSCode with Ocaml Platform

Hello, I stumbled upon a pretty frustrating issue while setting up a fresh install of VSCode to write Ocaml code. The syntax highlighting I got with the Ocaml Platform on this new install is different from what I’m used to on other machines and feels hardly readable.

On the image I linked we can see an example function with usual highlighting on the right and the one I got on the left. (It is the same VSCode theme “Quiet Light”)

I already tried to uninstall Ocaml Platform and VSCode entirely (deleted AppData as well) but I can’t manage to obtain the correct highlighting.

I’m on Windows 11 and my other two working machines are on Windows 10 with exact same VSCode version (1.87) and Ocaml Platform (v1.18.1).

I tried to find a fix but nobody seems to have my problem so I’m asking for help here to solve this issue.

Are you still having this issue?

My guess is that one of the examples is using the “semantic highlighting” feature to let the language server determine the highlighting of the code. That feature was added to the ocaml-lsp language server in a previous release, so the other example may be using an older language server without semantic highlighting support

You can try enabling/disabling semantic highlighting in VS Code to see if it solves your issue. Either edit the editor.semanticHighlighting.enabled setting in your settings.json or use the settings UI:

Note that if the issue is really semantic highlighting, it can look vastly different depending on the color theme. On some it’s barely readable, and on some others it’s a very nice addition.

1 Like

Hello again and thanks for the replies, I only just read them as I wanted to reply that the problem was fixed and that it was about semantic highlighting.
By diving in the ocaml-lsp github, I found that semantic highlighting was enabled by default on versions 1.14 and later, and the default one I had installed on my switch was 1.10.5. In order to enable it, there is an environment variable to set in the settings.json which is OCAMLLSP_SEMANTIC_HIGHLIGHTING=full.
After this, the highlighting was back and my issue was solved.