Allow multi line formatting of normal records

Only single line formatting of normal records was being supported. For
records with long names we need multi line formatting. This also needs
to support both multi and left indentation policies.
pull/259/head
Evan Rutledge Borden 2019-11-07 14:54:42 -06:00
parent a23ef696e8
commit 9494d6203a
2 changed files with 41 additions and 5 deletions

View File

@ -447,6 +447,24 @@ data Foo = Bar
ABC --g
)
#test normal records on multi line indent policy left
-- brittany {lconfig_indentPolicy: IndentPolicyLeft }
data EnterpriseGrantsForCompanyResponse = EnterpriseGrantsForCompanyResponse
Types.Company
[EnterpriseGrantResponse]
#test normal records on multi line indent policy free
-- brittany {lconfig_indentPolicy: IndentPolicyFree }
data EnterpriseGrantsForCompanyResponse = EnterpriseGrantsForCompanyResponse
Types.Company
[EnterpriseGrantResponse]
#test normal records on multi line indent policy multiple
-- brittany {lconfig_indentPolicy: IndentPolicyMultiple }
data EnterpriseGrantsForCompanyResponse = EnterpriseGrantsForCompanyResponse
Types.Company
[EnterpriseGrantResponse]
###############################################################################
###############################################################################

View File

@ -266,11 +266,29 @@ docDeriving = docLit $ Text.pack "deriving"
createDetailsDoc
:: Text -> HsConDeclDetails GhcPs -> (ToBriDocM BriDocNumbered)
createDetailsDoc consNameStr details = case details of
PrefixCon args -> docSeq
PrefixCon args -> do
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
let
singleLine = docSeq
[ docLit consNameStr
, docSeparator
, docSeq $ List.intersperse docSeparator $ args <&> layoutType
]
leftIndented = docSetParSpacing
. docAddBaseY BrIndentRegular
. docPar (docLit consNameStr)
. docLines
$ layoutType <$> args
multiIndented = docSetParSpacing
. docSetBaseAndIndent
. docPar (docLit consNameStr)
. docLines
$ layoutType
<$> args
case indentPolicy of
IndentPolicyLeft -> docAlt [singleLine, leftIndented]
IndentPolicyMultiple -> docAlt [singleLine, multiIndented]
IndentPolicyFree -> docAlt [singleLine, multiIndented]
RecCon (L _ []) -> docEmpty
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
RecCon lRec@(L _ [lField@(L _ (ConDeclField _ext names t _))]) -> docSeq