Support comments in record data decls
parent
d21ecf89e6
commit
2f6967b7b8
|
@ -379,6 +379,46 @@ data Foo = forall a b . (Show a, Eq b) => Bar
|
||||||
, bars :: b
|
, bars :: b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#test record comments simple
|
||||||
|
data Foo = Bar -- a
|
||||||
|
{ foo :: Baz -- b
|
||||||
|
, bars :: Bizzz -- c
|
||||||
|
} -- d
|
||||||
|
deriving (Show, Eq, Monad, Functor, Traversable, Foldable) -- e
|
||||||
|
|
||||||
|
#test record comments strange inline
|
||||||
|
data Foo = Bar
|
||||||
|
{ -- a
|
||||||
|
foo -- b
|
||||||
|
:: -- c
|
||||||
|
Baz -- d
|
||||||
|
, -- e
|
||||||
|
bars :: Bizzz
|
||||||
|
}
|
||||||
|
deriving (Show, Eq, Monad, Functor, Traversable, Foldable)
|
||||||
|
|
||||||
|
#test record comments in deriving
|
||||||
|
## maybe we want to switch to a differnt layout when there are such comments.
|
||||||
|
## Don't hesitate to modify this testcase, it clearly is not the ideal layout
|
||||||
|
## for this.
|
||||||
|
|
||||||
|
data Foo = Bar
|
||||||
|
{ foo :: Baz
|
||||||
|
, bars :: Bizzz
|
||||||
|
}
|
||||||
|
-- a
|
||||||
|
deriving --b
|
||||||
|
( -- c
|
||||||
|
ToJSON -- d
|
||||||
|
, -- e
|
||||||
|
FromJSON --f
|
||||||
|
) -- g
|
||||||
|
via -- h
|
||||||
|
( -- i
|
||||||
|
SomeType --j
|
||||||
|
, -- k
|
||||||
|
ABC --l
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
@ -176,6 +176,7 @@ createDerivingPar derivs mainDoc = do
|
||||||
docPar mainDoc
|
docPar mainDoc
|
||||||
$ docEnsureIndent BrIndentRegular
|
$ docEnsureIndent BrIndentRegular
|
||||||
$ docLines
|
$ docLines
|
||||||
|
$ docWrapNode derivs
|
||||||
$ derivingClauseDoc
|
$ derivingClauseDoc
|
||||||
<$> types
|
<$> types
|
||||||
|
|
||||||
|
@ -196,10 +197,13 @@ derivingClauseDoc (L _ (HsDerivingClause mStrategy types)) = case types of
|
||||||
in
|
in
|
||||||
docSeq
|
docSeq
|
||||||
[ docDeriving
|
[ docDeriving
|
||||||
, lhsStrategy
|
, docWrapNodePrior types $ lhsStrategy
|
||||||
, docSeparator
|
, docSeparator
|
||||||
, whenMoreThan1Type "("
|
, whenMoreThan1Type "("
|
||||||
, docSeq $ List.intersperse docCommaSep $ ts <&> \case
|
, docWrapNodeRest types
|
||||||
|
$ docSeq
|
||||||
|
$ List.intersperse docCommaSep
|
||||||
|
$ ts <&> \case
|
||||||
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
||||||
HsIB _ t -> layoutType t
|
HsIB _ t -> layoutType t
|
||||||
XHsImplicitBndrs x -> absurdExt x
|
XHsImplicitBndrs x -> absurdExt x
|
||||||
|
@ -215,11 +219,12 @@ derivingClauseDoc (L _ (HsDerivingClause mStrategy types)) = case types of
|
||||||
(L _ AnyclassStrategy ) -> (docLit $ Text.pack " anyclass", docEmpty)
|
(L _ AnyclassStrategy ) -> (docLit $ Text.pack " anyclass", docEmpty)
|
||||||
(L _ NewtypeStrategy ) -> (docLit $ Text.pack " newtype", docEmpty)
|
(L _ NewtypeStrategy ) -> (docLit $ Text.pack " newtype", docEmpty)
|
||||||
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
||||||
(L _ (ViaStrategy viaTypes) ) ->
|
lVia@(L _ (ViaStrategy viaTypes) ) ->
|
||||||
( docEmpty
|
( docEmpty
|
||||||
, case viaTypes of
|
, case viaTypes of
|
||||||
HsIB _ext t -> docSeq
|
HsIB _ext t -> docSeq
|
||||||
[ docLit $ Text.pack " via "
|
[ docWrapNode lVia $ docLit $ Text.pack " via"
|
||||||
|
, docSeparator
|
||||||
, layoutType t
|
, layoutType t
|
||||||
]
|
]
|
||||||
XHsImplicitBndrs ext -> absurdExt ext
|
XHsImplicitBndrs ext -> absurdExt ext
|
||||||
|
@ -239,26 +244,28 @@ createDetailsDoc consNameStr details = case details of
|
||||||
]
|
]
|
||||||
RecCon (L _ []) -> docEmpty
|
RecCon (L _ []) -> docEmpty
|
||||||
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
||||||
RecCon (L _ [L _ (ConDeclField _ext names t _)]) -> docSeq
|
RecCon lRec@(L _ [lField@(L _ (ConDeclField _ext names t _))]) -> docSeq
|
||||||
#else
|
#else
|
||||||
RecCon (L _ [L _ (ConDeclField names t _)]) -> docSeq
|
RecCon lRec@(L _ [lField@(L _ (ConDeclField names t _))]) -> docSeq
|
||||||
#endif
|
#endif
|
||||||
[ docLit consNameStr
|
[ docLit consNameStr
|
||||||
, docSeparator
|
, docSeparator
|
||||||
, appSep $ docLit $ Text.pack "{"
|
, docWrapNodePrior lRec $ docLit $ Text.pack "{"
|
||||||
, docSeq $ createNamesAndTypeDoc names t
|
, docSeparator
|
||||||
|
, docWrapNodeRest lRec $ docSeq $ createNamesAndTypeDoc lField names t
|
||||||
, docSeparator
|
, docSeparator
|
||||||
, docLit $ Text.pack "}"
|
, docLit $ Text.pack "}"
|
||||||
]
|
]
|
||||||
RecCon (L _ fields@(_:_)) -> do
|
RecCon lRec@(L _ fields@(_:_)) -> do
|
||||||
let (fDoc1 : fDocR) = mkFieldDocs fields
|
let (fDoc1 : fDocR) = mkFieldDocs fields
|
||||||
docAddBaseY BrIndentRegular $ docPar
|
docAddBaseY BrIndentRegular $ docPar
|
||||||
(docLit consNameStr)
|
(docLit consNameStr)
|
||||||
(docLines
|
(docWrapNodePrior lRec $ docLines
|
||||||
[ docCols ColRecDecl
|
[ docCols ColRecDecl
|
||||||
$ docLit (Text.pack "{ ")
|
$ appSep (docLit (Text.pack "{"))
|
||||||
: fDoc1
|
: fDoc1
|
||||||
, docLines $ fDocR <&> \f -> docCols ColRecDecl $ docCommaSep : f
|
, docWrapNodeRest lRec $ docLines $ fDocR <&> \f ->
|
||||||
|
docCols ColRecDecl $ docCommaSep : f
|
||||||
, docLit $ Text.pack "}"
|
, docLit $ Text.pack "}"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -270,12 +277,13 @@ createDetailsDoc consNameStr details = case details of
|
||||||
, layoutType arg2
|
, layoutType arg2
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
mkFieldDocs = fmap $ \case
|
mkFieldDocs :: [LConDeclField GhcPs] -> [[ToBriDocM BriDocNumbered]]
|
||||||
|
mkFieldDocs = fmap $ \lField -> case lField of
|
||||||
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
|
||||||
L _ (ConDeclField _ext names t _) -> createNamesAndTypeDoc names t
|
L _ (ConDeclField _ext names t _) -> createNamesAndTypeDoc lField names t
|
||||||
L _ (XConDeclField x) -> absurdExt x
|
L _ (XConDeclField x) -> absurdExt x
|
||||||
#else
|
#else
|
||||||
L _ (ConDeclField names t _) -> createNamesAndTypeDoc names t
|
L _ (ConDeclField names t _) -> createNamesAndTypeDoc lField names t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
createForallDoc :: [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
|
createForallDoc :: [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
|
||||||
|
@ -288,11 +296,13 @@ createForallDoc lhsTyVarBndrs = docSeq
|
||||||
]
|
]
|
||||||
|
|
||||||
createNamesAndTypeDoc
|
createNamesAndTypeDoc
|
||||||
:: [GenLocated t (FieldOcc GhcPs)]
|
:: Data.Data.Data ast
|
||||||
|
=> Located ast
|
||||||
|
-> [GenLocated t (FieldOcc GhcPs)]
|
||||||
-> Located (HsType GhcPs)
|
-> Located (HsType GhcPs)
|
||||||
-> [ToBriDocM BriDocNumbered]
|
-> [ToBriDocM BriDocNumbered]
|
||||||
createNamesAndTypeDoc names t =
|
createNamesAndTypeDoc lField names t =
|
||||||
[ docSeq
|
[ docNodeAnnKW lField Nothing $ docWrapNodePrior lField $ docSeq
|
||||||
[ docSeq
|
[ docSeq
|
||||||
$ List.intersperse docCommaSep
|
$ List.intersperse docCommaSep
|
||||||
$ names
|
$ names
|
||||||
|
@ -306,7 +316,7 @@ createNamesAndTypeDoc names t =
|
||||||
docLit =<< lrdrNameToTextAnn fieldName
|
docLit =<< lrdrNameToTextAnn fieldName
|
||||||
, docSeparator
|
, docSeparator
|
||||||
]
|
]
|
||||||
, docSeq
|
, docWrapNodeRest lField $ docSeq
|
||||||
[ docLit $ Text.pack "::"
|
[ docLit $ Text.pack "::"
|
||||||
, docSeparator
|
, docSeparator
|
||||||
, layoutType t
|
, layoutType t
|
||||||
|
|
Loading…
Reference in New Issue