diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-10-16 17:42:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-16 17:42:05 -0700 |
commit | b21c806740fd41e3fd25e17edc412aa69825611d (patch) | |
tree | 4457746fa503bac1be194ea27a220a88f43a6d73 | |
parent | 99253fd790dde6fd3d3622bd58a24d09a78b7ec4 (diff) |
Output pattern synonyms in Hoogle backend (#947)
* Output pattern synonyms in Hoogle backend
We were previously weren't outputting _any_ pattern synonyms, bundled or
not. Now, we output both.
Fixes #946.
* Update changelog
-rw-r--r-- | CHANGES.md | 2 | ||||
-rw-r--r-- | haddock-api/src/Haddock/Backends/Hoogle.hs | 21 | ||||
-rw-r--r-- | hoogle-test/ref/Bug946/test.txt | 19 | ||||
-rw-r--r-- | hoogle-test/src/Bug946/Bug946.hs | 16 |
4 files changed, 50 insertions, 8 deletions
@@ -4,6 +4,8 @@ * Support type and data families in the LaTeX backend (#734) + * Support pattern synonyms in the Hoogle backend (#947) + ## Changes in version 2.21.0 * Overhaul handling of data declarations in XHTML and LaTeX. Adds support for diff --git a/haddock-api/src/Haddock/Backends/Hoogle.hs b/haddock-api/src/Haddock/Backends/Hoogle.hs index 885c608b..5f77c38c 100644 --- a/haddock-api/src/Haddock/Backends/Hoogle.hs +++ b/haddock-api/src/Haddock/Backends/Hoogle.hs @@ -122,10 +122,14 @@ commaSeparate dflags = showSDocUnqual dflags . interpp'SP ppExport :: DynFlags -> ExportItem GhcRn -> [String] ppExport dflags ExportDecl { expItemDecl = L _ decl - , expItemMbDoc = (dc, _) + , expItemPats = bundledPats + , expItemMbDoc = mbDoc , expItemSubDocs = subdocs , expItemFixities = fixities - } = ppDocumentation dflags dc ++ f decl ++ ppFixities + } = concat [ ppDocumentation dflags dc ++ f d + | (d, (dc, _)) <- (decl, mbDoc) : bundledPats + ] ++ + ppFixities where f (TyClD _ d@DataDecl{}) = ppData dflags d subdocs f (TyClD _ d@SynDecl{}) = ppSynonym dflags d @@ -140,12 +144,13 @@ ppExport dflags ExportDecl { expItemDecl = L _ decl ppExport _ _ = [] ppSigWithDoc :: DynFlags -> Sig GhcRn -> [(Name, DocForDecl Name)] -> [String] -ppSigWithDoc dflags (TypeSig _ names sig) subdocs - = concatMap mkDocSig names - where - mkDocSig n = mkSubdoc dflags n subdocs [pp_sig dflags [n] (hsSigWcType sig)] - -ppSigWithDoc _ _ _ = [] +ppSigWithDoc dflags sig subdocs = case sig of + TypeSig _ names t -> concatMap (mkDocSig "" (hsSigWcType t)) names + PatSynSig _ names t -> concatMap (mkDocSig "pattern " (hsSigType t)) names + _ -> [] + where + mkDocSig leader typ n = mkSubdoc dflags n subdocs + [leader ++ pp_sig dflags [n] typ] ppSig :: DynFlags -> Sig GhcRn -> [String] ppSig dflags x = ppSigWithDoc dflags x [] diff --git a/hoogle-test/ref/Bug946/test.txt b/hoogle-test/ref/Bug946/test.txt new file mode 100644 index 00000000..ff63a766 --- /dev/null +++ b/hoogle-test/ref/Bug946/test.txt @@ -0,0 +1,19 @@ +-- Hoogle documentation, generated by Haddock +-- See Hoogle, http://www.haskell.org/hoogle/ + +@package test +@version 0.0.0 + +module Bug946 + +-- | A wrapper around <a>Int</a> +data AnInt + +-- | some <a>Int</a> +AnInt :: Int -> AnInt + +-- | The <a>Int</a> 0 +pattern Zero :: AnInt + +-- | The double 2.5 +pattern TwoPointFive :: Double diff --git a/hoogle-test/src/Bug946/Bug946.hs b/hoogle-test/src/Bug946/Bug946.hs new file mode 100644 index 00000000..606b5ac4 --- /dev/null +++ b/hoogle-test/src/Bug946/Bug946.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE PatternSynonyms #-} +module Bug946 ( + AnInt(AnInt, Zero), + pattern TwoPointFive, +) where + +-- | A wrapper around 'Int' +data AnInt = AnInt Int -- ^ some 'Int' + +-- | The 'Int' 0 +pattern Zero :: AnInt +pattern Zero = AnInt 0 + +-- | The double 2.5 +pattern TwoPointFive :: Double +pattern TwoPointFive = 2.5 |