Skip to content

Commit c61bbee

Browse files
ezyanghvr
authored andcommitted
Support listing signatures and reexported modules.
This is a partial patch which improves Hackage package description rendering of modules. Now, instead of ignoring reexported-modules and signatures, they get displayed. This is incomplete because: - reexported-module links will always be broken, because we'll be testing for HTML files which will never exist (Haddock doesn't currently generate HTML for reexported modules, although it may in the future.) - Signatures might be inherited from dependencies (and even get Haddock documentation for them), but we won't display them unless they are explicitly listed in signatures. Signed-off-by: Edward Z. Yang <[email protected]> (cherry picked from commit 389d9a4; relates to #577)
1 parent f8e96e0 commit c61bbee

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

Distribution/Server/Packages/Render.hs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Distribution.Server.Packages.Render (
77
, DependencyTree
88
, IsBuildable (..)
99
, doPackageRender
10+
, ModSigIndex(..)
1011

1112
-- * Utils
1213
, categorySplit,
@@ -43,6 +44,11 @@ import Distribution.Server.Users.Types
4344
import qualified Data.TarIndex as TarIndex
4445
import Data.TarIndex (TarIndex, TarEntryOffset)
4546

47+
data ModSigIndex = ModSigIndex {
48+
modIndex :: ModuleForest,
49+
sigIndex :: ModuleForest
50+
}
51+
4652
-- This should provide the caller enough information to encode the package information
4753
-- in its particular format (text, html, json) with minimal effort on its part.
4854
-- This is why some fields of PackageDescription are preprocessed, and others aren't.
@@ -57,7 +63,11 @@ data PackageRender = PackageRender {
5763
rendMaintainer :: Maybe String,
5864
rendCategory :: [String],
5965
rendRepoHeads :: [(RepoType, String, SourceRepo)],
60-
rendModules :: Maybe TarIndex -> Maybe ModuleForest,
66+
-- | The optional 'TarIndex' is of the documentation tarball; we use this
67+
-- to test if a module actually has a corresponding documentation HTML
68+
-- file we can link to. If no 'TarIndex' is provided, it is assumed
69+
-- all links are dead.
70+
rendModules :: Maybe TarIndex -> Maybe ModSigIndex,
6171
rendHasTarball :: Bool,
6272
rendChangeLog :: Maybe (FilePath, ETag, TarEntryOffset, FilePath),
6373
rendReadme :: Maybe (FilePath, ETag, TarEntryOffset, FilePath),
@@ -91,11 +101,7 @@ doPackageRender users info = PackageRender
91101
[] -> []
92102
str -> categorySplit str
93103
, rendRepoHeads = catMaybes (map rendRepo $ sourceRepos desc)
94-
, rendModules = \docindex ->
95-
fmap (moduleForest
96-
. map (\m -> (m, moduleHasDocs docindex m))
97-
. exposedModules)
98-
(library flatDesc)
104+
, rendModules = renderModules
99105
, rendHasTarball = not . Vec.null $ pkgTarballRevisions info
100106
, rendChangeLog = Nothing -- populated later
101107
, rendReadme = Nothing -- populated later
@@ -124,7 +130,18 @@ doPackageRender users info = PackageRender
124130
isBuildable ctData = if buildable $ getBuildInfo ctData
125131
then Buildable
126132
else NotBuildable
127-
133+
134+
renderModules docindex
135+
| Just lib <- library flatDesc
136+
= let mod_ix = mkForest $ exposedModules lib
137+
-- Assumes that there is an HTML per reexport
138+
++ map moduleReexportName (reexportedModules lib)
139+
sig_ix = mkForest $ signatures lib
140+
mkForest = moduleForest . map (\m -> (m, moduleHasDocs docindex m))
141+
in Just (ModSigIndex { modIndex = mod_ix, sigIndex = sig_ix })
142+
| otherwise
143+
= Nothing
144+
128145
moduleHasDocs :: Maybe TarIndex -> ModuleName -> Bool
129146
moduleHasDocs Nothing = const False
130147
moduleHasDocs (Just doctar) = isJust . TarIndex.lookup doctar

Distribution/Server/Pages/Package.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,16 @@ renderPackageFlags render =
275275
moduleSection :: PackageRender -> Maybe TarIndex -> URL -> [Html]
276276
moduleSection render mdocIndex docURL =
277277
maybeToList $ fmap msect (rendModules render mdocIndex)
278-
where msect libModuleForrest = toHtml
279-
[ h2 << "Modules"
280-
, renderModuleForest docURL libModuleForrest
281-
, renderDocIndexLink
282-
]
278+
where msect ModSigIndex{ modIndex = m, sigIndex = s } = toHtml $
279+
(if not (null s)
280+
then [ h2 << "Signatures"
281+
, renderModuleForest docURL s ]
282+
else []) ++
283+
(if not (null m)
284+
then [ h2 << "Modules"
285+
, renderModuleForest docURL m ]
286+
else []) ++
287+
[renderDocIndexLink]
283288
renderDocIndexLink
284289
| isJust mdocIndex =
285290
let docIndexURL = docURL </> "doc-index.html"

0 commit comments

Comments
 (0)