ocaml-lsp
ocaml-lsp copied to clipboard
Make educated guess for type annotation inside extension point
It would be useful to be able to annotate types in extension points (e.g., [%sexp x]), and even though we'd just be making an educated guess that the identifier in the extension point refers to the same variable outside it, that's probably good enough in practice for this to be valuable functionality.
It would be further useful to have code actions that make this easier, e.g., transforming [%message a ~_:b ~foo:c] into [%message (a: A.t) ~_:(b: B.t) ~foo:(c: C.t)].
Does ocaml-lsp currently give up if it's inside of a ppx like let%bind?
FWIW (in merlin) annotating types works just fine in [%message x]. It's the fact that [%sexp x] is invalid, i.e., the ppx raises an exception, which means that merlin cannot figure out the type of that variable.
([%message x] is expanded like [%message (x : string)], but merlin annotates it with the correct type of x if the variable is bound).
I've updated the original post to clarify. It is sad that we can't add an annotation in [%sexp x] - after all, adding the annotation will make it valid!