1
1
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:
mrkkrp 2019-09-09 11:28:18 +02:00 committed by Mark Karpov
parent d4761bf425
commit 1e14f9ff7e
10 changed files with 48 additions and 5 deletions

View File

@ -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 ())

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
foo :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a

View File

@ -0,0 +1 @@
foo :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a

View File

@ -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

View File

@ -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 ""