Skip to content

Commit bc3cc4e

Browse files
committed
only render else if declaration is shown in typeclass
1 parent d1a547e commit bc3cc4e

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/Language/PureScript/Docs/AsHtml.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,19 @@ declAsHtml r d@Declaration{..} = do
155155

156156
unless (null dctors) $ do
157157
h4 "Constructors"
158-
renderChildren r dctors
158+
renderChildren isTypeClassDecl r dctors
159159

160160
unless (null members) $ do
161161
h4 "Members"
162-
renderChildren r members
162+
renderChildren isTypeClassDecl r members
163163

164164
unless (null instances) $ do
165165
h4 "Instances"
166-
renderChildren r instances
166+
renderChildren isTypeClassDecl r instances
167167
where
168+
isTypeClassDecl = case declInfo of
169+
TypeClassDeclaration{} -> True
170+
_ -> False
168171
linkToSource :: HtmlRenderContext -> P.SourceSpan -> Html
169172
linkToSource ctx srcspan =
170173
maybe (return ()) go (renderSourceLink ctx srcspan)
@@ -173,9 +176,9 @@ declAsHtml r d@Declaration{..} = do
173176
H.span ! A.class_ "decl__source" $
174177
a ! A.href (v href) $ text "Source"
175178

176-
renderChildren :: HtmlRenderContext -> [ChildDeclaration] -> Html
177-
renderChildren _ [] = return ()
178-
renderChildren r xs = ul $ mapM_ item xs
179+
renderChildren :: Bool -> HtmlRenderContext -> [ChildDeclaration] -> Html
180+
renderChildren _ _ [] = return ()
181+
renderChildren isInTypeClass r xs = ul $ mapM_ item xs
179182
where
180183
item decl =
181184
li ! A.id (v (T.drop 1 (fragment decl))) $ do
@@ -184,7 +187,7 @@ renderChildren r xs = ul $ mapM_ item xs
184187
H.div ! A.class_ "decl__child_comments" $ renderMarkdown coms
185188

186189
fragment decl = makeFragment (childDeclInfoNamespace (cdeclInfo decl)) (cdeclTitle decl)
187-
renderCode = code . codeAsHtml r . Render.renderChildDeclaration
190+
renderCode = code . codeAsHtml r . Render.renderChildDeclaration isInTypeClass
188191

189192
codeAsHtml :: HtmlRenderContext -> RenderedCode -> Html
190193
codeAsHtml r = outputWith elemAsHtml

src/Language/PureScript/Docs/AsMarkdown.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,20 @@ declAsMarkdown decl@Declaration{..} = do
4545
let (instances, children) = partition (isChildInstance . cdeclInfo) declChildren
4646
fencedBlock $ do
4747
tell' (codeToString $ Render.renderDeclaration decl)
48-
zipWithM_ (\f c -> tell' (childToString f c)) (First : repeat NotFirst) children
48+
zipWithM_ (\f c -> tell' (childToString isTypeClassDecl f c)) (First : repeat NotFirst) children
4949
spacer
5050

5151
for_ declComments tell'
5252

5353
unless (null instances) $ do
5454
headerLevel 5 "Instances"
55-
fencedBlock $ mapM_ (tell' . childToString NotFirst) instances
55+
fencedBlock $ mapM_ (tell' . childToString isTypeClassDecl NotFirst) instances
5656
spacer
5757

5858
where
59+
isTypeClassDecl = case declInfo of
60+
TypeClassDeclaration{} -> True
61+
_ -> False
5962
isChildInstance (ChildInstance _ _ _) = True
6063
isChildInstance _ = False
6164

@@ -81,8 +84,8 @@ codeToString = outputWith elemAsMarkdown
8184
-- P.Infixr -> "right-associative"
8285
-- P.Infix -> "non-associative"
8386

84-
childToString :: First -> ChildDeclaration -> Text
85-
childToString f decl@ChildDeclaration{..} =
87+
childToString :: Bool -> First -> ChildDeclaration -> Text
88+
childToString inTypeClass f decl@ChildDeclaration{..} =
8689
case cdeclInfo of
8790
ChildDataConstructor _ ->
8891
let c = if f == First then "=" else "|"
@@ -92,7 +95,7 @@ childToString f decl@ChildDeclaration{..} =
9295
ChildInstance _ _ _ ->
9396
str
9497
where
95-
str = codeToString $ Render.renderChildDeclaration decl
98+
str = codeToString $ Render.renderChildDeclaration inTypeClass decl
9699

97100
data First
98101
= First

src/Language/PureScript/Docs/Render.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ renderDeclaration Declaration{..} =
8585
, kind (notQualified declTitle)
8686
]
8787

88-
renderChildDeclaration :: ChildDeclaration -> RenderedCode
89-
renderChildDeclaration ChildDeclaration{..} =
88+
renderChildDeclaration :: Bool -> ChildDeclaration -> RenderedCode
89+
renderChildDeclaration isInTypeClassContext ChildDeclaration{..} =
9090
mintersperse sp $ case cdeclInfo of
9191
ChildInstance constraints ty inChain ->
92-
(if inChain then [keywordElse] else []) ++ maybeToList (renderConstraints constraints) ++ [ renderType ty ]
92+
(if inChain && isInTypeClassContext then [keywordElse] else []) ++ maybeToList (renderConstraints constraints) ++ [ renderType ty ]
9393
ChildDataConstructor args ->
9494
[ dataCtor' cdeclTitle ]
9595
++ map renderTypeAtom args

0 commit comments

Comments
 (0)