ocaml / ocaml-lsp

OCaml Language Server Protocol implementation
Other
754 stars 116 forks source link

Make educated guess for type annotation inside extension point #1152

Open ddickstein opened 1 year ago

ddickstein commented 1 year ago

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)].

TyOverby commented 1 year ago

Does ocaml-lsp currently give up if it's inside of a ppx like let%bind?

bcc32 commented 1 year ago

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).

ddickstein commented 1 year ago

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!