Skip to content

Commit

Permalink
Support listing signatures and reexported modules.
Browse files Browse the repository at this point in the history
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 <ezyang@mit.edu>
  • Loading branch information
ezyang committed Mar 21, 2017
1 parent 9f49da3 commit 389d9a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
31 changes: 24 additions & 7 deletions Distribution/Server/Packages/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Distribution.Server.Packages.Render (
, DependencyTree
, IsBuildable (..)
, doPackageRender
, ModSigIndex(..)

-- * Utils
, categorySplit,
Expand Down Expand Up @@ -43,6 +44,11 @@ import Distribution.Server.Users.Types
import qualified Data.TarIndex as TarIndex
import Data.TarIndex (TarIndex, TarEntryOffset)

data ModSigIndex = ModSigIndex {
modIndex :: ModuleForest,
sigIndex :: ModuleForest
}

-- This should provide the caller enough information to encode the package information
-- in its particular format (text, html, json) with minimal effort on its part.
-- This is why some fields of PackageDescription are preprocessed, and others aren't.
Expand All @@ -57,7 +63,11 @@ data PackageRender = PackageRender {
rendMaintainer :: Maybe String,
rendCategory :: [String],
rendRepoHeads :: [(RepoType, String, SourceRepo)],
rendModules :: Maybe TarIndex -> Maybe ModuleForest,
-- | The optional 'TarIndex' is of the documentation tarball; we use this
-- to test if a module actually has a corresponding documentation HTML
-- file we can link to. If no 'TarIndex' is provided, it is assumed
-- all links are dead.
rendModules :: Maybe TarIndex -> Maybe ModSigIndex,
rendHasTarball :: Bool,
rendChangeLog :: Maybe (FilePath, ETag, TarEntryOffset, FilePath),
rendReadme :: Maybe (FilePath, ETag, TarEntryOffset, FilePath),
Expand Down Expand Up @@ -91,11 +101,7 @@ doPackageRender users info = PackageRender
[] -> []
str -> categorySplit str
, rendRepoHeads = catMaybes (map rendRepo $ sourceRepos desc)
, rendModules = \docindex ->
fmap (moduleForest
. map (\m -> (m, moduleHasDocs docindex m))
. exposedModules)
(library flatDesc)
, rendModules = renderModules
, rendHasTarball = not . Vec.null $ pkgTarballRevisions info
, rendChangeLog = Nothing -- populated later
, rendReadme = Nothing -- populated later
Expand Down Expand Up @@ -124,7 +130,18 @@ doPackageRender users info = PackageRender
isBuildable ctData = if buildable $ getBuildInfo ctData
then Buildable
else NotBuildable


renderModules docindex
| Just lib <- library flatDesc
= let mod_ix = mkForest $ exposedModules lib
-- Assumes that there is an HTML per reexport
++ map moduleReexportName (reexportedModules lib)
sig_ix = mkForest $ signatures lib
mkForest = moduleForest . map (\m -> (m, moduleHasDocs docindex m))
in Just (ModSigIndex { modIndex = mod_ix, sigIndex = sig_ix })
| otherwise
= Nothing

moduleHasDocs :: Maybe TarIndex -> ModuleName -> Bool
moduleHasDocs Nothing = const False
moduleHasDocs (Just doctar) = isJust . TarIndex.lookup doctar
Expand Down
15 changes: 10 additions & 5 deletions Distribution/Server/Pages/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,16 @@ renderPackageFlags render =
moduleSection :: PackageRender -> Maybe TarIndex -> URL -> [Html]
moduleSection render mdocIndex docURL =
maybeToList $ fmap msect (rendModules render mdocIndex)
where msect libModuleForrest = toHtml
[ h2 << "Modules"
, renderModuleForest docURL libModuleForrest
, renderDocIndexLink
]
where msect ModSigIndex{ modIndex = m, sigIndex = s } = toHtml $
(if not (null s)
then [ h2 << "Signatures"
, renderModuleForest docURL s ]
else []) ++
(if not (null m)
then [ h2 << "Modules"
, renderModuleForest docURL m ]
else []) ++
[renderDocIndexLink]
renderDocIndexLink
| isJust mdocIndex =
let docIndexURL = docURL </> "doc-index.html"
Expand Down

0 comments on commit 389d9a4

Please sign in to comment.