mirror of
https://github.com/google/ormolu.git
synced 2024-10-26 08:31:36 +03:00
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).
This commit is contained in:
parent
0a8cfd62ef
commit
524f8763f3
@ -24,6 +24,14 @@
|
||||
* Fixed [issue 446](https://github.com/tweag/ormolu/issues/446), which
|
||||
involved braces and operators.
|
||||
|
||||
* When there are comments between preceding Haddock (pipe-style) and its
|
||||
corresponding declaration they are preserved like this in the output
|
||||
instead of being shifted. To be clear, this is not a very good idea to
|
||||
have comments in that position because the Haddock will end up not being
|
||||
associated with the declarations. Issues
|
||||
[440](https://github.com/tweag/ormolu/issues/440) and
|
||||
[448](https://github.com/tweag/ormolu/issues/448).
|
||||
|
||||
## Ormolu 0.0.1.0
|
||||
|
||||
* Initial release.
|
||||
|
12
data/examples/other/comment-after-preceding-haddock-out.hs
Normal file
12
data/examples/other/comment-after-preceding-haddock-out.hs
Normal file
@ -0,0 +1,12 @@
|
||||
module Main where
|
||||
|
||||
-- | A
|
||||
|
||||
-- B
|
||||
|
||||
type D = E
|
||||
|
||||
-- | This is 'f'
|
||||
|
||||
-- * Comment
|
||||
f :: a -> b
|
12
data/examples/other/comment-after-preceding-haddock.hs
Normal file
12
data/examples/other/comment-after-preceding-haddock.hs
Normal file
@ -0,0 +1,12 @@
|
||||
module Main where
|
||||
|
||||
-- | A
|
||||
|
||||
-- B
|
||||
|
||||
type D = E
|
||||
|
||||
-- | This is 'f'
|
||||
|
||||
-- * Comment
|
||||
f :: a -> b
|
@ -29,19 +29,12 @@ spitPrecedingComments ::
|
||||
RealLocated a ->
|
||||
R ()
|
||||
spitPrecedingComments ref = do
|
||||
r <- getLastCommentSpan
|
||||
case r of
|
||||
Just (Just Pipe, _) ->
|
||||
-- We should not insert comments between pipe Haddock and the thing
|
||||
-- it's attached to.
|
||||
return ()
|
||||
_ -> do
|
||||
gotSome <- handleCommentSeries (spitPrecedingComment ref)
|
||||
when gotSome $ do
|
||||
-- Insert a blank line between the preceding comments and the thing
|
||||
-- after them if there was a blank line in the input.
|
||||
lastSpn <- fmap snd <$> getLastCommentSpan
|
||||
when (needsNewlineBefore (getRealSrcSpan ref) lastSpn) newline
|
||||
gotSome <- handleCommentSeries (spitPrecedingComment ref)
|
||||
when gotSome $ do
|
||||
-- Insert a blank line between the preceding comments and the thing
|
||||
-- after them if there was a blank line in the input.
|
||||
lastSpn <- fmap snd <$> getLastCommentSpan
|
||||
when (needsNewlineBefore (getRealSrcSpan ref) lastSpn) newline
|
||||
|
||||
-- | Output all comments following an element at given location.
|
||||
spitFollowingComments ::
|
||||
|
Loading…
Reference in New Issue
Block a user