Fix some type sig layouting minor issue

pull/3/head
Lennart Spitzner 2016-09-03 21:50:31 +02:00
parent d6cf33c3e0
commit 3809ba9ef0
2 changed files with 22 additions and 7 deletions

View File

@ -669,3 +669,13 @@ regressionTests = do
x1' <- docSeq [prepElem, return x1] x1' <- docSeq [prepElem, return x1]
return $ x1' Seq.<| xR return $ x1' Seq.<| xR
|] |]
it "type signature multiline forcing issue" $ do
roundTripEqual $
[text|
layoutWriteNewlineBlock
:: ( MonadMultiWriter Text.Builder.Builder m
, MonadMultiState LayoutState m
, MonadMultiWriter (Seq String) m
)
=> m ()
|]

View File

@ -39,6 +39,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
d <- docSharedWrapper layoutType kind d <- docSharedWrapper layoutType kind
return $ (lrdrNameToText lrdrName, Just $ d) return $ (lrdrNameToText lrdrName, Just $ d)
cntxtDocs <- cntxts `forM` docSharedWrapper layoutType cntxtDocs <- cntxts `forM` docSharedWrapper layoutType
let maybeForceML = case typ2 of
(L _ HsFunTy{}) -> docForceMultiline
_ -> id
let let
tyVarDocLineList = tyVarDocs >>= \case tyVarDocLineList = tyVarDocs >>= \case
(tname, Nothing) -> [docLit $ Text.pack " " <> tname] (tname, Nothing) -> [docLit $ Text.pack " " <> tname]
@ -119,7 +122,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
] ]
, docCols ColTyOpPrefix , docCols ColTyOpPrefix
[ docLit $ Text.pack "=> " [ docLit $ Text.pack "=> "
, docAddBaseY (BrIndentSpecial 3) $ docForceMultiline $ typeDoc , docAddBaseY (BrIndentSpecial 3) $ maybeForceML $ typeDoc
] ]
] ]
) )
@ -212,6 +215,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
] ]
in docPar open $ docLines $ list ++ [close] in docPar open $ docLines $ list ++ [close]
] ]
let maybeForceML = case typ1 of
(L _ HsFunTy{}) -> docForceMultiline
_ -> id
docAlt docAlt
-- (Foo a b c) => a b -> c -- (Foo a b c) => a b -> c
[ docSeq [ docSeq
@ -226,16 +232,16 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
(docForceSingleline contextDoc) (docForceSingleline contextDoc)
( docCols ColTyOpPrefix ( docCols ColTyOpPrefix
[ docLit $ Text.pack "=> " [ docLit $ Text.pack "=> "
, docAddBaseY (BrIndentSpecial 3) $ docForceMultiline typeDoc , docAddBaseY (BrIndentSpecial 3) $ maybeForceML typeDoc
] ]
) )
] ]
HsFunTy typ1 typ2 -> do HsFunTy typ1 typ2 -> do
typeDoc1 <- docSharedWrapper layoutType typ1 typeDoc1 <- docSharedWrapper layoutType typ1
typeDoc2 <- docSharedWrapper layoutType typ2 typeDoc2 <- docSharedWrapper layoutType typ2
let shouldForceML = case typ2 of let maybeForceML = case typ2 of
(L _ HsFunTy{}) -> True (L _ HsFunTy{}) -> docForceMultiline
_ -> False _ -> id
hasComments <- hasAnyCommentsBelow ltype hasComments <- hasAnyCommentsBelow ltype
docAlt $ docAlt $
[ docSeq [ docSeq
@ -250,8 +256,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
( docCols ColTyOpPrefix ( docCols ColTyOpPrefix
[ docWrapNodeRest ltype $ appSep $ docLit $ Text.pack "->" [ docWrapNodeRest ltype $ appSep $ docLit $ Text.pack "->"
, docAddBaseY (BrIndentSpecial 3) , docAddBaseY (BrIndentSpecial 3)
$ if shouldForceML then docForceMultiline typeDoc2 $ maybeForceML typeDoc2
else typeDoc2
] ]
) )
] ]