I created a simple dune project where I have a library preprocessed with camlp5 (more precisely, as a standalone executable built using camlp5 and which outputs serialized OCaml AST) and another library preprocessed with PPX.
Library 1 is being preprocessed into file _build/default/lib1.pp.ml and another into _build/default/libppx/lib2.pp.ml. Mimetype of both files is OCaml abstract syntax tree implementation file (Version 027)
The problem is that it’s OK to use PPX-preprocessed library in IDE but for camlp5 one I get and error. It seems it treats OCaml abstract syntax tre file as a plain text file.
If I remember correctly, merlin doesn’t have support for the camlp4/5 syntax. And for ppxes, merlin doesn’t read the preprocessed file but runs the ppxes itself.
You can probably follow an approach similar to the one taken by reason. Reason has a different frontend for merlin that is automatically transforming the reason file into an ocaml ast. And merlin is working on this ast. I don’t know if camlp5 generates good enough locations for this to be practical.
(1) you have a test-case where merlin or LSP is inhaling serialized AST, and not source-code (via parsing), and it’s blowing up. So if this is a camlp5 bug, it’s due to camlp5’s outputting bad AST, not a parsing issue, yes?
(2) furthermore, these same serialized ASTs are consumed by the OCaml compiler just fine: sans any sort of complaint.
(2) It would be good to -verify- that merlin/lsp is not somehow attempting to invoke camlp5, but I suspect that that’s the case, maybe not high-priority.
(2) I don’t see a standalone test-case. Perhaps a next step would be to take a unit-test from merlin/lsp and modify it to use these serialized AST files, to elicit a failure?
With a standalone unit-test involving merlin/lsp, I could try to explore whether it’s something bad put out by Camlp5.
I’m not a merlin/lsp user, so a full-stack reproduction involving and editor, multiple processes, etc, is Greek to me.
(1) I’m not sure whose bug it is. If it will indeed be a bug of camlp5 I will let you know
(2) I’m sure merlin/lsp doesn’t invoke camlp5. AFAIU it was design not to handle camp5 from very beginning
(2) I don’t want prepare a unit-test right now. I hope that I will get an answer like Merlin doesn't care about contents of '*.pp.ml' files, look at another files or these files should have another mime type or something.