Skip to content

Commit

Permalink
Fix {- -}, multiline and not breaking layout due to whitespace traili…
Browse files Browse the repository at this point in the history
…ng a Before inline comment may address last comment in ennocramer#28
  • Loading branch information
Leonidas Loucas committed Jul 3, 2020
1 parent 277fa18 commit 0a06023
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Floskell/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Floskell.Types

import qualified Language.Haskell.Exts.Pretty as HSE
import Language.Haskell.Exts.Syntax
import Data.Char (ord)

-- | Like `span`, but comparing adjacent items.
run :: (a -> a -> Bool) -> [a] -> ([a], [a])
Expand Down Expand Up @@ -164,9 +165,19 @@ printComment correction (Comment{..}, nextSpan) = do
modify (\s -> s { psEolComment = True })
InlineComment -> do
write $ BS.replicate padding 32
write "{-"
string commentText
write "-}"
if srcSpanEndColumn commentSpan - 2 == srcSpanStartColumn commentSpan
then do
alCol <- getNextColumn
write "{-"
string $ case break ((==) 10 . ord) $ reverse commentText of
(pre, _:rest) | all ((==) 32 . ord) pre -> reverse rest
_ -> commentText
newline
column alCol $ write "-}"
else do
write "{-"
string commentText
write "-}"
when (srcSpanEndLine commentSpan /= srcSpanStartLine nextSpan) $
modify (\s -> s { psEolComment = True })
LineComment -> do
Expand Down

0 comments on commit 0a06023

Please sign in to comment.