HIghlighting issue in OCaml LSP server

I have a custom PPX rewriter. When I’m using it I have issues with highlighting of ranges where variable is being used, more precisely I expect it to highlight all usages and definitions of the variable, but it highlights some weird stuff (see below). This doesn’t happen when I’m not using my rewriter, so I’m not sure is it a bug in my rewriter of lsp-server.

My rewriter looks for expressions like fresh (a b c ...) something and changes them to Fresh.one (fun a -> Fresh.one (fun b -> Fresh.one (fun c -> .... something))). When I create new pattern variables I use the same location of the expression variables in the original AST. I expect that it should be enough to have a proper highlighting. I tried to use other locations for generated variables, but no luck.

Any ideas what is the best way to investigate this?
Demo project is here: GitHub - Kakadu/ocaml-lps-demo-issue147: A demo for https://github.com/ocaml/ocaml-lsp/issues/147

Hi,

I think ocaml-lsp uses merlin occurrences for such highlighting (see here). It’s likely that the problem is a merlin bug or unexpected locations provided by the rewriter. Either way, it’s more of a merlin-related question.