Commit Graph

87 Commits (5481e5015fe87b9eb94b89006a0fdfd6ee42b75b)

Author SHA1 Message Date
Lennart Spitzner 5481e5015f Make use of OpTree for type (signature) layouting, Fix layout
Some more cases that still produced broken layout on interaction
with do-blocks were fixed.
2023-05-29 20:44:01 +00:00
Lennart Spitzner 8706b55139 Properly handle comments at the end of imports 2023-05-28 13:55:21 +00:00
Lennart Spitzner a5f2178d87 Fix missing comments in record decl 2023-05-28 13:55:21 +00:00
Lennart Spitzner d4f49f9ced Fix one more block-comment restore-position issue 2023-05-28 13:55:21 +00:00
Lennart Spitzner 8f69d5e816 Fix bad indentation problem for HsMultiIf inside parens 2023-05-28 13:55:21 +00:00
Lennart Spitzner 6721a44359 Retain comments after lambdacase and at record fields 2023-05-28 13:55:21 +00:00
Lennart Spitzner adc74d8bb1 Fix paren-multiline-expression in do block 2023-05-28 13:55:21 +00:00
Lennart Spitzner b874175986 Fix no-module-header start-of-file whitespace 2023-05-28 13:55:21 +00:00
Lennart Spitzner 3b431cdad2 Fix invalid syntax on nested do-block with comment 2023-05-28 13:55:21 +00:00
Lennart Spitzner 5ee0733f96 Add a few more hardcoded fixities 2023-05-28 13:55:20 +00:00
Lennart Spitzner a90550f62d Respect inline configs that happen to appear deep in AST
comments between top-level decls should be considered
for inline-config. But despite being placed between
top-level decls, occasionally they get connected
somewhere nested inside the AST of the first decl.
We fix this by extracting such comments in a
pre-processing step. The control flow was significantly
altered to allow for this;
before:
  parsing -> extract inline configs
          -> compute final config(s)
          -> split module into head/decls/comments/whitespace
          -> ... bridoc -> transformations -> printing
after:
  parsing -> split module into head/decl/comments/whitespace
          -> extract inline configs respecting comments that
             got extracted from decls in the previous step
          -> compute final config(s)
          -> ... bridoc -> transformations -> printing
2023-05-28 13:55:20 +00:00
Lennart Spitzner a9091daeb9 Improve layout options for newtype-decls
Also re-introduce the config flag to enable/disable
single-line newtype rhs layouting.
2023-05-18 15:42:48 +00:00
Lennart Spitzner 9c5a490938 Fix comment duplication on Matches 2023-05-18 15:42:48 +00:00
Lennart Spitzner e38836fdab Fix top-level comment position+whitespace bug 2023-05-18 15:42:48 +00:00
Lennart Spitzner 860c8771ae Fix issue with indentation after block-comments 2023-05-18 15:42:48 +00:00
Lennart Spitzner 47bcdb045b Amend output of golden-tests to avoid confusion 2023-05-18 15:42:48 +00:00
Lennart Spitzner 6008cb26ac Support basic form of HsBangTy 2023-05-18 15:42:48 +00:00
Lennart Spitzner 7e56701bc2 Support associated data decls with multiple constructors 2023-05-18 15:42:48 +00:00
Lennart Spitzner 94fcf56b28 Teach obfuscation module new haskell keywords 2023-05-18 15:42:48 +00:00
Lennart Spitzner b057c49727 Include parse-error in output-not-valid error message 2023-05-18 15:42:48 +00:00
Lennart Spitzner 7bf2879ac0 Deny one layout for OpApp cases unless precedence<=1
Previously allowed: `foo = abc + def-as-par`
Still allowed:      `foo = abc $ def-as-par`
Still allowed:      `foo = abc <&> \x -> def-as-par`
2023-05-08 15:15:14 +00:00
Lennart Spitzner e7cdff440d Fix space between paren and multi-line lambda 2023-05-08 15:15:14 +00:00
Lennart Spitzner 91300f5316 Respect empty lines after let keyword 2023-05-08 14:54:34 +00:00
Lennart Spitzner 687b59c62f Respect newlines before "where" 2023-05-08 14:54:34 +00:00
Lennart Spitzner 2b77142617 Fix layout of type-level list literal 2023-05-03 19:53:19 +00:00
Lennart Spitzner 84e703d7f3 Respect and Fix disable-next-binding/decl 2023-05-02 12:37:02 +00:00
Lennart Spitzner fe876ea0b0 Hardcode more precedences 2023-05-02 12:37:02 +00:00
Lennart Spitzner 884c7da97c Allow special layout for HsApp with HsDo/HsSpiceE args 2023-05-02 09:56:39 +00:00
Lennart Spitzner ab67a794db Fix retaining newlines between do statements 2023-05-02 09:56:39 +00:00
Phil Hazelden 52bde7910f Support promoted type applications.
Closes #370.

Up to GHC 8.10,

    foo @ 'Bar

was a valid type application. In GHC 9 it's not, which means brittany
needs to allow

    foo @'Bar

which it now does.

The reason the space was needed was to allow a promoted type variable at
the head of a type-level list. That is,

    '['Foo]

is invalid syntax, because it initially parses as the character `'['`.
So the promoted type variable was always given a separator at the
beginning, and we'd get

    '[ 'Foo]

which was valid. Now we handle this case by specifically examining the
head of a type-level list; if it's promoted we introduce spaces, so

    '[ 'Foo ]
    '[Foo]

I've added tests for this and some related cases. In doing so I noticed
that unnecessary spaces get added in front of commas in these lists; I
believe that's a separate bug, and I've written a comment explaining why
it happens, but I haven't tried to fix it.

I'm not sure when the first alternates in the `FirstLastSingleton`
and `FirstLast` branches would ever be hit, so I'm not entirely sure if
the separators are necessary there. But since `docSeparator` disappears
at the end of a line and merges with adjacent separators, they should be
harmless.
2023-05-02 09:56:39 +00:00
Lennart Spitzner e11188eb16 Respect newlines after block-comments 2023-05-02 09:56:39 +00:00
Lennart Spitzner 556bc896a6 Refactor WriteBriDoc FlushCommentsPrior code slightly 2023-05-02 09:56:39 +00:00
Lennart Spitzner d2a48ba559 Fixup misspelled data-type name 2023-05-02 09:56:39 +00:00
Lennart Spitzner 7ab6a207ae Update OpApp layouting options
- Allow par-spacing for single-operator 1+n-line layout
- Tweak when to flatten operators, i.e. when to allow a flat one-line-each
  layout for the operator sequence "$ $ $ + +".
2023-05-02 09:16:44 +00:00
Lennart Spitzner 99e5aacb5e Discard special case for non-nested OpApp 2023-05-02 09:16:04 +00:00
Lennart Spitzner 52e4658314 Minor comment updates and cleanup 2023-05-02 09:16:04 +00:00
Lennart Spitzner 56e7d6b5b9 Simplify/Optimize Decl:layoutPatternBindFinal 2023-05-02 09:16:04 +00:00
Lennart Spitzner 156b5cf407 setParSpacing for operator-expression ending in par 2023-05-02 09:16:04 +00:00
Lennart Spitzner d29303d4cd Improve one HsLet layout
- Allow parSpacing for single-clause layout
- Allow par/sl layout when no where-clause was present
  (not sure why this was disabled in the first place)
2023-05-02 09:16:04 +00:00
Lennart Spitzner 5563cd4d93 Dont flatten operators without surrounding parens 2023-05-02 09:16:04 +00:00
Lennart Spitzner 09ec59eaf9 Fix comment-after-context 2023-05-02 09:16:04 +00:00
Lennart Spitzner b24379d104 Fix restore-position after block comment 2023-05-02 09:16:04 +00:00
Lennart Spitzner 2fef44559e Fix comments moving after "where" 2023-05-02 09:16:04 +00:00
Lennart Spitzner ebe85a5949 Use dependency-injection for ToBriDoc modules
I assume this makes inlining impossible, but it enables
parallel compilation of all these modules. In my tests
this reduce wall clock time to 92%, and with more cores
the benefit should be higher.
2023-05-02 09:16:04 +00:00
Lennart Spitzner 736c2a8d46 Fix retain comments on matches (lambda rhs etc.) 2023-05-02 09:16:04 +00:00
Lennart Spitzner 0a76fe952c Refactor s/rec/go for extension compat 2023-05-02 09:16:03 +00:00
Lennart Spitzner dc4e59f2a1 Fix BDLines getSpacing computation 2023-05-02 09:16:03 +00:00
Lennart Spitzner 412c5460aa Do not count warnings for considering exactprint fallback 2023-05-02 09:16:03 +00:00
Lennart Spitzner dd4367c6e8 Fixup annotation on error-fallback 2023-05-02 09:16:03 +00:00
Lennart Spitzner 676695a609 Implement fixity-aware-ops feature 2023-05-02 09:16:03 +00:00