Commit Graph

32 Commits

Author SHA1 Message Date
Mark Karpov
54d36fcc2c Update nix pin, test with GHC 8.8.4 2020-08-23 11:57:50 +02:00
zimbatm
0b92af2a7f nix: allow to pass the system attribute
This allows to build ormolu for another system as the machine's,
combined with Nix remote builders. It is also useful in a context of a
pure evaluation (like Flakes).
2020-08-21 14:51:37 +02:00
Mark Karpov
35f4fb3932 Deal with non-zero indentation in region formatting
Improved region formatting so that indented fragments can also be processed
correctly.
2020-06-16 14:20:52 +02:00
Mark Karpov
8eac6bb7a0 Fix an idempotence issue with operators chains 2020-05-25 16:19:37 +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
991bf8e24d Prevent incorrect detection of continuations of comment series 2020-05-04 19:02:42 +02:00
Mark Karpov
5d1612f153 Replace “idempotency” with “idempotence” 2020-04-27 15:16:40 +02:00
Mark Karpov
83d6dcbc15 Format Cabal file with ‘cabal format’ 2020-04-26 22:10:43 +02:00
Mark Karpov
21dd3775e7 Fix rendering of module headers 2020-04-24 20:21:35 +02:00
Mark Karpov
840acd908b Allow selection of a region to format 2020-04-24 19:01:30 +02:00
Mark Karpov
31f6cfd83f Compare failing logs with exact expected result
This will allow us to test on more code and catch changes in the logs as
they happen.
2020-04-15 15:00:08 +02:00
Mark Karpov
1e089f7dc8 Run the build with 3 latest GHC versions 2020-04-14 18:23:56 +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
5f5a70655a Use Buildkite
Replace CircleCI with Buildkite.
2020-02-10 20:17:49 +01:00
Yuriy Syrovetskiy
40ec6b0098 Fix a typo and GHC warnings 2019-11-18 20:08:41 +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
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
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
mrkkrp
de1a2789c0
A couple of minor changes in ‘default.nix’ 2019-09-27 14:09:07 +02:00
mrkkrp
61a68bbbce Enable checking ‘capability’ on CI 2019-09-16 13:14:25 +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
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
d900f4efaf Test a few Hackage packages on CI 2019-08-30 12:44:14 +02:00
mrkkrp
c0513b3024 Use GHC 8.6.5 2019-08-28 15:44:41 +02:00
mrkkrp
a3559a2a07 Adjust the nix expression to facilitate importing from outside 2019-08-16 17:49:57 +02:00
Utku Demir
e2a6305bd3 Change the way operators are formatted 2019-08-07 20:50:30 +02:00
mrkkrp
7a9aab77b3 Add nix expression for reformatting sources of arbitrary packages
See the description in readme.
2019-07-14 13:14:55 +02:00
mrkkrp
ca49003d41
Drop redundant trailing newlines in nix files 2019-06-24 20:14:49 +02:00
Luc Tielen
6b73283246 Clean nix configuration
* Point to more recent nixpkgs commit. This fixes build issue with python
  3.7.3 (only on darwin?).

* Separate shell.nix and default.nix. This is so that lorri can be used for
  development.

* Add nix output to .gitignore.

* Format *.nix using nixfmt.

* Use gitignore for filtering files in nix derivation.
2019-06-23 19:17:05 +02:00
mrkkrp
34b9b71601 Build the project with Nix and switct to GHC 8.6.4
It was decided that we're going to make the project compatible with just one
GHC version at a time. Right now this version is going to be 8.6.4.

A small refactoring included, plus support for the “deriving via” feature.
2019-05-31 14:43:15 +02:00