Add proper multiline layout for type-level-lists

pull/288/head
Lennart Spitzner 2020-02-23 23:33:03 +01:00
parent 38cdd15221
commit a3b501051a
2 changed files with 68 additions and 2 deletions

View File

@ -834,3 +834,29 @@ module Main
, name , name
) )
where where
#test type level list
xeoeqibIaib
:: ( KqujhIsaus m
, XivuvIpoboi Droqifim m
, IgorvOtowtf m
, RyagaYaqac m
, QouruDU m
)
=> MaptAdfuxgu
-> Zcnxg NsxayqmvIjsezea -- ^ if Lvqucoo, opsip jl reyoyhk lfil qaculxgd
-> QNOZqwuzg
-> Eoattuq
'[ XkatytdWdquraosu -- test comment
, KyezKijim -- another test comment
, DjmioeePuoeg
, NinrxoiOwezc
, QATAlrijacpk
, TrutvotwIwifiqOjdtu
, CoMmuatjwr
, BoZckzqyodseZole
, VagfwoXaeChfqe
]
m
()

View File

@ -14,6 +14,10 @@ where
import Language.Haskell.Brittany.Internal.Config.Types import Language.Haskell.Brittany.Internal.Config.Types
import Language.Haskell.Brittany.Internal.Types import Language.Haskell.Brittany.Internal.Types
import Language.Haskell.Brittany.Internal.LayouterBasics import Language.Haskell.Brittany.Internal.LayouterBasics
import Language.Haskell.Brittany.Internal.Utils
( splitFirstLast
, FirstLastView(..)
)
import GHC ( runGhc import GHC ( runGhc
, GenLocated(L) , GenLocated(L)
@ -693,12 +697,48 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
HsExplicitListTy _ typs -> do HsExplicitListTy _ typs -> do
#endif #endif
typDocs <- docSharedWrapper layoutType `mapM` typs typDocs <- docSharedWrapper layoutType `mapM` typs
hasComments <- hasAnyCommentsBelow ltype
let specialCommaSep = appSep $ docLit $ Text.pack " ,"
docAlt docAlt
[ docSeq [ docSeq
$ [docLit $ Text.pack "'["] $ [docLit $ Text.pack "'["]
++ List.intersperse docCommaSep typDocs ++ List.intersperse specialCommaSep (docForceSingleline <$> typDocs)
++ [docLit $ Text.pack "]"] ++ [docLit $ Text.pack "]"]
-- TODO , case splitFirstLast typDocs of
FirstLastEmpty -> docSeq
[ docLit $ Text.pack "'["
, docNodeAnnKW ltype (Just AnnOpenS) $ docLit $ Text.pack "]"
]
FirstLastSingleton e -> docAlt
[ docSeq
[ docLit $ Text.pack "'["
, docNodeAnnKW ltype (Just AnnOpenS) $ docForceSingleline e
, docLit $ Text.pack "]"
]
, docSetBaseY $ docLines
[ docSeq
[ docLit $ Text.pack "'["
, docSeparator
, docSetBaseY $ docNodeAnnKW ltype (Just AnnOpenS) e
]
, docLit $ Text.pack " ]"
]
]
FirstLast e1 ems eN -> runFilteredAlternative $ do
addAlternativeCond (not hasComments)
$ docSeq
$ [docLit $ Text.pack "'["]
++ List.intersperse specialCommaSep (docForceSingleline <$> (e1:ems ++ [docNodeAnnKW ltype (Just AnnOpenS) eN]))
++ [docLit $ Text.pack " ]"]
addAlternative $
let
start = docCols ColList
[appSep $ docLit $ Text.pack "'[", e1]
linesM = ems <&> \d ->
docCols ColList [specialCommaSep, d]
lineN = docCols ColList [specialCommaSep, docNodeAnnKW ltype (Just AnnOpenS) eN]
end = docLit $ Text.pack " ]"
in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end]
] ]
HsExplicitTupleTy{} -> -- TODO HsExplicitTupleTy{} -> -- TODO
briDocByExactInlineOnly "HsExplicitTupleTy{}" ltype briDocByExactInlineOnly "HsExplicitTupleTy{}" ltype