diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc402a6b..6674d4d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - A newline is no longer inserted after a pattern signature ([#663]). - A type with many type applications are now broken into multiple lines. ([#664]). +- A long type-level list is broken into multiple lines. ([#665]). ### Removed @@ -305,6 +306,7 @@ This version is accidentally pushlished, and is the same as 5.3.3. [@uhbif19]: https://github.com/uhbif19 [@toku-sa-n]: https://github.com/toku-sa-n +[#665]: https://github.com/mihaimaruseac/hindent/pull/665 [#664]: https://github.com/mihaimaruseac/hindent/pull/664 [#663]: https://github.com/mihaimaruseac/hindent/pull/663 [#662]: https://github.com/mihaimaruseac/hindent/pull/662 diff --git a/TESTS.md b/TESTS.md index 83b1900d5..a52cf7c63 100644 --- a/TESTS.md +++ b/TESTS.md @@ -1654,24 +1654,6 @@ foo :: #### Promoted types -Promoted lists - -```haskell -fun1 :: Def ('[ Ref s (Stored Uint32), IBool] T.:-> IBool) -fun1 = undefined - -fun2 :: Def ('[ Ref s (Stored Uint32), IBool] :-> IBool) -fun2 = undefined -``` - -Promoted list (issue #348) - -```haskell -a :: A '[ 'True] --- nested promoted list with multiple elements. -b :: A '[ '[ 'True, 'False], '[ 'False, 'True]] -``` - Class constraints should leave `::` on same line ``` haskell @@ -1708,6 +1690,40 @@ c :: '(:->) 'True 'False d :: (:->) 'True 'False ``` +##### Promoted lists + +Short + +```haskell +fun1 :: Def ('[ Ref s (Stored Uint32), IBool] T.:-> IBool) +fun1 = undefined + +fun2 :: Def ('[ Ref s (Stored Uint32), IBool] :-> IBool) +fun2 = undefined +``` + +Long + +```haskell +-- https://github.com/mihaimaruseac/hindent/issues/522 +type OurContext + = '[ AuthHandler W.Request (ExtendedPayloadWrapper UserSession) + , BasicAuthCheck GameInstanceId + , BasicAuthCheck (RegionId, RegionName) + , BasicAuthCheck Alert.SourceId + , M.MultipartOptions M.Tmp + ] +``` + +Nested + +```haskell +-- https://github.com/mihaimaruseac/hindent/issues/348 +a :: A '[ 'True] +-- nested promoted list with multiple elements. +b :: A '[ '[ 'True, 'False], '[ 'False, 'True]] +``` + #### Symbol type constructors Infix diff --git a/src/HIndent/Pretty.hs b/src/HIndent/Pretty.hs index f400b5f0e..75eff81e9 100644 --- a/src/HIndent/Pretty.hs +++ b/src/HIndent/Pretty.hs @@ -1081,7 +1081,7 @@ prettyHsType (HsRecTy _ xs) = hvFields $ fmap pretty xs prettyHsType (HsExplicitListTy _ _ xs) = case xs of [] -> string "'[]" - _ -> hPromotedList $ fmap pretty xs + _ -> hvPromotedList $ fmap pretty xs prettyHsType (HsExplicitTupleTy _ xs) = hPromotedTuple $ fmap pretty xs prettyHsType (HsTyLit _ x) = pretty x prettyHsType HsWildCardTy {} = string "_" diff --git a/src/HIndent/Pretty/Combinators/Lineup.hs b/src/HIndent/Pretty/Combinators/Lineup.hs index 1ee4c9ea7..2cc3d9b5a 100644 --- a/src/HIndent/Pretty/Combinators/Lineup.hs +++ b/src/HIndent/Pretty/Combinators/Lineup.hs @@ -20,7 +20,7 @@ module HIndent.Pretty.Combinators.Lineup , -- * Lists hList , vList - , hPromotedList + , hvPromotedList , -- * Bars hvBarSep , hBarSep @@ -135,10 +135,20 @@ hList = brackets . hCommaSep vList :: [Printer ()] -> Printer () vList = vCommaSepWrapped ("[", "]") +-- | Runs printers to construct a promoted list where elements are aligned +-- in a line or vertically. +hvPromotedList :: [Printer ()] -> Printer () +hvPromotedList = (<-|>) <$> hPromotedList <*> vPromotedList + -- | Runs printers to construct a promoted list in a line. hPromotedList :: [Printer ()] -> Printer () hPromotedList = promotedListBrackets . hCommaSep +-- | Runs printers to construct a promoted list where elements are aligned +-- vertically. +vPromotedList :: [Printer ()] -> Printer () +vPromotedList = vCommaSepWrapped ("'[", " ]") + -- | Runs printers in a line with a space as the separator. spaced :: [Printer ()] -> Printer () spaced = inter space