1
1
mirror of https://github.com/google/ormolu.git synced 2024-09-19 04:07:48 +03:00
Commit Graph

251 Commits

Author SHA1 Message Date
amesgen
34bdf62429
Group StandaloneKindSignatures with type synonyms 2021-02-02 21:15:27 +01:00
Mark Karpov
286afb7ed6 Avoid inserting a redundant space in front of ticked types
In certain cases spaces in this position are unnecessary. Here we try to
make the algorithm smarter so that it doesn't always insert spaces.
2020-11-11 14:33:23 +01:00
Greg Pfeil
288e1cc039 Add support for monad comprehensions 2020-11-11 00:57:32 +01:00
Mark Martynov
64735598c7 Fix multiline record dot updates with the record dot plugin 2020-11-01 14:17:15 +01:00
Mark Karpov
c883856849 Make single-line explicit bidirectional pattern synonyms idempotent 2020-09-21 22:45:36 +02:00
Mark Karpov
a38b0096b9 Guarantee a space before ticked promoted types 2020-09-21 22:27:32 +02:00
Mark Karpov
68c3147f5e Improve grouping of top-level type signatures 2020-06-26 14:04:47 +02:00
Mark Karpov
e29dd2b1c7 Fix the bug when comments in different styles get glued together 2020-06-24 17:10:54 +02:00
Mark Karpov
ca83f15869 Implement merging on imports 2020-06-22 16:31:26 +02:00
Mark Karpov
be1eac66c3 Implement merging of the items in import sections 2020-06-19 17:39:23 +02:00
Mark Karpov
e09fcc0316 Fix the bug related to de-association of pragma comments 2020-06-18 13:59:04 +02:00
Mark Karpov
3fc444a70b Fixed the bug in the de-duplicating algorithm for import lists 2020-06-17 16:50:32 +02:00
Mark Karpov
cc337bda18 Prevent type applications from gluing to TH splices that follow them 2020-06-15 12:12:23 +02:00
Mark Karpov
a877785709 Preserve blank lines in ‘let’ and ‘where’ bindings 2020-06-15 10:56:03 +02:00
Mark Karpov
d5a5bf66c0 Fix rendering of function arguments in multiline layout 2020-06-10 15:14:46 +02:00
Mark Karpov
2efc5d37f9 Format linked lists with colon as line terminator
This adds support for a formatting style described here:

<https://wiki.haskell.org/List_notation>
2020-06-10 14:31:07 +02:00
Mark Karpov
903d8d9eef Avoid outputting trailing whitespace in multiline comments 2020-06-04 16:50:47 +02:00
Mark Karpov
2b1d013d7c Put operators after other names
Previously ‘RdrName’s were sorted by simple comparison of their names.
However, in ASCII not all “operator-like” symbols go after alpha-numeric
characters. This resulted in this sort of output:

  import Linear.Vector ((*^), Additive (..), (^*))

The new ordering scheme allows us to separate operators and other names:

  import Linear.Vector (Additive (..), (*^), (^*))
2020-06-03 17:39:12 +02:00
Mark Karpov
67e43e0057 Handle magic comments for disabling/enabling with more flexibility 2020-06-03 15:28:57 +02:00
Jonas
9e11a5c1b2 Remove duplicate LIE's from import lists 2020-05-26 12:04:53 +02:00
Mark Karpov
8eac6bb7a0 Fix an idempotence issue with operators chains 2020-05-25 16:19:37 +02:00
Mark Karpov
1fb65a218c Fix non-idempotent transformation of partly documented data definition 2020-05-15 12:21:27 +02:00
Mark Karpov
b0092e11a1 Fix another case of non-idempotence with inline comments 2020-05-14 15:45:01 +02:00
Mark Karpov
76c4f523d7 Fix rendering of unnamed fields of data constructors 2020-05-13 15:37:07 +02:00
Mark Karpov
a5c4d6c439 Improve rendering of comments around if expressions 2020-05-11 16:47:37 +02:00
Mark Karpov
6ecae36922 Fix the false positive about AST differences
Comments that have more than one consecutive blank line will be rendered
with just a single blank line due to how our rendering engine works. I think
that the engine work correctly in this case and we want to generally
normalize blank lines. So what should be fixed is just the check. For that
we remove extra consecutive blank lines when we construct ‘Comment’ values.
2020-05-11 13:58:48 +02:00
Mark Karpov
60752a2853 Fixed an idempotence issue in type synonym and data declarations 2020-05-07 19:29:52 +02:00
Mark Karpov
0abedcce03 Prevent the equality sign from “disconnecting” comments
This resolves a class of idempotence issues when the equality sign happens
to be inserted between an element and its comment that follows on the same
line. I had to special-case equality sign for this, because all alternative
approaches (changing comment association logic or trying to find a more
general rule) did not work or fixed this issue yet made other things worse.

There is nothing special about the equality sign per se, but it (always?)
starts definitions which have their own ‘Located’ wrappers and it is those
spans interfere with the logic of comment association (they are detected as
AST elements between the “host” element and its comment) on subsequent
passes. This results in non-idempotent formatting.

The solution is OKish in that it fixes 99% of problems that one will
encounter in practice, but I see how an input can be crafted to show that
there is still an issue with idempotence.
2020-05-06 23:03:57 +02:00
Mark Karpov
194da3a19f Fix the difference in indentation levels in a comment series 2020-05-05 14:05:24 +02:00
Mark Karpov
991bf8e24d Prevent incorrect detection of continuations of comment series 2020-05-04 19:02:42 +02:00
Mark Karpov
22839ed74c Improve tracking of dirty lines, better hang expressions in records 2020-04-29 18:12:42 +02:00
Mark Karpov
ae789a41b0 Fix rendering of type signatures concerning several identifiers
Previously an extra space were erroneously inserted if the first identifier
happened to be one character long.
2020-04-26 22:44:57 +02:00
Mark Karpov
21dd3775e7 Fix rendering of module headers 2020-04-24 20:21:35 +02:00
Mark Karpov
ec1a432eed Add a CPP macro continuation test 2020-04-22 15:48:53 +02:00
Mark Karpov
53f582a575
Implement experimental support for CPP 2020-04-22 14:47:09 +02:00
Mark Karpov
dde7560291 Allow disabling of Ormolu with special comments
Ormolu can be turned on and off via the special comments:

{- ORMOLU_DISABLE -}

and

{- ORMOLU_ENABLE -}

This allows us to disable formatting selectively for code between these
markers or disable it for the entire file. To achieve the latter, just put
{- ORMOLU_DISABLE -} at the very top. Note that the source code should still
be parseable even without the “excluded” part. Because of that the magic
comments cannot be placed arbitrary, but should rather enclose independent
top-level definitions.
2020-04-21 12:44:39 +02:00
Mark Karpov
c364a30555 Preserve grouping of TH splices 2020-04-20 14:06:22 +02:00
Mark Karpov
490720fedc Preserve comments on pragmas 2020-04-17 17:01:34 +02:00
Mark Karpov
145f7296f5 Preserve grouping of do statements 2020-04-16 20:41:36 +02:00
Mark Karpov
d09429f6ec Format records with a single data constructor more compactly 2020-04-10 18:02:26 +02:00
Mark Karpov
d96f7e3e00 Do not lump together forall and constructors when deciding on layout 2020-04-10 14:37:15 +02:00
Mark Karpov
9b342488be Render type applications similar to value applications 2020-04-10 14:37:15 +02:00
Mark Karpov
9b7b6eb239 Fix rendering of arrow notation with multiline expressions 2020-04-10 12:42:05 +02:00
Utku Demir
100fa44dbb Respect the ‘ImportQualifiedPost’ language extension
It is tempting to enable ‘ImportQualifiedPost’ automatically for all files,
but in that case we won't be able to tell when to format in the
classical (prefix) style vs the new postfix style. Checking the list of
pragmas on per-file basis is not good enough because the extension can be
enabled in other ways, such as via the --ghc-opt flag.
2020-04-05 12:22:07 +02:00
Utku Demir
b0a261fe5b Support StandaloneKindSignatures 2020-04-05 11:06:32 +02:00
Utku Demir
2c5472944b Update ghc-lib-parser to 8.10.1
GHC 8.10.1 comes with some changes to the AST, which works great for
Ormolu, but causes this commit to be a bit large:

* Trees That Grow extension points for new constructors are now statically
  proven to be uninhabited, via noExtCon :: NoExtCon -> a. Thanks to this
  change I got rid of many notImplemented calls.
* LPat constructor is now a lot more usable, so we don't need to use
  the locatedPat combinator and can remove some boilerplate code.

Also it comes with ImportQualifiedPost and StandaloneKindSignatures
we should support. I did not implement them in this commit, they'll
be merged in later on.

It causes one behaviour change, where the ordering of qualified and
non-qualified imports of the same module is changed. This is due to
our usage of gcompare resulting a different ordering because of the
AST change caused by the ImportQualifiedPost extension. I think this is
acceptable and we shouldn't try to keep backwards compatibility there.

Another behaviour change is that previously HsExpr had a few extra
constructors for arrows and patterns used in expression context. Those
programs were syntactically incorrect, but refused on a later stage. But
we nonetheless formatted those constructs so Ormolu didn't fail there
while keeping the source code intact. However, now those constructors
are removed, so Ormolu fails with a parse error in this case (same as
GHC). I also removed some tests exhibiting this behaviour.
2020-04-05 10:53:40 +02:00
Mark Karpov
ac719f3e99 Improve rendering of "where" in class declarations and such 2020-02-10 11:21:34 +01:00
Mark Karpov
84c2a53349 More compact rendering of type family injectivity constraints 2020-02-01 20:03:41 +01:00
Mark Karpov
a37765cbcb Make rendering of operator patterns consistent with other cases 2020-01-31 14:36:40 +01:00
Avi Dessauer
77424882fd Differentiate recordDot & standard record updates 2020-01-17 11:12:08 +01:00