Commit Graph

313 Commits

Author SHA1 Message Date
Yuriy Syrovetskiy
cd6c7521c1 Add stack.yaml.lock to ignored files 2019-11-07 15:39:13 +01:00
mrkkrp
2517d98ba1 Preserve empty ‘forall’s 2019-11-02 15:06:18 +01:00
mrkkrp
fa96da7d67 Restore ‘--ghc-opt’ options again, report unrecognized options
While migrating to ‘ghc-lib-parser’ we accidentally stopped taking into
account the ‘--ghc-opt’ options. This commit fixes that and makes sure we do
not ignore unrecognized GHC options.
2019-11-02 12:45:44 +01:00
Artyom Kazak
b08af17217 Migrate to ‘ghc-lib-parser’
This would let us have features from GHC 8.8.1 while still using GHC 8.6.5
from Nixpkgs. Bonus: Ormolu will be compilable with GHCJS.
2019-11-01 18:19:34 +01:00
mrkkrp
647e32299f Fix moving comments before module header into the export list 2019-11-01 18:12:05 +01:00
mrkkrp
c5c9962604
Add the fix for #420 to the changelog
[skip ci]
2019-10-27 13:49:20 +01:00
mrkkrp
e966848e52 Fix printing of result type in closed type families
Apparently ‘KindSig’ always means double colon, while ‘TyVarSig’ always
means equal sign.
2019-10-26 15:44:03 +02:00
mrkkrp
07a6728c57
Add the fix for #408 the changelog
[skip ci]
2019-10-26 14:20:59 +02:00
mrkkrp
f83f6fd1da
Update links in the readme to make them work outside of GitHub
Relative links work fine on GitHub, but not on e.g. Hackage.
2019-10-22 21:58:57 +02:00
mrkkrp
43c6f45634 Fix a minor inconsistency between normal and foreign type signatures 2019-10-19 13:29:29 +02:00
Yuriy Syrovetskiy
73b03b1b7f Add VS Code plugin link 2019-10-19 12:06:01 +02:00
Utku Demir
3abadaefa5 Make function arguments look more consistent
This change modifies the ‘HsApp’ printer to handle all function parameters
at once instead of following the AST order.

This allows us to consistently put each function argument on separate lines.
Previously, when printing the function f a b c, the AST would look like (((f
a) b) c), which would cause inconsistencies regarding to newlines (imagine f
a\n b).

Otherwise I tried to preserve the same behaviour as the previous printer,
and added a few tests.

This only changes the ‘p_hsExpr’ function, rest of the changes are caused by
the formatting change.
2019-10-08 11:55:04 +02:00
Utku Demir
1d3eeba701 Don't use braces inside parens 2019-10-08 11:08:07 +02:00
mrkkrp
d02483a8ab Fix the “overindentation” issues with function applications 2019-10-04 20:54:04 +02:00
mrkkrp
096c8d7f63 Update the readme
Also adds the note to ‘DESIGN.md’ stating that it's no longer being updated.
2019-10-04 11:44:21 +02:00
mrkkrp
480d6edfb3 Format Ormolu with Ormolu 2019-10-03 23:10:12 +02:00
mrkkrp
c386de89bd Assert that Ormolu is formatted with current version of Ormolu 2019-10-03 23:10:12 +02:00
mrkkrp
368b2da09b Hang expressions in RHS of (<-) in do blocks
Plus some refactoring.
2019-10-03 15:28:38 +02:00
mrkkrp
519136f062 More precise layouts in precise of Haddocks in data definitions 2019-10-03 11:53:05 +02:00
mrkkrp
397fc55b67 Keep the ($) operator on the same line in certain cases 2019-10-02 21:46:15 +02:00
mrkkrp
8466d6e743 Change the style of type signatures
The commit changes how type signatures are printed. The new style looks like
this:

  foo ::
    Int ->
    Char ->
    String

This works better with foralls and other features of the type system that
will be added in the near future, like linear arrows.

In order to print Haddocks nicely (this seems to be the only acceptable
placement):

  foo ::
    -- | First argument
    Int ->
    -- | Second argument
    Char ->
    -- | Result
    String

It is often necessary to re-arrange them completely and use the “pipe style”
instead of “caret style”. It proved to be a very hard task with our older
comment-handling system, if not impossible.

Here we start parsing Haddocks so that they are treated as components of AST
and we now render them as part of rendering of those components. The
existing framework for handling comments only prints non-Haddock comments
now.

The change caused a fair number of new problems and failures which I added
new tests for.
2019-10-02 16:52:42 +02:00
Kierán Meinhardt
776d3f546c Fix small typo in readme 2019-10-01 10:21:26 +02:00
mrkkrp
de1a2789c0
A couple of minor changes in ‘default.nix’ 2019-09-27 14:09:07 +02:00
mrkkrp
87406cbd8f Align opening/closing parentheses and other similar punctuation 2019-09-17 11:58:22 +02:00
mrkkrp
a4e97da37d Introduce a breakpoint after ‘forall’ in type signatures 2019-09-16 13:16:26 +02:00
mrkkrp
61a68bbbce Enable checking ‘capability’ on CI 2019-09-16 13:14:25 +02:00
Utku Demir
c16fe06df3 Tweak hanging logic on HsApp 2019-09-16 10:56:18 +02:00
Utku Demir
4bed990334 Do not use GHC's defaultErrorHandler
It makes the exceptions get wrapped as GHC panic's.
2019-09-16 10:46:15 +02:00
Utku Demir
ed27fb4a9a Handle operators as record fields 2019-09-16 10:38:07 +02:00
mrkkrp
a83796bccb Fix positioning of shebangs 2019-09-14 16:47:19 +02:00
mrkkrp
75ac291f13 Hang guarded equations
Previously guarded expressions were always printed in non-hanging fashion
even if they had a hanging form. This change fixes this behavior.
2019-09-14 14:34:39 +02:00
Utku Demir
1b818c0064 Correct indentation on string gaps
Haskell strings can have "gaps", where any amount of whitespace between
two backslashes are ignored. This allows writing multi-line strings. As
an example, all strings below are the same:

```
"foobar"
"foo\   \bar"
"foo\

   \bar"
```

When parsing a string literal, lexer usually produces two fields, one
of them is the actual string user wrote as a 'SourceText', the other one
is the sanitized version where gaps and other special characters removed.

While printing the string, GHC's Outputable instance uses the 'SourceText'
field, however since that text contains gaps as-is, we can not change
the original indentation. In order to fix this, this commit splits the
strings by the gaps and print each line separately applying the layout
rules.

Also, it applies the same logic to type-level strings.
2019-09-13 11:26:05 +02:00
mrkkrp
c9c3876410 Handle comments inside of import statements better 2019-09-12 21:59:43 +02:00
Utku Demir
5c923a2cf7 Group together pragmas after type signatures 2019-09-11 13:10:19 +02:00
mrkkrp
db486977d7
Add an example how to use Ormolu straight from GitHub 2019-09-11 12:13:58 +02:00
mrkkrp
4109878fe6
Drop handling of operator chains from the limitation list 2019-09-11 09:36:15 +02:00
mrkkrp
5928af6360
Show how to build just Oromlu itself in the readme
Not everyone wants to build all the tests and some people find it annoying
that nix creates dozen of ‘result-’ symlinks after it.
2019-09-11 09:35:05 +02:00
Utku Demir
7268eb1e98 Handle operator chains better
I implemented a custom logic where we assign a score to every occurance of
an operator based on their location, and the average of that score determine
the fixity of the operator.

As you can imagine, the solution is a bit brittle; and it is easy to mislead
it if you knowingly craft an input, but it gave acceptable results for every
code snippet I found online. And since it returns the same AST no matter how
we infer the fixities, it is not the end of the world if we infer something
incorrectly.

The code is not really optimised, and I think it has quadratic time
complexity. Notably, we use opTreeLoc function quite often and it traverses
the whole tree every time. Memoizing that on the OpBranch constructor would
make formatting files with reeeally long operator chains a lot faster. We
can do this once we decide to optimize for speed.
2019-09-10 18:27:15 +02:00
mrkkrp
e5d197fed9 Do not enable -XBangPatterns by default
Here is an example which fails to parse with bang patterns but succeeds
otherwise:

  (!) :: Foo -> Int -> Int
  (Foo n) ! p = n + p

To run Ormolu on this we must not enable bang patterns by default.
2019-09-10 15:33:55 +02:00
mrkkrp
1e14f9ff7e Better handle multi-line following comments 2019-09-09 11:54:18 +02:00
mrkkrp
d4761bf425 Enable checking the ‘tls’ package on CI 2019-09-09 11:13:58 +02:00
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