tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Implement support for operator fixity configuration file #845

Closed mrkkrp closed 2 years ago

mrkkrp commented 2 years ago

This issue describes the next step regarding the operator chains overhaul, it is based on the work in #830.

We need to introduce the ability to overwrite fixity info of specific operators selectively. The override should be added to the Config type and can have exactly the same type as normal fixity map. There should be also a mechanism to read .ormolu (suggested name for configuration files) automatically if it exists, otherwise do nothing leaving the overriding fixity map empty.

I propose we use the same familiar syntax in .ormolu for fixity information, e.g.:

infixl 9  !!
infix  4 `elem`, `notElem`

This has the advantage that it is immediately editable by Haskellers without a need to study a new syntax.

Further, the new override mechanism should be used in the test suite instead of our current practice of choosing a few packages that have the right operators in order to get the "right" results in the tests. This should make the test suite a little bit more robust.

tbagrel1 commented 2 years ago

Is it possible to put two operators in the same fixity declaration in regular haskell files? If that is the case, then we need to update extract-hackage-info, because my regex doesn't support this at the moment. Otherwise, I will suggest that we stick to 1 symbol per fixity declaration.

mrkkrp commented 2 years ago

Yes, it is possible. I copied the example from the source code of base.