Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some support for CPP #4

Open
mrkkrp opened this issue Oct 20, 2019 · 2 comments
Open

Some support for CPP #4

mrkkrp opened this issue Oct 20, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@mrkkrp
Copy link

mrkkrp commented Oct 20, 2019

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

  • Passing the --tolerate-cpp option.
  • Commenting CPP macros in some magic way before formatting and restoring them afterwards.

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.

@vyorkin vyorkin added the enhancement New feature or request label Dec 1, 2019
@sellout
Copy link
Contributor

sellout commented Feb 7, 2020

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
Copy link
Contributor

fisx commented Feb 19, 2020

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants