Which editor/IDE do you use when developing OCaml projects?

While I am perfectly aware that editor-related questions more often than not can lead to heated discussions, I think many OCaml beginners (such as myself) would appreciate to have some insight on what the community uses for day-to-day development.

Therefore, I think it’s a good idea to keep the topic to: what works for you? In particular, I want to know about:

  1. The editor/IDE that you use
  2. OCaml-related plugins, if any
  3. Notable configurations that you’ve made to the editor/plugin, if any
  4. Any extra tooling that you use, if any

Thanks!

2 Likes

I have used Emacs + Tuareg + Merlin + Ocp-indent + Utop for a while.
Now, I’m using Visual Studio Code + vscode-ocaml (which include Merlin).
Now, I’m using Utop instead of ocaml.

2 Likes

I’m terribly backwards, and still use vanilla Vim with no plugins and no type inference. So one of my goals is to move towards a modern Merlin-based setup, ideally using one of the fancy new editors like Atom or VS Code. Help and advice welcome here – I’ve never quite figured out how to bend Vi/Merlin to my needs.

4 Likes

I think the most popular editors in the community remain Vim and Emacs. The main edition helpers are ocp-indent and merlin, and have plugins to integrate with those, as well as a few others (this is also the case of ocp-index/ocp-grep, which functionality overlaps a bit with that of merlin).

The plugins require a bit of setup, but opam user-setup install runs a tool that helps with that part (in a non-invasive and reversible way). Support for more editors is in progress (contributions welcome), see here. Gathering setup info about more popular editors (sublime, atom, etc.) in this thread would be a good thing.

Another tool that I would like to point out tobeginners, for one-file projects or exercises, is ocaml-top (opam install ocaml-top), that pairs a simple editor pane (with library types lookup and automatic indentation) with a toplevel window and easy evaluation controls.

2 Likes

Using tuareg, merlin, flycheck-ocaml and ocp-indent with spacemacs is trivial, just add the ocaml layer. I did not have to configure anything for them to work. (I use spacemacs with vi keybindings and I find it works great.)

3 Likes

Vim here too, but with lots of plugins, unlike @avsm. From Merlin to ocp-indent, with git management, directory tree, multiple cursors and everything.

Quick peek:

2 Likes
  1. emacs
  2. ocp-indent, merlin (+ company as suggested by @let-def), caml-mode
  3. (setq merlin-error-on-single-line t)
  4. odig for API docs.
1 Like

I use neovim with merlin, ocp-indent and deoplete, and I use VSCode with hackwaly:ocaml and Rainbow Brackets.

For documentation, odig if I can use a recent compiler, otherwise ocp-browser.

I use neovim + merlin (using syntastic) + ocp-indent (with def-lkb/ocp-indent-vim plugin available on github) + rgrinberg/vim-ocaml plugin for syntax highlighting of ocaml-related files (such as _tags, opam, etc…)

Also, I have a small rule in vim setup to disable merlin on .mll and .mly files.

2 Likes

If you try VSCode, check out the Vim extension (vscodevim.vim); it’s a fairly good Vim emulator. Look through the extension documentation because they have a lot of settings that can make life easier (e.g. setting the Leader key, etc.).

1 Like

I mainly use vscode, it works great with merlin.

1 Like
  1. good ol’ vim
  2. merlin + syntastic, ocp-indent
  3. nope.
  4. utop. odig. I’m not sure whether topkg is the sort of thing you’re looking for? Lots of little shell snippets and aliases for things like ocaml setup.ml -configure --enable-tests.

I didn’t know about rgrinberg/vim-ocaml and edit a lot of those ancillary things; it sounds really helpful!

I’d like to advocate the vscode-reasonml plugin. The support of OCaml has been re-activated in master branch recently and it’s crazy good. It works by default, without any other additional extension or configuration of your editor. You just need to have merlin and ocp-indent installed.

It provides features like:

  • code lens with type of the value
    If you have a line like
    let plus_one x = x + 1
    The editor will display the type int -> int above the function, without you asking for it types, calling merlin or hovering it.
  • symbols lookup in the file
  • symbols lookup over the PROJECT. I don’t think that another editor provides this feature for OCaml. And you learn to appreciate it.
  • basically all the “basic” features of merlin over a file. And for the missing ones, they are coming soon.
  • semantic highlighting

All this without any line of configuration. I have been using emacs for years and I’m about to switch definitely because it’s so comfortable to have the editor that works by default, without checking which completion plugin it uses, how to be sure this plugin can actually display the documentation and find a shortcut on which to bind this completion.

The extension uses the ocaml-language-server project. Which means any editor can have the same benefits by using a language-server client.

The author is very reactive on the github. I don’t know how to thank him.

And it evens support reasonml (I will try it one day…)!

6 Likes

We have a repo that contains instructions to set up both Atom and VS Code to work nicely with OCaml, (and also other instructions for getting started with xapi-project development), the commands are collected in a Vagrantfile, so the setup can be tested in a VirtualBox VM: https://github.com/xapi-project/dev-vm/blob/master/Vagrantfile#L54

1 Like
  1. |emacs|
  2. |tuareg|, |merlin|, |utop|
  3. |company|
  4. |git|, |magit|, |opam|

When on windows: the same toolset, using https://fdopen.github.io/opam-repository-mingw

1 Like

Err, I believe that either merlin or ocp-index provide them in both Emacs and Vim. I couldn’t live without it either :slight_smile:. ocp-grep (bundled with ocp-index) allows search for uses (rather than definition) of a given symbol, too.

Wow, Visual Studio Code is pretty epic. I installed the OCaml plugin and everything works out of the box indeed. How do I use the master branch of the Reason plugin to try out the OCaml support there, @Khady?

4 Likes

I’ve been using Visual Studio Code and the vscode-reasonml plugin and it is very good. VS Code is snappier than Atom and customizing is also easy. The plugin works almost flawlessly. I’m primarily writing in Reason syntax so there is that.

The only issue with the plugin is that it doesn’t re-run Merlin when switching between tabs. This means if I fixed code in a different file, and it affects a file I just switched into, I have to make a pointless save by adding a space or something for Merlin to re-run and the old error messages to go away. But given the painless install and jump to definition and super-imposing inferred type definitions visually, it is a treat.

3 Likes

I don’t think it’s in merlin. Or I missed the command. There is merlin-locate-ident but it doesn’t list the symbols. Is it what you are talking about? Or it’s in ocp-index and then I missed it because I don’t use ocp-index (yet).

@avsm I compile a vsix and install it in VScode:

npm install vsce
node_modules/vsce/out/vsce package

Then in the extension panel, you can install an extension from a vsix.

I uploaded mine on https://drive.google.com/file/d/0BxPxGGirdyAPdnBPbzZvOUFIc0k/view?usp=sharing if it helps…

The vscode-ocaml extension is very good too. But I feel like a few things are missing. And I prefer the idea of the ocaml-language-server that can be reused. Not sure that it will win at the end though.

1 Like

So I had a look at ocp-grep and it seems to be able to search all usages of a fully qualified ident. Which is pretty useful. Thank you for the advice :slight_smile: A good complement to merlin occurrences that searches only in one file.

ocp-index doesn’t seem to provide a command to list the symbols of the project. ocp-browser does though. So I guess it could be possible to have an editor integration for ocp-index that does the same thing than ocp-browser or what is provided in vscode-reasonml.