VSCode vs vim/emacs for OCaml

I used emacs for OCaml development for many years, then switched to vscode a few years ago. I’ve been pretty happy with the ocaml-lsp-server extension, the language support seems very comparable to emacs with tuareg/merlin.

I happened to be looking at ocaml.org and noticed this blurb:

OCaml has great support for the most popular editors. VS Code is recommended for beginners, and for power users there is deep integration with Vim and Emacs.

So my question is: what are these “deep integrations” and how to do they go beyond what’s available in vscode? I would consider switching back to emacs if it has better language support these days.

I don’t think you are missing much. I think there are one or two features that are not available due to limitations in the lsp protocol. See this message for more information.

That’s a helpful link, thanks. Sounds like the main missing thing is viewing expression types. I actually do remember using that in emacs and thinking it was useful, but on the other hand I apparently didn’t miss it enough to notice!

Interesting ! My gut feeling is that I couldn’t do without it :–)

I played around with this and actually there is a partial solution – if you hover over subexpressions it will pop up a little window with the type. So, that’s nice. I wish I could figure out how to trigger the popup with the keyboard though.

Also I haven’t figured out if there is a way to pick out a selected subexpression, like if I wanted to know the type of 1 + 2 in the expression 1 + 2 < 3. I can only get the types of the atomic sub-expressions. It seems like this should be easy given the above trick but maybe it’s not supported.

You can use the Expand Selection command to grow the selection and trigger the typing with the Show hover command but sadly it seems like it still only takes the cursor’s location into account.

1 Like

There’s a simple (but tedious) workaround. Surround the expression you would like lsp to infer with parentheses and trigger the hover while the cursor is on one of the parentheses characters.

2 Likes