@@ -18,33 +18,36 @@ import Language.PureScript.Docs.RenderedCode
18import Language.PureScript.Docs.Utils.MonoidExtras
18import Language.PureScript.Docs.Utils.MonoidExtras
20renderDeclaration :: Declaration -> RenderedCode
20renderDeclaration :: Declaration -> RenderedCode
21−renderDeclaration Declaration{..} =
21+renderDeclaration = renderDeclarationWithOptions defaultRenderTypeOptions
23+renderDeclarationWithOptions :: RenderTypeOptions -> Declaration -> RenderedCode
24+renderDeclarationWithOptions opts Declaration{..} =
22 mintersperse sp $ case declInfo of
25 mintersperse sp $ case declInfo of
23 ValueDeclaration ty ->
26 ValueDeclaration ty ->
24 [ ident declTitle
27 [ ident declTitle
25 , syntax "::"
28 , syntax "::"
26− , renderType ty
29+ , renderType' ty
28 DataDeclaration dtype args ->
31 DataDeclaration dtype args ->
29 [ keyword (show dtype)
32 [ keyword (show dtype)
30− , renderType (typeApp declTitle args)
33+ , renderType' (typeApp declTitle args)
32 ExternDataDeclaration kind' ->
35 ExternDataDeclaration kind' ->
33 [ keywordData
36 [ keywordData
34− , renderType (P.TypeConstructor (notQualified declTitle))
37+ , renderType' (P.TypeConstructor (notQualified declTitle))
35 , syntax "::"
38 , syntax "::"
36 , renderKind kind'
39 , renderKind kind'
38 TypeSynonymDeclaration args ty ->
41 TypeSynonymDeclaration args ty ->
39 [ keywordType
42 [ keywordType
40− , renderType (typeApp declTitle args)
43+ , renderType' (typeApp declTitle args)
41 , syntax "="
44 , syntax "="
42− , renderType ty
45+ , renderType' ty
44 TypeClassDeclaration args implies ->
47 TypeClassDeclaration args implies ->
45 [ keywordClass ]
48 [ keywordClass ]
46 ++ maybe [] (:[]) superclasses
49 ++ maybe [] (:[]) superclasses
47− ++ [renderType (typeApp declTitle args)]
50+ ++ [renderType' (typeApp declTitle args)]
48 ++ if any (isTypeClassMember . cdeclInfo) declChildren
51 ++ if any (isTypeClassMember . cdeclInfo) declChildren
49 then [keywordWhere]
52 then [keywordWhere]
@@ -59,28 +62,23 @@ renderDeclaration Declaration{..} =
60 isTypeClassMember (ChildTypeClassMember _) = True
63 isTypeClassMember (ChildTypeClassMember _) = True
61 isTypeClassMember _ = False
64 isTypeClassMember _ = False
66+ renderType' = renderTypeWithOptions opts
63renderChildDeclaration :: ChildDeclaration -> RenderedCode
68renderChildDeclaration :: ChildDeclaration -> RenderedCode
64−renderChildDeclaration ChildDeclaration{..} =
69+renderChildDeclaration = renderChildDeclarationWithOptions defaultRenderTypeOptions
71+renderChildDeclarationWithOptions :: RenderTypeOptions -> ChildDeclaration -> RenderedCode
72+renderChildDeclarationWithOptions opts ChildDeclaration{..} =
65 mintersperse sp $ case cdeclInfo of
73 mintersperse sp $ case cdeclInfo of
66 ChildInstance constraints ty ->
74 ChildInstance constraints ty ->
67 [ keywordInstance
75 [ keywordInstance
68 , ident cdeclTitle
76 , ident cdeclTitle
69 , syntax "::"
77 , syntax "::"
70− ] ++ maybe [] (:[]) constraints'
78+ ] ++ maybe [] (:[]) (renderConstraints constraints)
71− ++ [ renderType ty ]
79+ ++ [ renderType' ty ]
74− | null constraints = Nothing
77− <> renderedConstraints
78− <> syntax ")" <> sp <> syntax "=>"
80− renderedConstraints = mintersperse (syntax "," <> sp)
81− (map renderConstraint constraints)
82 ChildDataConstructor args ->
80 ChildDataConstructor args ->
83− [ renderType typeApp' ]
81+ [ renderType' typeApp' ]
85 typeApp' = foldl P.TypeApp ctor' args
83 typeApp' = foldl P.TypeApp ctor' args
86 ctor' = P.TypeConstructor (notQualified cdeclTitle)
84 ctor' = P.TypeConstructor (notQualified cdeclTitle)
@@ -88,12 +86,32 @@ renderChildDeclaration ChildDeclaration{..} =
88 ChildTypeClassMember ty ->
86 ChildTypeClassMember ty ->
89 [ ident cdeclTitle
87 [ ident cdeclTitle
90 , syntax "::"
88 , syntax "::"
91− , renderType ty
89+ , renderType' ty
92+ renderType' = renderTypeWithOptions opts
94renderConstraint :: (P.Qualified P.ProperName, [P.Type]) -> RenderedCode
94renderConstraint :: (P.Qualified P.ProperName, [P.Type]) -> RenderedCode
95−renderConstraint (pn, tys) =
95+renderConstraint = renderConstraintWithOptions defaultRenderTypeOptions
97+renderConstraintWithOptions :: RenderTypeOptions -> (P.Qualified P.ProperName, [P.Type]) -> RenderedCode
98+renderConstraintWithOptions opts (pn, tys) =
96− renderType $ foldl P.TypeApp (P.TypeConstructor pn) tys
99+ renderTypeWithOptions opts $ foldl P.TypeApp (P.TypeConstructor pn) tys
101+renderConstraints :: [P.Constraint] -> Maybe RenderedCode
102+renderConstraints = renderConstraintsWithOptions defaultRenderTypeOptions
104+renderConstraintsWithOptions :: RenderTypeOptions -> [P.Constraint] -> Maybe RenderedCode
105+renderConstraintsWithOptions opts constraints
106+ | null constraints = Nothing
107+ | otherwise = Just $
109+ <> renderedConstraints
110+ <> syntax ")" <> sp <> syntax "=>"
112+ renderedConstraints =
113+ mintersperse (syntax "," <> sp)
114+ (map (renderConstraintWithOptions opts) constraints)
98notQualified :: String -> P.Qualified P.ProperName
116notQualified :: String -> P.Qualified P.ProperName
99notQualified = P.Qualified Nothing . P.ProperName
117notQualified = P.Qualified Nothing . P.ProperName