Share your VS Code `settings.json` for OCaml dev

I’m normally a Neovim person and that integration with OCaml is nice enough, but I thought I should give VS Code an honest try.

Maybe this is Neovim → VS Code oriented, but here’s what I’ve collected so far after a day of messing around with it.

Besides the obvious first steps

  • install the OCaml Platform extension
  • install the Vim extension, for Vim keys!

My settings.json:

{
   // ms; default kept trying to suggest in_channel stuff `let _ = foo in`
   "editor.quickSuggestionsDelay": 250,
   // only accept suggestions on Tab, not Enter, to save me from the above
   "editor.acceptSuggestionOnEnter": "off",
    // I expect ocamlformat to run every time I hit :w
    // (requires having an .ocamlformat file in your project dir)
    "editor.formatOnSave": true,
}

Bonus

  • any sweet color themes? I miss the neovim / opam editor setup defaults…
3 Likes

How did I not know of "editor.acceptSuggestionOnEnter": "off"? The suggestions on in were my major pain editing OCaml, thanks!

My settings.json has grown huge, but nothing in it is OCaml-specific. I do find the new "editor.bracketPairColorization.enabled": true particularly handy for OCaml source, though.

However, coming from Vim, you may be used to files being terminated by newlines (and not showing the next line number), whereas Code treats newlines as a separator by default, in Windows fashion. So you may be interested in:

{
    "editor.renderFinalNewline": false,
    "files.insertFinalNewline": true
}

Although the latter can also mess up diffs for projects that don’t already have them; I prefer that to be configured in a per-project .editorconfig (there’s a Code extension for these too).

Finally, anyone using editor.formatOnSave for the first time should keep in mind that most formatters, unlike ocamlformat, run even if they aren’t configured for the project. I’ve accidentally ended up with huge diffs after small changes to JSON files due to Code’s built-in formatter, for example. I thus recommend disabling it for languages with problematic formatters; example from my settings.json I can’t resist to share:

{
    "[fsharp]": {
        // I can't take soundness bugs anymore.
        "editor.formatOnSave": false
    }
}
1 Like