Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Small fixes #1045

Merged
merged 4 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
/latex-test/out/
/hoogle-test/out/

*.o
*.hi
*.dyn_o
*.dyn_hi
*.hp

/doc/haddock
/doc/haddock.ps
/doc/haddock.pdf
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

* `--show-interface` now outputs to stdout (instead of stderr)

* Render associated type defaults and also improve rendering of
default method signatures

* Many fixes to the LaTeX backend, mostly focused on not crashing
as well as generating LaTeX source that compiles

## Changes in version 2.22.0

* Make `--package-version` optional for `--hoogle` (#899)
Expand Down
261 changes: 141 additions & 120 deletions haddock-api/src/Haddock/Backends/LaTeX.hs

Large diffs are not rendered by default.

99 changes: 71 additions & 28 deletions haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Text.XHtml hiding ( name, title, p, quote )

import BasicTypes (PromotionFlag(..), isPromoted)
import GHC hiding (LexicalFixity(..))
import qualified GHC
import GHC.Exts
import Name
import BooleanFormula
Expand Down Expand Up @@ -75,14 +76,14 @@ ppLFunSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName ->
[Located DocName] -> LHsType DocNameI -> [(DocName, Fixity)] ->
Splice -> Unicode -> Maybe Package -> Qualification -> Html
ppLFunSig summary links loc doc lnames lty fixities splice unicode pkg qual =
ppFunSig summary links loc doc (map unLoc lnames) lty fixities
ppFunSig summary links loc noHtml doc (map unLoc lnames) lty fixities
splice unicode pkg qual

ppFunSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName ->
ppFunSig :: Bool -> LinksInfo -> SrcSpan -> Html -> DocForDecl DocName ->
[DocName] -> LHsType DocNameI -> [(DocName, Fixity)] ->
Splice -> Unicode -> Maybe Package -> Qualification -> Html
ppFunSig summary links loc doc docnames typ fixities splice unicode pkg qual =
ppSigLike summary links loc mempty doc docnames fixities (unLoc typ, pp_typ)
ppFunSig summary links loc leader doc docnames typ fixities splice unicode pkg qual =
ppSigLike summary links loc leader doc docnames fixities (unLoc typ, pp_typ)
splice unicode pkg qual HideEmptyContexts
where
pp_typ = ppLType unicode qual HideEmptyContexts typ
Expand Down Expand Up @@ -218,7 +219,7 @@ ppFor :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName
-> Splice -> Unicode -> Maybe Package -> Qualification -> Html
ppFor summary links loc doc (ForeignImport _ (L _ name) typ _) fixities
splice unicode pkg qual
= ppFunSig summary links loc doc [name] (hsSigType typ) fixities splice unicode pkg qual
= ppFunSig summary links loc noHtml doc [name] (hsSigType typ) fixities splice unicode pkg qual
ppFor _ _ _ _ _ _ _ _ _ _ = error "ppFor"


Expand Down Expand Up @@ -496,7 +497,7 @@ ppShortClassDecl summary links (ClassDecl { tcdCtxt = lctxt, tcdLName = lname, t

-- ToDo: add associated type defaults

[ ppFunSig summary links loc doc names (hsSigType typ)
[ ppFunSig summary links loc noHtml doc names (hsSigType typ)
[] splice unicode pkg qual
| L _ (ClassOpSig _ False lnames typ) <- sigs
, let doc = lookupAnySubdoc (head names) subdocs
Expand All @@ -517,8 +518,9 @@ ppClassDecl :: Bool -> LinksInfo -> [DocInstance DocNameI] -> [(DocName, Fixity)
-> [(DocName, DocForDecl DocName)] -> TyClDecl DocNameI
-> Splice -> Unicode -> Maybe Package -> Qualification -> Html
ppClassDecl summary links instances fixities loc d subdocs
decl@(ClassDecl { tcdCtxt = lctxt, tcdLName = lname, tcdTyVars = ltyvars
, tcdFDs = lfds, tcdSigs = lsigs, tcdATs = ats })
decl@(ClassDecl { tcdCtxt = lctxt, tcdLName = lname@(L _ nm)
, tcdTyVars = ltyvars, tcdFDs = lfds, tcdSigs = lsigs
, tcdATs = ats, tcdATDefs = atsDefs })
splice unicode pkg qual
| summary = ppShortClassDecl summary links decl loc subdocs splice unicode pkg qual
| otherwise = classheader +++ docSection curname pkg qual d
Expand All @@ -535,28 +537,68 @@ ppClassDecl summary links instances fixities loc d subdocs
-- Only the fixity relevant to the class header
fixs = ppFixities [ f | f@(n,_) <- fixities, n == unLoc lname ] qual

nm = tcdName decl

hdr = ppClassHdr summary lctxt (unLoc lname) ltyvars lfds

-- ToDo: add assocatied typ defaults
atBit = subAssociatedTypes [ ppAssocType summary links doc at subfixs splice unicode pkg qual
| at <- ats
, let n = unL . fdLName $ unL at
doc = lookupAnySubdoc (unL $ fdLName $ unL at) subdocs
subfixs = [ f | f@(n',_) <- fixities, n == n' ] ]

methodBit = subMethods [ ppFunSig summary links loc doc [name] (hsSigType typ)
subfixs splice unicode pkg qual
| L _ (ClassOpSig _ _ lnames typ) <- lsigs
, name <- map unLoc lnames
, let doc = lookupAnySubdoc name subdocs
subfixs = [ f | f@(n',_) <- fixities
, name == n' ]
]
-- N.B. taking just the first name is ok. Signatures with multiple names
-- are expanded so that each name gets its own signature.
-- Associated types
atBit = subAssociatedTypes
[ ppAssocType summary links doc at subfixs splice unicode pkg qual
<+>
subDefaults (maybeToList defTys)
| at <- ats
, let name = unL . fdLName $ unL at
doc = lookupAnySubdoc name subdocs
subfixs = filter ((== name) . fst) fixities
defTys = ppDefaultAssocTy name <$> lookupDAT name
]

-- Default associated types
ppDefaultAssocTy n (vs,t,d') = ppTySyn summary links [] loc d' synDecl
splice unicode pkg qual
where
synDecl = SynDecl { tcdSExt = noExt
, tcdLName = noLoc n
, tcdTyVars = vs
, tcdFixity = GHC.Prefix
, tcdRhs = t }

lookupDAT name = Map.lookup (getName name) defaultAssocTys
defaultAssocTys = Map.fromList
[ (getName name, (vs, typ, doc))
| L _ (FamEqn { feqn_rhs = typ
, feqn_tycon = L _ name
, feqn_pats = vs }) <- atsDefs
, let doc = noDocForDecl -- TODO: get docs for associated type defaults
]

-- Methods
methodBit = subMethods
[ ppFunSig summary links loc noHtml doc [name] (hsSigType typ)
subfixs splice unicode pkg qual
<+>
subDefaults (maybeToList defSigs)
| ClassOpSig _ False lnames typ <- sigs
, name <- map unLoc lnames
, let doc = lookupAnySubdoc name subdocs
subfixs = filter ((== name) . fst) fixities
defSigs = ppDefaultFunSig name <$> lookupDM name
]
-- N.B. taking just the first name is ok. Signatures with multiple names
-- are expanded so that each name gets its own signature.

-- Default methods
ppDefaultFunSig n (t, d') = ppFunSig summary links loc (keyword "default")
d' [n] (hsSigType t) [] splice unicode pkg qual

lookupDM name = Map.lookup (getOccString name) defaultMethods
defaultMethods = Map.fromList
[ (nameStr, (typ, doc))
| ClassOpSig _ True lnames typ <- sigs
, name <- map unLoc lnames
, let doc = noDocForDecl -- TODO: get docs for method defaults
nameStr = getOccString name
]

-- Minimal complete definition
minimalBit = case [ s | MinimalSig _ _ (L _ s) <- sigs ] of
-- Miminal complete definition = every shown method
And xs : _ | sort [getName n | L _ (Var (L _ n)) <- xs] ==
Expand All @@ -565,7 +607,7 @@ ppClassDecl summary links instances fixities loc d subdocs

-- Minimal complete definition = the only shown method
Var (L _ n) : _ | [getName n] ==
[getName n' | L _ (ClassOpSig _ _ ns _) <- lsigs, L _ n' <- ns]
[getName n' | ClassOpSig _ _ ns _ <- sigs, L _ n' <- ns]
-> noHtml

-- Minimal complete definition = nothing
Expand All @@ -580,6 +622,7 @@ ppClassDecl summary links instances fixities loc d subdocs
where wrap | p = parens | otherwise = id
ppMinimal p (Parens x) = ppMinimal p (unLoc x)

-- Instances
instancesBit = ppInstances links (OriginClass nm) instances
splice unicode pkg qual

Expand Down
4 changes: 4 additions & 0 deletions haddock-api/src/Haddock/Backends/Xhtml/Layout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Haddock.Backends.Xhtml.Layout (
subInstances, subOrphanInstances,
subInstHead, subInstDetails, subFamInstDetails,
subMethods,
subDefaults,
subMinimal,

topDeclElem, declElem,
Expand Down Expand Up @@ -259,6 +260,9 @@ instAnchorId iid = makeAnchorId $ "i:" ++ iid
subMethods :: [Html] -> Html
subMethods = divSubDecls "methods" "Methods" . subBlock

subDefaults :: [Html] -> Html
subDefaults = divSubDecls "default" "" . subBlock

subMinimal :: Html -> Html
subMinimal = divSubDecls "minimal" "Minimal complete definition" . Just . declElem

Expand Down
3 changes: 3 additions & 0 deletions haddock-api/src/Haddock/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ showWrapped f (Unadorned n) = f n
showWrapped f (Parenthesized n) = "(" ++ f n ++ ")"
showWrapped f (Backticked n) = "`" ++ f n ++ "`"

instance HasOccName DocName where

occName = occName . getName

-----------------------------------------------------------------------------
-- * Instances
Expand Down
158 changes: 158 additions & 0 deletions html-test/ref/DefaultAssociatedTypes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<html xmlns="http://www.w3.org/1999/xhtml"
><head
><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
/><meta name="viewport" content="width=device-width, initial-scale=1"
/><title
>DefaultAssociatedTypes</title
><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
/><link rel="stylesheet" type="text/css" href="#"
/><link rel="stylesheet" type="text/css" href="#"
/><script src="haddock-bundle.min.js" async="async" type="text/javascript"
></script
><script type="text/x-mathjax-config"
>MathJax.Hub.Config({ tex2jax: { processClass: &quot;mathjax&quot;, ignoreClass: &quot;.*&quot; } });</script
><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
></script
></head
><body
><div id="package-header"
><span class="caption empty"
></span
><ul class="links" id="page-menu"
><li
><a href="#"
>Contents</a
></li
><li
><a href="#"
>Index</a
></li
></ul
></div
><div id="content"
><div id="module-header"
><table class="info"
><tr
><th
>Safe Haskell</th
><td
>Safe</td
></tr
></table
><p class="caption"
>DefaultAssociatedTypes</p
></div
><div id="synopsis"
><details id="syn"
><summary
>Synopsis</summary
><ul class="details-toggle" data-details-id="syn"
><li class="src short"
><span class="keyword"
>class</span
> <a href="#"
>Foo</a
> a <span class="keyword"
>where</span
><ul class="subs"
><li
><span class="keyword"
>type</span
> <a href="#"
>Qux</a
> a :: *</li
><li
><a href="#"
>bar</a
>, <a href="#"
>baz</a
> :: a -&gt; <a href="#" title="Data.String"
>String</a
></li
></ul
></li
></ul
></details
></div
><div id="interface"
><h1
>Documentation</h1
><div class="top"
><p class="src"
><span class="keyword"
>class</span
> <a id="t:Foo" class="def"
>Foo</a
> a <span class="keyword"
>where</span
> <a href="#" class="selflink"
>#</a
></p
><div class="doc"
><p
>Documentation for Foo.</p
></div
><div class="subs associated-types"
><p class="caption"
>Associated Types</p
><p class="src"
><span class="keyword"
>type</span
> <a id="t:Qux" class="def"
>Qux</a
> a :: * <a href="#" class="selflink"
>#</a
></p
><div class="doc"
><p
>Doc for Qux</p
></div
> <div class="subs default"
><p class="caption"
></p
><p class="src"
><span class="keyword"
>type</span
> <a id="t:Qux" class="def"
>Qux</a
> a = [a] <a href="#" class="selflink"
>#</a
></p
></div
></div
><div class="subs methods"
><p class="caption"
>Methods</p
><p class="src"
><a id="v:bar" class="def"
>bar</a
> :: a -&gt; <a href="#" title="Data.String"
>String</a
> <a href="#" class="selflink"
>#</a
></p
><div class="doc"
><p
>Documentation for bar and baz.</p
></div
><p class="src"
><a id="v:baz" class="def"
>baz</a
> :: a -&gt; <a href="#" title="Data.String"
>String</a
> <a href="#" class="selflink"
>#</a
></p
><div class="doc"
><p
>Documentation for bar and baz.</p
></div
></div
></div
></div
></div
><div id="footer"
></div
></body
></html
>
Loading