aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Backends/Hoogle.hs
diff options
context:
space:
mode:
Diffstat (limited to 'haddock-api/src/Haddock/Backends/Hoogle.hs')
-rw-r--r--haddock-api/src/Haddock/Backends/Hoogle.hs29
1 files changed, 22 insertions, 7 deletions
diff --git a/haddock-api/src/Haddock/Backends/Hoogle.hs b/haddock-api/src/Haddock/Backends/Hoogle.hs
index 2c7be079..9a31428f 100644
--- a/haddock-api/src/Haddock/Backends/Hoogle.hs
+++ b/haddock-api/src/Haddock/Backends/Hoogle.hs
@@ -129,6 +129,7 @@ ppExport dflags ExportDecl { expItemDecl = L _ decl
f (TyClD _ d@DataDecl{}) = ppData dflags d subdocs
f (TyClD _ d@SynDecl{}) = ppSynonym dflags d
f (TyClD _ d@ClassDecl{}) = ppClass dflags d subdocs
+ f (TyClD _ (FamDecl _ d)) = ppFam dflags d
f (ForD _ (ForeignImport _ name typ _)) = [pp_sig dflags [name] (hsSigType typ)]
f (ForD _ (ForeignExport _ name typ _)) = [pp_sig dflags [name] (hsSigType typ)]
f (SigD _ sig) = ppSig dflags sig ++ ppFixities
@@ -141,11 +142,7 @@ ppSigWithDoc :: DynFlags -> Sig GhcRn -> [(Name, DocForDecl Name)] -> [String]
ppSigWithDoc dflags (TypeSig _ names sig) subdocs
= concatMap mkDocSig names
where
- mkDocSig n = concatMap (ppDocumentation dflags) (getDoc n)
- ++ [pp_sig dflags names (hsSigWcType sig)]
-
- getDoc :: Located Name -> [Documentation Name]
- getDoc n = maybe [] (return . fst) (lookup (unL n) subdocs)
+ mkDocSig n = mkSubdoc dflags n subdocs [pp_sig dflags [n] (hsSigWcType sig)]
ppSigWithDoc _ _ _ = []
@@ -173,10 +170,14 @@ ppClass dflags decl subdocs =
ppTyFams
| null $ tcdATs decl = ""
| otherwise = (" " ++) . showSDocUnqual dflags . whereWrapper $ concat
- [ map ppr (tcdATs decl)
+ [ map pprTyFam (tcdATs decl)
, map (ppr . tyFamEqnToSyn . unLoc) (tcdATDefs decl)
]
+ pprTyFam :: LFamilyDecl GhcRn -> SDoc
+ pprTyFam (L _ at) = vcat' $ map text $
+ mkSubdoc dflags (fdLName at) subdocs (ppFam dflags at)
+
whereWrapper elems = vcat'
[ text "where" <+> lbrace
, nest 4 . vcat . map (Outputable.<> semi) $ elems
@@ -192,6 +193,15 @@ ppClass dflags decl subdocs =
, tcdSExt = emptyNameSet
}
+ppFam :: DynFlags -> FamilyDecl GhcRn -> [String]
+ppFam dflags decl@(FamilyDecl { fdInfo = info })
+ = [out dflags decl']
+ where
+ decl' = case info of
+ -- We don't need to print out a closed type family's equations
+ -- for Hoogle, so pretend it doesn't have any.
+ ClosedTypeFamily{} -> decl { fdInfo = OpenTypeFamily }
+ _ -> decl
ppInstance :: DynFlags -> ClsInst -> [String]
ppInstance dflags x =
@@ -286,6 +296,10 @@ docWith dflags header d
lines header ++ ["" | header /= "" && isJust d] ++
maybe [] (showTags . markup (markupTag dflags)) d
+mkSubdoc :: DynFlags -> Located Name -> [(Name, DocForDecl Name)] -> [String] -> [String]
+mkSubdoc dflags n subdocs s = concatMap (ppDocumentation dflags) getDoc ++ s
+ where
+ getDoc = maybe [] (return . fst) (lookup (unL n) subdocs)
data Tag = TagL Char [Tags] | TagP Tags | TagPre Tags | TagInline String Tags | Str String
deriving Show
@@ -329,7 +343,8 @@ markupTag dflags = Markup {
markupAName = const $ str "",
markupProperty = box TagPre . str,
markupExample = box TagPre . str . unlines . map exampleToString,
- markupHeader = \(Header l h) -> box (TagInline $ "h" ++ show l) h
+ markupHeader = \(Header l h) -> box (TagInline $ "h" ++ show l) h,
+ markupTable = \(Table _ _) -> str "TODO: table"
}