vyorkin / ormolu.el

A formatter for Haskell source code
36 stars 10 forks source link

Some support for CPP #4

Open mrkkrp opened 5 years ago

mrkkrp commented 5 years ago

CPP is the reality in many files. We could add some limited support for it by:

To be clear, the CPP problem I think is an elephant in the room because for using the formatter on real code you're going to need a way to deal with it. On the other hand it cannot be 100% correctly supported, so we're probably doing the right thing by not supporting it in the tool itself.

sellout commented 4 years ago

I think this is already supported via the ormolu-extra-args variable. If you need to enable it for a project, you can set that variable in a .dir-locals.el file.

I think passing --tolerate-cpp by default just means that ormolu-format-on-save-mode will cause anything actually containing CPP to be potentially mangled, rather than erroring in Ormolu and saving the unformatted file, and trying to do something like commenting CPP is something that should be handled by Ormolu itself if at all. The complexity of successfully re-inserting CPP into a reformatted context is high (which is likely why it's not already in Ormolu).

fisx commented 4 years ago

For what it's worth, we enable CPP in the file itself only, and decided to only run ormolu on files not matching /{-# LANGUAGE CPP/ #-}.

The resulting cleanup lead to a bunch of files where we had it turned on but didn't use it, and even more files where we are using it wrong, and should either replace the CPP blocks with conditional modules in the cabal file, or get rid of the branching altogether. The rest can be moved into small modules that do only CPP, and export only things that don't require CPP any more when being used.

I consider the fact that ormolu makes it awkward to use CPP one of the benefits rather than a drawback. Using bad features should have clear and immediate penalties. :)