Make record declarations respect alignment
This commit introduces tests for aligned record declarations. It utilizes docCols and introduces a new `ColSig` for for record declarations.pull/105/head
parent
55f636fcf2
commit
041c5263c2
|
@ -295,6 +295,47 @@ func = f
|
|||
f = id
|
||||
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
#group data type declarations
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
#test single record
|
||||
data Foo = Bar { foo :: Baz }
|
||||
|
||||
#test record multiple names
|
||||
data Foo = Bar { foo, bar :: Baz }
|
||||
|
||||
#test record multiple types
|
||||
data Foo = Bar
|
||||
{ foo :: Baz
|
||||
, bars :: Bizzz
|
||||
}
|
||||
|
||||
#test record multiple types and names
|
||||
data Foo = Bar
|
||||
{ foo, biz :: Baz
|
||||
, bar :: Bizzz
|
||||
}
|
||||
|
||||
#test record multiple types deriving
|
||||
data Foo = Bar
|
||||
{ fooz :: Baz
|
||||
, bar :: Bizzz
|
||||
}
|
||||
deriving Show
|
||||
|
||||
#test record multiple types deriving
|
||||
data Foo = Bar
|
||||
{ foo :: Baz
|
||||
, bars :: Bizzz
|
||||
}
|
||||
deriving (Show, Eq, Monad, Functor, Traversable, Foldable)
|
||||
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
|
|
@ -434,6 +434,7 @@ alignColsLines bridocs = do -- colInfos `forM_` \colInfo -> do
|
|||
(BDCols ColBindStmt _) -> True
|
||||
(BDCols ColDoLet _) -> True
|
||||
(BDCols ColRecUpdate _) -> False
|
||||
(BDCols ColRecDecl _) -> False
|
||||
(BDCols ColListComp _) -> False
|
||||
(BDCols ColList _) -> False
|
||||
(BDCols ColApp _) -> True
|
||||
|
|
|
@ -173,7 +173,7 @@ createDetailsDoc consNameStr details = case details of
|
|||
[ docLit consNameStr
|
||||
, docSeparator
|
||||
, appSep $ docLit $ Text.pack "{"
|
||||
, createNamesAndTypeDoc names t
|
||||
, docSeq $ createNamesAndTypeDoc names t
|
||||
, docSeparator
|
||||
, docLit $ Text.pack "}"
|
||||
]
|
||||
|
@ -181,14 +181,13 @@ createDetailsDoc consNameStr details = case details of
|
|||
docAddBaseY BrIndentRegular $ docPar
|
||||
(docLit consNameStr)
|
||||
(docLines
|
||||
[ docSeq
|
||||
[ docLit $ Text.pack "{ "
|
||||
, let L _ (ConDeclField names t _) = fstField
|
||||
[ docCols ColRecDecl
|
||||
$ docLit (Text.pack "{ ")
|
||||
: let L _ (ConDeclField names t _) = fstField
|
||||
in createNamesAndTypeDoc names t
|
||||
]
|
||||
, docLines
|
||||
$ (\(L _ (ConDeclField names t _)) ->
|
||||
docSeq [docCommaSep, createNamesAndTypeDoc names t])
|
||||
docCols ColRecDecl $ docCommaSep : createNamesAndTypeDoc names t)
|
||||
<$> fields
|
||||
, docLit $ Text.pack "}"
|
||||
]
|
||||
|
@ -213,15 +212,19 @@ createForallDoc (Just (HsQTvs _ bs _)) = do
|
|||
]
|
||||
|
||||
createNamesAndTypeDoc
|
||||
:: [GenLocated t (FieldOcc u)] -> Located (HsType RdrName) -> ToBriDocM BriDocNumbered
|
||||
createNamesAndTypeDoc names t = docSeq
|
||||
:: [GenLocated t (FieldOcc u)] -> Located (HsType RdrName) -> [ToBriDocM BriDocNumbered]
|
||||
createNamesAndTypeDoc names t =
|
||||
[ docSeq
|
||||
$ List.intersperse docCommaSep
|
||||
$ names
|
||||
<&> \(L _ (FieldOcc fieldName _)) ->
|
||||
docLit =<< lrdrNameToTextAnn fieldName
|
||||
, docSeparator
|
||||
, docLit $ Text.pack "::"
|
||||
, docSeparator
|
||||
, layoutType t
|
||||
[ docSeq
|
||||
$ List.intersperse docCommaSep
|
||||
$ names
|
||||
<&> \(L _ (FieldOcc fieldName _)) ->
|
||||
docLit =<< lrdrNameToTextAnn fieldName
|
||||
, docSeparator
|
||||
]
|
||||
, docSeq
|
||||
[ docLit $ Text.pack "::"
|
||||
, docSeparator
|
||||
, layoutType t
|
||||
]
|
||||
]
|
||||
|
|
|
@ -172,6 +172,7 @@ data ColSig
|
|||
| ColBindStmt
|
||||
| ColDoLet -- the non-indented variant
|
||||
| ColRecUpdate -- used for both RecCon and RecUpd. TODO: refactor to reflect?
|
||||
| ColRecDecl
|
||||
| ColListComp
|
||||
| ColList
|
||||
| ColApp
|
||||
|
|
Loading…
Reference in New Issue