mirror of
https://github.com/google/ormolu.git
synced 2024-11-23 14:16:24 +03:00
Better handle multi-line following comments
This commit is contained in:
parent
d4761bf425
commit
1e14f9ff7e
@ -2,7 +2,7 @@ foreign export ccall foo :: Int -> IO Int
|
||||
|
||||
-- | 'foreignTomFun' is a very important thing
|
||||
foreign export ccall "tomography"
|
||||
foreignTomFun :: StablePtr Storage -> TomForegin {- Storage is bad -}
|
||||
foreignTomFun :: StablePtr Storage {- Storage is bad -} -> TomForegin
|
||||
|
||||
foreign export {- We can't use capi here -} ccall "dynamic"
|
||||
export_nullaryMeth :: (IO HRESULT) -> IO (Ptr ())
|
||||
|
@ -17,7 +17,7 @@ foreign import javascript
|
||||
|
||||
foreign import {- We use capi here -} capi "pi.h value pi" c_pi :: CDouble
|
||||
|
||||
foreign import stdcall "dynamic" {- This is a bad place for a comment -}
|
||||
foreign import stdcall {- This is a bad place for a comment -} "dynamic"
|
||||
dyn_gluBeginSurface
|
||||
:: FunPtr (Ptr GLUnurbs -> IO ())
|
||||
-- ^ This 'FunPtr' is extremely dangerous, beware
|
||||
|
@ -7,10 +7,10 @@ foo =
|
||||
|
||||
foo =
|
||||
bar
|
||||
++ case foo of {- some comment -}
|
||||
++ {- some comment -} case foo of
|
||||
a -> a
|
||||
|
||||
foo =
|
||||
bar
|
||||
++ case foo of {- some comment -}
|
||||
++ case foo {- some comment -} of
|
||||
a -> a
|
@ -0,0 +1,16 @@
|
||||
foo =
|
||||
bar
|
||||
++
|
||||
-- some comment
|
||||
case foo of
|
||||
a -> a
|
||||
|
||||
foo =
|
||||
bar
|
||||
++ case foo of -- some comment
|
||||
a -> a
|
||||
|
||||
foo =
|
||||
bar
|
||||
++ case foo of -- some comment
|
||||
a -> a
|
@ -0,0 +1,17 @@
|
||||
foo =
|
||||
bar
|
||||
++
|
||||
-- some comment
|
||||
case foo of
|
||||
a -> a
|
||||
|
||||
foo =
|
||||
bar
|
||||
++ -- some comment
|
||||
case foo of
|
||||
a -> a
|
||||
|
||||
foo =
|
||||
bar
|
||||
++ case foo of -- some comment
|
||||
a -> a
|
1
data/examples/other/comment-multiline-after-out.hs
Normal file
1
data/examples/other/comment-multiline-after-out.hs
Normal file
@ -0,0 +1 @@
|
||||
foo :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a
|
1
data/examples/other/comment-multiline-after.hs
Normal file
1
data/examples/other/comment-multiline-after.hs
Normal file
@ -0,0 +1 @@
|
||||
foo :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a
|
@ -11,6 +11,7 @@ module Ormolu.Parser.CommentStream
|
||||
, Comment (..)
|
||||
, mkCommentStream
|
||||
, isPrevHaddock
|
||||
, isMultilineComment
|
||||
, showCommentStream
|
||||
)
|
||||
where
|
||||
@ -71,6 +72,11 @@ mkCommentStream extraComments pstate =
|
||||
isPrevHaddock :: Comment -> Bool
|
||||
isPrevHaddock (Comment (x :| _)) = "-- ^" `isPrefixOf` x
|
||||
|
||||
-- | Is this comment multiline-style?
|
||||
|
||||
isMultilineComment :: Comment -> Bool
|
||||
isMultilineComment (Comment (x :| _)) = "{-" `isPrefixOf` x
|
||||
|
||||
-- | Pretty-print a 'CommentStream'.
|
||||
|
||||
showCommentStream :: CommentStream -> String
|
||||
|
@ -91,7 +91,9 @@ spitFollowingComment (L ref a) mlastSpn = do
|
||||
meSpn <- getEnclosingSpan (/= ref)
|
||||
withPoppedComment (commentFollowsElt ref mnSpn meSpn mlastSpn) $ \l comment ->
|
||||
if theSameLinePost l ref && not (isModule a)
|
||||
then spitCommentPending OnTheSameLine l comment
|
||||
then if isMultilineComment comment
|
||||
then space >> spitCommentNow l comment
|
||||
else spitCommentPending OnTheSameLine l comment
|
||||
else do
|
||||
when (needsNewlineBefore l mlastSpn) $
|
||||
registerPendingCommentLine OnNextLine ""
|
||||
|
Loading…
Reference in New Issue
Block a user