on master help sign in
Fix the bug when comments in different styles get glued together
commite29dd2b1c7c6437fe3524862a1dd36ef1c7ae17f authorMark Karpov <markkarpov92@gmail.com> dateTue 23 Jun 2020, 21:46 (6 years ago) parentc97ba55
5 files changed+20−6
CHANGELOG.md+5 data/examples/other/comment-glued-together-out.hs+7 data/examples/other/comment-glued-together.hs+6 expected-failures/idris.txt−4 src/Ormolu/Printer/Comments.hs+2−2
CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+## Ormolu 0.1.2.0
2+
3+* Fixed the bug when comments in different styles got glued together after
4+ formatting. [Issue 589](https://github.com/tweag/ormolu/issues/589).
5+
16## Ormolu 0.1.1.0
27
38* Imports in a import lists are now normalized: duplicate imports are
data/examples/other/comment-glued-together-out.hsnew file+7
@@ -0,0 +1,7 @@
1+module Main (main) where
2+
3+-- | Foo.
4+
5+-- Bar
6+main :: IO ()
7+main = return ()
data/examples/other/comment-glued-together.hsnew file+6
@@ -0,0 +1,6 @@
1+module Main (main) where
2+
3+{- | Foo. -}
4+-- Bar
5+main :: IO ()
6+main = return ()
expected-failures/idris.txt−4
@@ -2,10 +2,6 @@ The GHC parser (in Haddock mode) failed:
22 src/Idris/Parser.hs:1052:1
33 parse error on input `@'
44
5−AST of input and AST of formatted code differ.
6− at src/Idris/Parser/Data.hs:281:1-29
7−Please, consider reporting the bug.
8−
95The GHC parser (in Haddock mode) failed:
106 src/Idris/Parser/Expr.hs:75:1
117 parse error on input `@'
src/Ormolu/Printer/Comments.hs+2−2
@@ -154,6 +154,7 @@ needsNewlineBefore ::
154154 -- | Last printed comment span
155155 Maybe SpanMark ->
156156 Bool
157+needsNewlineBefore _ (Just (HaddockSpan _ _)) = True
157158needsNewlineBefore l mlastMark =
158159 case spanMarkSpan <$> mlastMark of
159160 Nothing -> False
@@ -238,8 +239,7 @@ commentFollowsElt ref mnSpn meSpn mlastMark (L l comment) =
238239 -- lexemes in front of it and goes right after the previous comment.
239240 not (hasAtomsBefore comment)
240241 && ( case mlastMark of
241− Just (HaddockSpan _ spn) ->
242− srcSpanEndLine spn + 1 == srcSpanStartLine l
242+ Just (HaddockSpan _ _) -> False
243243 Just (CommentSpan spn) ->
244244 srcSpanEndLine spn + 1 == srcSpanStartLine l
245245 _ -> False