on master help sign in
Insert comments between declarations and their preceding Haddocks

I originally thought it's a good idea to prevent this, but it looks like it makes things arguably worse in certain cases even though the Haddocks end up not associated with their declarations (but they are not associated with them in the input either, so it's OK).

commit524f8763f3fc3bd338267c0cf5f4aa78f16ee5b1 authormrkkrp <mark.karpov@tweag.io> dateTue 19 Nov 2019, 11:31 (7 years ago) parent0a8cfd6
4 files changed+38−13
CHANGELOG.md+8 data/examples/other/comment-after-preceding-haddock-out.hs+12 data/examples/other/comment-after-preceding-haddock.hs+12 src/Ormolu/Printer/Comments.hs+6−13
CHANGELOG.md+8
@@ -24,6 +24,14 @@
2424* Fixed [issue 446](https://github.com/tweag/ormolu/issues/446), which
2525 involved braces and operators.
2626
27+* When there are comments between preceding Haddock (pipe-style) and its
28+ corresponding declaration they are preserved like this in the output
29+ instead of being shifted. To be clear, this is not a very good idea to
30+ have comments in that position because the Haddock will end up not being
31+ associated with the declarations. Issues
32+ [440](https://github.com/tweag/ormolu/issues/440) and
33+ [448](https://github.com/tweag/ormolu/issues/448).
34+
2735## Ormolu 0.0.1.0
2836
2937* Initial release.
data/examples/other/comment-after-preceding-haddock-out.hsnew file+12
@@ -0,0 +1,12 @@
1+module Main where
2+
3+-- | A
4+
5+-- B
6+
7+type D = E
8+
9+-- | This is 'f'
10+
11+-- * Comment
12+f :: a -> b
data/examples/other/comment-after-preceding-haddock.hsnew file+12
@@ -0,0 +1,12 @@
1+module Main where
2+
3+-- | A
4+
5+-- B
6+
7+type D = E
8+
9+-- | This is 'f'
10+
11+-- * Comment
12+f :: a -> b
src/Ormolu/Printer/Comments.hs+6−13
@@ -29,19 +29,12 @@ spitPrecedingComments ::
2929 RealLocated a ->
3030 R ()
3131spitPrecedingComments ref = do
32− r <- getLastCommentSpan
33− case r of
34− Just (Just Pipe, _) ->
35− -- We should not insert comments between pipe Haddock and the thing
36− -- it's attached to.
37− return ()
38− _ -> do
39− gotSome <- handleCommentSeries (spitPrecedingComment ref)
40− when gotSome $ do
41− -- Insert a blank line between the preceding comments and the thing
42− -- after them if there was a blank line in the input.
43− lastSpn <- fmap snd <$> getLastCommentSpan
44− when (needsNewlineBefore (getRealSrcSpan ref) lastSpn) newline
32+ gotSome <- handleCommentSeries (spitPrecedingComment ref)
33+ when gotSome $ do
34+ -- Insert a blank line between the preceding comments and the thing
35+ -- after them if there was a blank line in the input.
36+ lastSpn <- fmap snd <$> getLastCommentSpan
37+ when (needsNewlineBefore (getRealSrcSpan ref) lastSpn) newline
4538
4639-- | Output all comments following an element at given location.
4740spitFollowingComments ::