Setting up Ormolu for IntelliJ IDEA

🎉I am writing these notes at Brick, a magical mystery no-bullshit publishing platform. Turns out writing goes much faster when I don't have to hit “Publish” or do git commit.

You can use it too — check it out at Brick.do.


Valid as of April 20, 2020.

But doesn't IntelliJ-Haskell already use Ormolu?

Yes, but not the newest version. If you want anything newer than v0.0.3.1, you have to go through the process below.

Installing Ormolu

Easy with Cabal:

cabal install ormolu-0.0.x.y

You can also do it with Stack but it's more involved and depends on the version you need. You want a different resolver for each version. See the list of resolvers Ormolu appears in.

cd ~

stack install --resolver=lts-15.9 ormolu             # Ormolu 0.0.3.1
stack install --resolver=nightly-2020-04-18 ormolu   # Ormolu 0.0.4.0

Setting up IntelliJ

Oh boy, this one is annoying. VSCode was much easier. Anyway, here we go.

You will need to use a newer version of the IntelliJ-Haskell plugin that is published officially. At least beta64.

Go to IntelliJ preferences → Plugins → little cog icon → Manage Plugin Repositories. Add https://plugins.jetbrains.com/plugins/alpha/8258. Search for “IntelliJ-Haskell”, reinstall the plugin.

While you are at it, install the “Save Actions” plugin too, we'll need it later.

Restart the IDE (why? eh, okay).

In preferences → Languages & Frameworks → Haskell, check “Use custom Haskell tools”. Put all the tool names (hlint, hoogle, ormolu, stylish-haskell). You might have to install HLint and Hoogle globally, too, or they won't be available.

In preferences → Save Actions, check “Activate save actions on save” and “Reformat file”.

Finally, note that it's not enough to just open a folder with a Haskell project for it to be considered a Haskell project — you have to set it up (see the instructions). And then, Ormolu won't work, until IntelliJ-Haskell has gone through a bunch of steps re/ setting up the project.