on master help sign in
Better handle multi-line following comments
1e14f9fmrkkrp
data/examples/declaration/foreign/foreign-export-out.hs+1−1
@@ -2,7 +2,7 @@ foreign export ccall foo :: Int -> IO Int
2
2
3-- | 'foreignTomFun' is a very important thing
3-- | 'foreignTomFun' is a very important thing
4foreign export ccall "tomography"
4foreign export ccall "tomography"
5− foreignTomFun :: StablePtr Storage -> TomForegin {- Storage is bad -}
5+ foreignTomFun :: StablePtr Storage {- Storage is bad -} -> TomForegin
6
6
7foreign export {- We can't use capi here -} ccall "dynamic"
7foreign export {- We can't use capi here -} ccall "dynamic"
8 export_nullaryMeth :: (IO HRESULT) -> IO (Ptr ())
8 export_nullaryMeth :: (IO HRESULT) -> IO (Ptr ())
data/examples/declaration/foreign/foreign-import-out.hs+1−1
@@ -17,7 +17,7 @@ foreign import javascript
17
17
18foreign import {- We use capi here -} capi "pi.h value pi" c_pi :: CDouble
18foreign import {- We use capi here -} capi "pi.h value pi" c_pi :: CDouble
19
19
20−foreign import stdcall "dynamic" {- This is a bad place for a comment -}
20+foreign import stdcall {- This is a bad place for a comment -} "dynamic"
21 dyn_gluBeginSurface
21 dyn_gluBeginSurface
22 :: FunPtr (Ptr GLUnurbs -> IO ())
22 :: FunPtr (Ptr GLUnurbs -> IO ())
23 -- ^ This 'FunPtr' is extremely dangerous, beware
23 -- ^ This 'FunPtr' is extremely dangerous, beware
data/examples/declaration/value/function/operator-comments-out.hs → data/examples/declaration/value/function/operator-comments-0-out.hsrenamed+2−2
@@ -7,10 +7,10 @@ foo =
7
7
8foo =
8foo =
9 bar
9 bar
10− ++ case foo of {- some comment -}
10+ ++ {- some comment -} case foo of
11 a -> a
11 a -> a
12
12
13foo =
13foo =
14 bar
14 bar
15− ++ case foo of {- some comment -}
15+ ++ case foo {- some comment -} of
16 a -> a
16 a -> a
data/examples/declaration/value/function/operator-comments.hs → data/examples/declaration/value/function/operator-comments-0.hsrenamed

The content is the same.

data/examples/declaration/value/function/operator-comments-1-out.hsnew file+16
@@ -0,0 +1,16 @@
1+foo =
2+ bar
3+ ++
4+ -- some comment
5+ case foo of
6+ a -> a
7+
8+foo =
9+ bar
10+ ++ case foo of -- some comment
11+ a -> a
12+
13+foo =
14+ bar
15+ ++ case foo of -- some comment
16+ a -> a
data/examples/declaration/value/function/operator-comments-1.hsnew file+17
@@ -0,0 +1,17 @@
1+foo =
2+ bar
3+ ++
4+ -- some comment
5+ case foo of
6+ a -> a
7+
8+foo =
9+ bar
10+ ++ -- some comment
11+ case foo of
12+ a -> a
13+
14+foo =
15+ bar
16+ ++ case foo of -- some comment
17+ a -> a
data/examples/other/comment-multiline-after-out.hsnew file+1
@@ -0,0 +1 @@
1+foo :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a
data/examples/other/comment-multiline-after.hsnew file+1
@@ -0,0 +1 @@
1+foo :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a
src/Ormolu/Parser/CommentStream.hs+6
@@ -11,6 +11,7 @@ module Ormolu.Parser.CommentStream
11 , Comment (..)
11 , Comment (..)
12 , mkCommentStream
12 , mkCommentStream
13 , isPrevHaddock
13 , isPrevHaddock
14+ , isMultilineComment
14 , showCommentStream
15 , showCommentStream
15 )
16 )
16where
17where
@@ -71,6 +72,11 @@ mkCommentStream extraComments pstate =
71isPrevHaddock :: Comment -> Bool
72isPrevHaddock :: Comment -> Bool
72isPrevHaddock (Comment (x :| _)) = "-- ^" `isPrefixOf` x
73isPrevHaddock (Comment (x :| _)) = "-- ^" `isPrefixOf` x
73
74
75+-- | Is this comment multiline-style?
76+
77+isMultilineComment :: Comment -> Bool
78+isMultilineComment (Comment (x :| _)) = "{-" `isPrefixOf` x
79+
74-- | Pretty-print a 'CommentStream'.
80-- | Pretty-print a 'CommentStream'.
75
81
76showCommentStream :: CommentStream -> String
82showCommentStream :: CommentStream -> String
src/Ormolu/Printer/Comments.hs+3−1
@@ -91,7 +91,9 @@ spitFollowingComment (L ref a) mlastSpn = do
91 meSpn <- getEnclosingSpan (/= ref)
91 meSpn <- getEnclosingSpan (/= ref)
92 withPoppedComment (commentFollowsElt ref mnSpn meSpn mlastSpn) $ \l comment ->
92 withPoppedComment (commentFollowsElt ref mnSpn meSpn mlastSpn) $ \l comment ->
93 if theSameLinePost l ref && not (isModule a)
93 if theSameLinePost l ref && not (isModule a)
94+ then if isMultilineComment comment
95+ then space >> spitCommentNow l comment
94− then spitCommentPending OnTheSameLine l comment
96+ else spitCommentPending OnTheSameLine l comment
95 else do
97 else do
96 when (needsNewlineBefore l mlastSpn) $
98 when (needsNewlineBefore l mlastSpn) $
97 registerPendingCommentLine OnNextLine ""
99 registerPendingCommentLine OnNextLine ""