Main occurrence is the operator tree code. This commit changes
OpBranches [OpTree ty op] [op]
to
OpBranches (NonEmpty (OpTree ty op)) [op]
such that the calls to `head`/`tail`/`last` can then be replaced by pattern
matching on `:|` or by using the total replacements from `Data.List.NonEmpty`.
Still, we need to call `NE.fromList` twice. `OverloadedLists` is only used in
the tests; as it is otherwise too easy to accidentally write `[] :: NonEmpty a`
without any warning.
Alternatives to this commit are:
- Just do the absolute minimal changes required to silence the warnings (ie
basically inline `head`/`tail`).
- Rewrite the operator tree code even further (maybe using more precise types)
such that the `NE.fromList` are not necessary anymore.
Support explicit mention of target package name in module re-exports. Even
if the exported package is not specified as a direct dependency of the
component being formatted it will be taken into account correctly.
It turns out that gaining knowledge of all module re-exports in the
ecosystem is tricky because the Hoogle database does not contain this
information, so one would need to download all 14+k packages from Hackage
and parse their source code. We've decided that perhaps hardcoding some
common re-exports and otherwise giving the users a way to make Ormolu aware
of arbitrary important re-exports is a satisfactory solution for now.
Co-authored-by: amesgen <alexander.esgen@tweag.io>
I think `Internal` makes it more obvious that the module is not part of the
public API (e.g. the data constructor of `LazyFixityMap` should normally
stay hidden).
This removes (or rather puts it to a lower level) logic around “modifying
newline” because it was very hard to reason about and almost blocked my work
on fixing issue #337.
I also dropped debugging output because it's too verbose and I'm not using
it anyway.
As part of these changes I also changed now the ‘newline’ combinator works.
Now, similar to ‘space’, the second ‘newline’ in a row just tells the
rendering engine to prefix next thing with a newline, using the ‘newline’
combinator more than twice in a row has no effect.
To take full advantage of the new feature I also went through the code and
simplified some logic around outputting exact amount of newlines because now
it's harder to get things wrong, so we can be less careful with counting
newlines.
This change adds an ad-hoc parser for module pragmas to handle
OPTIONS_* pragmas. I did not want to use an existing tokenizer,
because I felt like tokenizing and pretty printing the GHC options
are more prone to error without providing much benefit.
Goals:
* Make the set of combinators clearer and smaller.
* Solve a number of issues, such as those about parse failures related to
patterns.
* Solve the bug from #244.
The idea is very simple, we stop doing this
( foo
, bar
)
and start doing this
( foo,
bar
)
* We switch to trailing commas which solves the indentation issues for
patterns automatically.
* The new general ‘sep’ combinator finally is clear enough, and all the old
zoo of ‘velt’ and ‘velt'’ and ‘sepWith’, etc. which was confusing and
overlapping goes away.