1
1
mirror of https://github.com/google/ormolu.git synced 2024-12-01 00:32:04 +03:00
Commit Graph

272 Commits

Author SHA1 Message Date
mrkkrp
a3a93ebfef Refactor the comment rendering code and ‘newline’
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.
2019-09-05 16:56:43 +02:00
Utku Demir
e90508e88f Support infix patern synonyms 2019-09-05 11:38:23 +02:00
Utku Demir
b2c6388a01 Remove extra space before type variables with apostrophe 2019-09-05 11:25:33 +02:00
Utku Demir
dde569e918 Don't wrap Ormolu exceptions as GHC errors
Turns out when ‘--unsafe’ is not set, exceptions thrown in formatting code
are caught in the subsequent parsing check, which wraps them as GHC errors
adding a text like:

  Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Which is misleading since the error is not caused by GHC.

This PR avoids it by strictly binding the result of ‘printModule’.
2019-09-05 11:25:20 +02:00
mrkkrp
10232b9c86
Sort extensions that should be manually enabled 2019-09-02 17:10:08 +02:00
mrkkrp
607ef5369a
Add more badges
[skip ci]
2019-08-31 20:31:55 +02:00
Utku Demir
d900f4efaf Test a few Hackage packages on CI 2019-08-30 12:44:14 +02:00
Utku Demir
9dd08eea3b Remove UnicodeSyntax from default extensions 2019-08-30 11:48:26 +02:00
Utku Demir
4ae8025f90 Workaround pattern constructs in expressions 2019-08-30 11:47:30 +02:00
Utku Demir
a2af1eb831 Remove TypeApplications from default extensions 2019-08-30 11:32:31 +02:00
Utku Demir
76ce40df7f Don't use newlines on LambdaCases on single-line layouts 2019-08-30 11:28:47 +02:00
mrkkrp
d74b211f1e
A couple of minor tweaks (command line options parser) 2019-08-28 16:21:43 +02:00
mrkkrp
c0513b3024 Use GHC 8.6.5 2019-08-28 15:44:41 +02:00
mrkkrp
e138b56821
Update the contribution guidelines
[skip ci]
2019-08-28 15:05:53 +02:00
mrkkrp
6713073c5e
Update the readme mentioning current limitations
[skip ci]
2019-08-28 15:02:10 +02:00
mrkkrp
376d8ed9b0
Update the ‘data-files’ field in Cabal file 2019-08-28 13:55:44 +02:00
Utku Demir
592e4695c9 Make multi-line multi-name patterns prettier 2019-08-28 12:04:25 +02:00
Utku Demir
8662581ad5 Correctly place comments inside enclosing expressions at the end of the module 2019-08-28 12:04:14 +02:00
mrkkrp
374aca58e4
Some cosmetic changes in ‘Value.hs’ 2019-08-27 18:38:50 +02:00
mrkkrp
075b2b3680
Drop a bit of useless commented-out code
[skip ci]
2019-08-27 18:31:34 +02:00
mrkkrp
8485e34ec7
Use ‘sitcc’ around let-in construction
Due to the “weird” leading space before ‘in’ we get rather unpleasing
results without ‘sitcc’.
2019-08-27 18:28:49 +02:00
mrkkrp
96390b2405 Fix idempotence bug due to wandering comments
Previously, if an operator had preceding comments attached to its second
argument, they would end up printed right after the operator:

  a
    + -- b comment
      b

On second run however, the comment would be interpreted as attached to ‘(+)’
and the result would be:

  a
    + b -- b comment

Breaking the idempotence guarantees.

The solution that this commit implements includes several steps:

* Introduce the concept of “dirty line”. A line is dirty if it has something
  on it that can have a comment attached to it.

* ‘txt’ is supposed to output fixed bits of syntax that cannot have comments
  attached to them (at least in Ormolu's model).

* ‘atom’ on the other hand outputs things that mark the current line dirty.

* When we're to print preceding comments for the second argument we check if
  the current line is dirty. If it is, we output an extra newline to prevent
  the first comment from changing “hosts”.

* Now there is another problem with trailing whitespace after the operator
  in that case. We solve that by making spaces a bit “lazy”. When the ‘space’
  combinator is used (which is the recommeneded way to separate different
  constructs now) it just guarantees that the next thing we'll output on the
  same line will be separated from previous output by a single space.
  So, using ‘space’ twice results in single space in output still. This has
  the extra benefit of simplifying all the logic that made sure that we have
  only single space and not 0 or 2 spaces when spaces are inserted
  conditionally and independently.
2019-08-27 17:32:11 +02:00
Utku Demir
effb5cd306 Group declarations referring to multiple names 2019-08-27 11:08:43 +02:00
Utku Demir
721ba7e367 Only force braces on hsLocalBinds on a single-line layout 2019-08-27 10:33:11 +02:00
Utku Demir
e5b99e8e66 Be more conservative when inserting braces 2019-08-26 11:58:19 +02:00
Utku Demir
af907ecb9e Make the first newline optional on class declarations 2019-08-26 10:49:23 +02:00
Utku Demir
25c609ca23 Fix an issue with detecting spans of patterns with guards 2019-08-26 10:39:25 +02:00
Utku Demir
de279d8012 Align multi-line lambda arguments nicer 2019-08-25 13:36:47 +02:00
Utku Demir
b2c26b7859 Conditionally add an extra newline on instances 2019-08-25 13:03:45 +02:00
Utku Demir
8cb86d3fac Hang expressions in if-then-else 2019-08-25 12:43:12 +02:00
Utku Demir
9a1f5ebd87 Split large examples
There has been a lot of good intense work lately and as a result of that
some examples have grown considerably. The problem is that we do not show
diffs when something is not formatted as expected, we show entire
"expected/got" files. It works well when files are small, but not so well
where they are huge (some of our examples are well beyond 100 lines). It can
be hard to understand where the problem is.

This commit split long examples into smaller ones to make it easier to see
what went wrong when a test fails.
2019-08-25 12:35:31 +02:00
mrkkrp
19deae563b
Add examples to table of contents and drop the roadmap
[skip ci]
2019-08-21 12:31:02 +02:00
B YI
6408a34e45 Correct the dead link to examples in ‘DESIGN.md’ 2019-08-21 12:30:01 +02:00
mrkkrp
a7076c0f83
Mention the Emacs package in the readme
[skip ci]
2019-08-16 23:24:16 +02:00
mrkkrp
3a093e65c8 Support formatting multiple files at once 2019-08-16 23:06:05 +02:00
mrkkrp
f94400b486 Indent ‘then’ and ‘else’ clauses one level further
This arguably improves readability especially when if-then-else is placed
inside of a ‘do’-block.
2019-08-16 22:38:38 +02:00
Utku Demir
da0b3b8565 Implement the --check-idempotency flag 2019-08-16 22:21:20 +02:00
Utku Demir
e598b72be5 Preserve the name of the expression bracket
Both `[e|...|]` and `[||]` mean the same thing, and instead of sticking to a
single style, we can just preserve what user wrote.
2019-08-16 22:17:53 +02:00
mrkkrp
a3559a2a07 Adjust the nix expression to facilitate importing from outside 2019-08-16 17:49:57 +02:00
mrkkrp
367f7b8a71 Update cabal file to include the full list of data sub-dirs
Although Cabal 3 is now released, not everyone is using it yet. This is why
we cannot just write ‘data/**/*.hs’. We have to have compatibility with
older Cabal versions. For that I'm adding the full list of data
sub-directories constructed using ‘find data -type d’.
2019-08-16 17:29:02 +02:00
Yuriy Syrovetskiy
ee3c506889 Change multiway if layout to keep consistent 2-space indent increase 2019-08-16 17:03:11 +02:00
mrkkrp
d0a44c23cb Add a couple of tests for lambdas with block arguments 2019-08-16 16:48:39 +02:00
mrkkrp
0f76bd4a56
Fix the build 2019-08-16 16:42:35 +02:00
Utku Demir
118558738b Hang after block arguments 2019-08-16 16:20:33 +02:00
yumiova
682a5f4672 Dedent parallel list comprehensions by one step 2019-08-16 16:20:20 +02:00
Utku Demir
159e5e7761 Use new operator style in types & declarations
```
a
  + b
```

instead of

```
a +
  b
2019-08-16 16:15:28 +02:00
Utku Demir
f86155a8ea Try to contain comments inside enclosing constructs
Attach the comment if the next element is not a sibling. I think this is
quite often what we want, since if we put a comment inside a construct, we
prefer it to stay inside the same element.
2019-08-16 16:11:33 +02:00
Utku Demir
58f81876e9 Hang record constructor fields 2019-08-16 16:08:17 +02:00
Utku Demir
625f23959c Implement implicit parameter bindings 2019-08-16 15:57:20 +02:00
Utku Demir
16f2c644a7 Implement handling of semicolons 2019-08-16 15:41:40 +02:00