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

[WIP] Hi Haddock #906

Closed
wants to merge 143 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
9b55d12
First steps adjusting to HsDoc
sjakobi Jun 6, 2018
ea274d3
Add hack that creates a HsDoc from a warning
sjakobi Jun 6, 2018
0b1d4e9
Fix renameLDocHsSyn
sjakobi Jun 6, 2018
a29151b
Adjustments for new WarningTxt type
sjakobi Jun 13, 2018
4ce9b69
First progress
sjakobi Jun 7, 2018
369c813
Document how to populate Interface fields
sjakobi Jun 19, 2018
6414442
Resolve type errors with undefineds
sjakobi Jun 20, 2018
0d532db
Use haddock opts from ModIface
sjakobi Jun 21, 2018
ce0fe21
Spread ErrMsgGhc type, add Renamer type
sjakobi Jun 21, 2018
d836aa0
Add TODO for mkWarningMap
sjakobi Jun 21, 2018
8d47a60
rename: Use HasDynFlags ErrMsgGhc instance
sjakobi Jun 21, 2018
14659ba
Use getDynFlags instead of the dflags from ModSummary
sjakobi Jun 21, 2018
2078fdf
rename: Use a Renamer instead of a GlobalRdrEnv
sjakobi Jun 21, 2018
e9b07a1
Adjust processModuleHeader
sjakobi Jun 21, 2018
0dce2f0
Use docs_language and docs_extensions
sjakobi Jun 22, 2018
2b34210
Get module warning
sjakobi Jun 22, 2018
995c5b6
Fill in ifaceDocMap
sjakobi Jun 22, 2018
674bcec
Fill in ifaceArgMap
sjakobi Jun 22, 2018
27d6f66
Fix mkWarningMap, use it
sjakobi Jun 22, 2018
f17fd01
ifaceOrigFilename: Note idea
sjakobi Jun 25, 2018
b692803
ifaceOrigFilename: Won't fix
sjakobi Jun 25, 2018
6448107
Add notes on ifaceOrigFilename
sjakobi Jun 25, 2018
9d70a90
Adjust mkFixMap
sjakobi Jun 26, 2018
3550672
ifaceModuleAliases: Add comment
sjakobi Jun 26, 2018
4ed73c9
Add TODOS
sjakobi Jun 26, 2018
fdde4f5
Get class and family instances via ModDetails
sjakobi Jun 26, 2018
58410ce
Fill in ifaceDeclMap
sjakobi Jun 26, 2018
b982aa5
mkExportItems': Initial scaffolding
sjakobi Jun 26, 2018
6c630ea
Construct export items
sjakobi Jun 27, 2018
2ff77de
Comment on ifaceVisibleEXports
sjakobi Jun 27, 2018
1531eba
Fill in ifaceVisibleExports
sjakobi Jun 27, 2018
f806813
More comments
sjakobi Jun 27, 2018
f40be70
Fill in ifaceHaddockCoverage, add stubs
sjakobi Jun 27, 2018
bb463da
Use createInterface'
sjakobi Jun 28, 2018
23dc246
Add FIXME regarding mkDeclMap
sjakobi Jun 28, 2018
01151b7
Remove %{FILE} syntax for URL customization options
sjakobi Jun 28, 2018
7ed48a7
Pass allWarnings to mkExportItems'
sjakobi Jun 28, 2018
e152a50
Get the semantic module from mi_sig_of
sjakobi Jun 28, 2018
e5e8cf3
ifaceExportItems: Use pruned items
sjakobi Jun 28, 2018
72950eb
createInterface': Remove "Done" labels
sjakobi Jun 28, 2018
5876d75
mkDeclMap: Add FIXME
sjakobi Jun 28, 2018
ee6c7a2
Construct instanceMap
sjakobi Jun 28, 2018
2f7eaf1
Restructure FIXMEs
sjakobi Jun 28, 2018
9dd1c13
Update FIXME
sjakobi Jun 30, 2018
16a2314
Update FIXMEs regarding re-exported modules / aliases
sjakobi Jun 30, 2018
766847e
FIXME: We'll remove the ignore-exports option
sjakobi Jun 30, 2018
66906be
Use docs_splices
sjakobi Jul 2, 2018
f98855c
Use docs_locations
sjakobi Jul 2, 2018
c891fb1
Improve splice handling
sjakobi Jul 2, 2018
fd1dfa0
WIP: Try to skip parsing etc
sjakobi Jul 5, 2018
c14e057
Use load' to make ModIfaces available but skip the version checks
sjakobi Jul 6, 2018
71d2886
availExportItem: Convert error to warning for now
sjakobi Jul 9, 2018
f272c5e
Handle module (re-)exports
sjakobi Jul 11, 2018
959975a
mkDeclMap: Turn off warning
sjakobi Jul 12, 2018
56de53c
availExportItem: Add module name to warning
sjakobi Jul 12, 2018
344b9a1
Remove the --qual=aliased option
sjakobi Jul 12, 2018
51c53c4
Remove the ignore-exports option
sjakobi Jul 12, 2018
076ccda
Fix --show-extensions instead of removing it
sjakobi Jul 12, 2018
9abfe33
WIP: Use hiDecl to construct an ExportItem from an Avail
sjakobi Jul 16, 2018
b01a2cd
Fix Binary instances for InterfaceFile and InstalledInterface
sjakobi Jul 17, 2018
454c93d
Remove comment
sjakobi Jul 18, 2018
046b690
Remove redundant imports
sjakobi Jul 22, 2018
08b68bf
Adjust to new HsDocIdentifier representation
sjakobi Aug 4, 2018
6d17d50
Adjust to new HsDoc' representation
sjakobi Aug 5, 2018
3ddac91
Adjust to new WarningTxt representation
sjakobi Aug 5, 2018
79fed91
extractDecl: Improve error message for catch-all
sjakobi Aug 6, 2018
cf8c433
Remove the old 'createInterface'
sjakobi Aug 12, 2018
ae3e21b
Remove mkDeclMap
sjakobi Aug 12, 2018
d0b908d
Remove use of docs_splices
sjakobi Aug 12, 2018
44682d9
createInterface: Use mi_semantic_module
sjakobi Aug 13, 2018
1e36138
Haddock.withGhc': Document DynFlag settings
sjakobi Aug 13, 2018
0c2fadc
Haddock.Interface: Formatting
sjakobi Aug 13, 2018
816f0dc
createIfaces: Add comment
sjakobi Aug 13, 2018
801abd6
Haddock.Interface: Misc cleanup
sjakobi Aug 13, 2018
b3129e7
Haddock.Interface.Create: Formatting
sjakobi Aug 13, 2018
613768f
createInterface: Add haddocks
sjakobi Aug 13, 2018
2cdc05e
createInterface: Cleanup ModDetails usage
sjakobi Aug 13, 2018
5cb7d3c
createInterface: Formatting
sjakobi Aug 13, 2018
62916e5
createInterface: Re-add comment
sjakobi Aug 13, 2018
447132c
createInterface: Update comment for ifaceTokenizedSrc
sjakobi Aug 13, 2018
ecfa406
mkExportItems: Formatting
sjakobi Aug 13, 2018
a193b04
Remove splice handling which we'll leave to the extended .hie-files
sjakobi Aug 13, 2018
2c074f8
availExportItem: Clarify comment
sjakobi Aug 13, 2018
6e627b8
availExportItem: Remove outdated comment
sjakobi Aug 13, 2018
aca8cc6
availExportItem: Formatting
sjakobi Aug 13, 2018
fb014ff
Haddock.Interface.Create: Reduce diff
sjakobi Aug 13, 2018
3ca8f99
Refactor moduleWarning
sjakobi Aug 13, 2018
eae9c18
Haddock.Interface.Rename: Delete some forgotten comments
sjakobi Aug 14, 2018
51cbcd4
Simplify renameLDocHsSyn
sjakobi Aug 14, 2018
4681d7f
Haddock.Interface.Create: Delete redundant imports
sjakobi Aug 14, 2018
29edbb9
Use 'hiDecl' in 'extractDecl'
harpocrates Aug 15, 2018
c798cf4
Delete dead code-paths (#910)
harpocrates Aug 20, 2018
3b746c8
Remove unused arguments and fields (#911)
harpocrates Aug 20, 2018
a8f64c6
'Deprected' -> 'Deprecated'
harpocrates Aug 21, 2018
a53c131
Detect GADTs properly and no foralls on GADT constructors
harpocrates Aug 21, 2018
e8f9c6d
Tell git to ignore .hi/.dyn_hi files
harpocrates Aug 21, 2018
f177dc4
Hide family result signature when it is 'Type'
harpocrates Aug 21, 2018
edf9ceb
Properly detect 'HsQualTy' in 'synifyType'
harpocrates Aug 22, 2018
4a013ed
Fix parenthesization of contexts in LaTeX
harpocrates Aug 22, 2018
f6a771c
Add kind signatures to tyvars with kind not 'Type'
harpocrates Aug 22, 2018
b128737
Heuristics for hiding more kind signatures
harpocrates Aug 23, 2018
458dd06
Better rendering of unboxed sums/tuples
harpocrates Aug 21, 2018
e0b3a34
Handle promoted tuples in 'synifyType'
harpocrates Aug 21, 2018
edf4a05
Accept test cases
harpocrates Aug 22, 2018
ddf02b6
Properly synify promoted list types
harpocrates Aug 27, 2018
8921adb
Only look at visible types when synifying a 'HsListTy'
harpocrates Sep 3, 2018
bf633b0
Various improvements to synifying Types
harpocrates Sep 4, 2018
6a499a5
Deduce proper order for type variables
harpocrates Sep 4, 2018
1217645
Infer kinds in pattern syns based on kind of TyCon
harpocrates Sep 4, 2018
b590e91
Synify associated type defaults
harpocrates Sep 4, 2018
94332da
Extend variables in scope when synifying
harpocrates Sep 5, 2018
abf15a2
Add example of 'tyCoVarsOfTypeList's behaviour
harpocrates Sep 5, 2018
637e14b
Move 'forall's left on pattern synonym sigs
harpocrates Sep 7, 2018
7c297c6
Fix return kind of polykinded H98 types
harpocrates Sep 7, 2018
0b64fd1
Don't make 'ExportModule's for hidden modules
harpocrates Sep 6, 2018
d37df4d
Add better support for default signatures in class definitions
blmage Oct 12, 2017
0853a6f
Remove unnecessary import
blmage Oct 13, 2017
89df564
Fix filtering to let through default methods...
harpocrates Sep 5, 2018
689b5ea
Render default associated types
harpocrates Sep 5, 2018
b65647e
Patch LaTeX backend support for class methods
harpocrates Sep 5, 2018
218a0b6
Add test cases for default methods sigs
harpocrates Sep 5, 2018
97954c1
Accept default signature test case outputs
harpocrates Sep 11, 2018
ba9176a
Address review comments
harpocrates Sep 11, 2018
5c9ca33
LaTeX and Hoogle backend fixes
harpocrates Sep 11, 2018
ca139d8
Avoid multi-line `emph` in LaTeX backend
harpocrates Sep 9, 2018
0dd8c88
Add newlines after all block elements in LaTeX
harpocrates Sep 9, 2018
2006e69
Properly synify wildcard types
harpocrates Sep 11, 2018
8e06234
Remove heuristics around treating `*` as a kind
harpocrates Sep 8, 2018
d7259c5
Default 'RuntimeRep' arguments unless otherwise specified (#941)
harpocrates Sep 29, 2018
3bccfc1
Hard-code some exports with built-in syntax (#943)
harpocrates Oct 5, 2018
3106301
Merge remote-tracking branch 'ghc-head' into wip/hi-haddock
harpocrates Oct 21, 2018
d10fb12
Load all visible external package modules for instance lookups
harpocrates Aug 23, 2018
5ed76b4
Fix `data (a :: TYPE r) -> (b :: TYPE q)` in GHC.Prim
harpocrates Oct 22, 2018
dd553ed
Silence a warning
sjakobi Oct 23, 2018
cad2ed9
Adjust renaming to new Docs format
sjakobi Oct 24, 2018
3bd504b
Stop using NonDetKeyMap
sjakobi Oct 26, 2018
1713905
hsDocRenamer: Clarify intended usage
sjakobi Oct 26, 2018
9d8554d
Remove some dead code
sjakobi Oct 27, 2018
dea4275
Adjust to changed definition of docs_extensions
sjakobi Nov 10, 2018
17d9720
Merge remote-tracking branch 'origin/ghc-head' into HEAD
sjakobi Jan 5, 2019
cff4abf
synifyType: Properly adjust to visual kind annotation changes
sjakobi Jan 5, 2019
282f174
Merge branch 'ghc-head' into merged-convert-fixes
harpocrates Feb 4, 2019
1ad8a10
Merge pull request #1021 from harpocrates/merged-convert-fixes
harpocrates Mar 8, 2019
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
/latex-test/out/
/hoogle-test/out/

# ignore interface files
*.hi
*.dyn_hi

/doc/haddock
/doc/haddock.ps
/doc/haddock.pdf
Expand Down
5 changes: 2 additions & 3 deletions doc/cheatsheet/haddocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ definitions with "[thing]"
Omit this module from the docs
{-# OPTIONS_HADDOCK prune #-}
Omit definitions without docs
{-# OPTIONS_HADDOCK ignore-exports #-}
Treat this module as though all
top-level items are exported
{-# OPTIONS_HADDOCK not-home #-}
Do not treat this module as the
"home" of identifiers it exports
{-# OPTIONS_HADDOCK show-extensions #-}
Show all enabled LANGUAGE extensions
{-# OPTIONS_HADDOCK print-explicit-runtime-reps #-}
Show all `RuntimeRep` type variables
```

# Grid tables
Expand Down
19 changes: 0 additions & 19 deletions doc/invoking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ The following options are available:
name. Note that for the per-entity URLs this is the name of the
*exporting* module.

- The string ``%F`` or ``%{FILE}`` is replaced by the original
source file name. Note that for the per-entity URLs this is the
name of the *defining* module.

- The string ``%N`` or ``%{NAME}`` is replaced by the name of the
exported value or type. This is only valid for the
:option:`--source-entity` option.
Expand All @@ -264,9 +260,6 @@ The following options are available:

- The string ``%%`` is replaced by ``%``.

For example, if your sources are online under some directory, you
would say ``haddock --source-base=url/ --source-module=url/%F``

If you have html versions of your sources online with anchors for
each type and function name, you would say
``haddock --source-base=url/ --source-module=url/%M.html --source-entity=url/%M.html#%N``
Expand All @@ -277,11 +270,6 @@ The following options are available:
characters in a file name). To replace it with a character c use
``%{MODULE/./c}``.

Similarly, for the ``%{FILE}`` substitution you may want to replace
the ``/`` character in the file names with some other character
(especially for links to colourised entity source code with a shared
css file). To replace it with a character c use ``%{FILE///c}``/

One example of a tool that can generate syntax-highlighted HTML from
your source code, complete with anchors suitable for use from
haddock, is
Expand Down Expand Up @@ -474,13 +462,6 @@ The following options are available:
:option:`-i` or :option:`--read-interface`). This is used to generate a single
contents and/or index for multiple sets of Haddock documentation.

.. option:: --ignore-all-exports

Causes Haddock to behave as if every module has the
``ignore-exports`` attribute (:ref:`module-attrs`). This might be useful for
generating implementation documentation rather than interface
documentation, for example.

.. option:: --hide <module>

Causes Haddock to behave as if module module has the ``hide``
Expand Down
13 changes: 7 additions & 6 deletions doc/markup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ specified in a comma-separated list in an
``{-# OPTIONS_HADDOCK ... #-}`` pragma at the top of the module, either
before or after the module description. For example: ::

{-# OPTIONS_HADDOCK hide, prune, ignore-exports #-}
{-# OPTIONS_HADDOCK hide, prune #-}

-- |Module description
module A where
Expand All @@ -768,11 +768,6 @@ The following attributes are currently understood by Haddock:
Omit definitions that have no documentation annotations from the
generated documentation.

``ignore-exports``
Ignore the export list. Generate documentation as if the module had
no export list - i.e. all the top-level declarations are exported,
and section headings may be given in the body of the module.

``not-home``
Indicates that the current module should not be considered to be the
home module for each entity it exports, unless that entity is not
Expand All @@ -787,6 +782,12 @@ The following attributes are currently understood by Haddock:
be rendered, including those implied by their more powerful
versions.

``print-explicit-runtime-reps``
Print type variables that have kind ``RuntimeRep``. By default, these
are defaulted to ``LiftedRep`` so that end users don't have to see the
underlying levity polymorphism. This flag is analogous to GHC's
``-fprint-explicit-runtime-reps`` flag.

.. _markup:

Markup
Expand Down
1 change: 0 additions & 1 deletion haddock-api/src/Documentation/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module Documentation.Haddock (
DocMarkupH(..),
Documentation(..),
ArgMap,
AliasMap,
WarningMap,
DocMap,
HaddockModInfo(..),
Expand Down
15 changes: 13 additions & 2 deletions haddock-api/src/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,19 @@ withGhc' libDir needHieFiles flags ghcActs = runGhc (Just libDir) $ do
parseGhcFlags dynflags = do
-- TODO: handle warnings?

let extra_opts | needHieFiles = [Opt_WriteHie, Opt_Haddock]
| otherwise = [Opt_Haddock]
let extra_opts =
[ Opt_Haddock
-- Include docstrings in .hi-files.

, Opt_SkipIfaceVersionCheck
-- Ignore any aspects of .hi-files except docs.

, Opt_WriteInterface
-- If we can't use an old .hi-file, save the new one.
] ++
[ Opt_WriteHie | needHieFiles
-- Generate .hie-files
]
dynflags' = (foldl' gopt_set dynflags extra_opts)
{ hscTarget = HscNothing
, ghcMode = CompManager
Expand Down
9 changes: 7 additions & 2 deletions haddock-api/src/Haddock/Backends/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ ppCtor dflags dat subdocs con@ConDeclH98 {}
-- docs for con_names on why it is a list to begin with.
name = commaSeparate dflags . map unL $ getConNames con

resType = apps $ map (reL . HsTyVar NoExt NotPromoted . reL) $
(tcdName dat) : [hsTyVarName v | L _ v@(UserTyVar _ _) <- hsQTvExplicit $ tyClDeclTyVars dat]
tyVarArg (UserTyVar _ n) = HsTyVar NoExt NotPromoted n
tyVarArg (KindedTyVar _ n lty) = HsKindSig NoExt (reL (HsTyVar NoExt NotPromoted n)) lty
tyVarArg _ = panic "ppCtor"

resType = apps $ map reL $
(HsTyVar NoExt NotPromoted (reL (tcdName dat))) :
map (tyVarArg . unLoc) (hsQTvExplicit $ tyClDeclTyVars dat)

ppCtor dflags _dat subdocs con@(ConDeclGADT { })
= concatMap (lookupCon dflags subdocs) (getConNames con) ++ f
Expand Down
4 changes: 2 additions & 2 deletions haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ hyperlink (srcs, srcs') ident = case ident of
Just SrcLocal -> Html.anchor content !
[ Html.href $ hypSrcModuleNameUrl mdl name ]
Just (SrcExternal path) -> Html.anchor content !
[ Html.href $ spliceURL Nothing (Just mdl) (Just name) Nothing (".." </> path) ]
[ Html.href $ spliceURL (Just mdl) (Just name) Nothing (".." </> path) ]
Nothing -> content
where
mdl = nameModule name
Expand All @@ -260,7 +260,7 @@ hyperlink (srcs, srcs') ident = case ident of
Just SrcLocal -> Html.anchor content !
[ Html.href $ hypSrcModuleUrl' moduleName ]
Just (SrcExternal path) -> Html.anchor content !
[ Html.href $ spliceURL' Nothing (Just moduleName) Nothing Nothing (".." </> path) ]
[ Html.href $ spliceURL' (Just moduleName) Nothing Nothing (".." </> path) ]
Nothing -> content


Expand Down
2 changes: 1 addition & 1 deletion haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ hypSrcModuleFile m = moduleNameString (moduleName m) <.> "html"

hypSrcModuleFile' :: ModuleName -> FilePath
hypSrcModuleFile' mdl = spliceURL'
Nothing (Just mdl) Nothing Nothing moduleFormat
(Just mdl) Nothing Nothing moduleFormat

hypSrcModuleUrl :: Module -> String
hypSrcModuleUrl = hypSrcModuleFile
Expand Down
84 changes: 47 additions & 37 deletions haddock-api/src/Haddock/Backends/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import qualified Pretty
import BasicTypes ( PromotionFlag(..) )
import GHC
import OccName
import Name ( nameOccName )
import Name ( getOccString, nameOccName, tidyNameOcc )
import RdrName ( rdrNameOcc )
import FastString ( unpackFS )
import Outputable ( panic)
Expand Down Expand Up @@ -295,7 +295,7 @@ ppDecl decl pats (doc, fnArgsDoc) instances subdocs _fxts = case unLoc decl of
-- | Just _ <- tcdTyPats d -> ppTyInst False loc doc d unicode
-- Family instances happen via FamInst now
TyClD _ d@ClassDecl{} -> ppClassDecl instances doc subdocs d unicode
SigD _ (TypeSig _ lnames ty) -> ppFunSig (doc, fnArgsDoc) (map unLoc lnames) (hsSigWcType ty) unicode
SigD _ (TypeSig _ lnames ty) -> ppFunSig Nothing (doc, fnArgsDoc) (map unLoc lnames) (hsSigWcType ty) unicode
SigD _ (PatSynSig _ lnames ty) -> ppLPatSig (doc, fnArgsDoc) (map unLoc lnames) ty unicode
ForD _ d -> ppFor (doc, fnArgsDoc) d unicode
InstD _ _ -> empty
Expand All @@ -307,7 +307,7 @@ ppDecl decl pats (doc, fnArgsDoc) instances subdocs _fxts = case unLoc decl of

ppFor :: DocForDecl DocName -> ForeignDecl DocNameI -> Bool -> LaTeX
ppFor doc (ForeignImport _ (L _ name) typ _) unicode =
ppFunSig doc [name] (hsSigType typ) unicode
ppFunSig Nothing doc [name] (hsSigType typ) unicode
ppFor _ _ _ = error "ppFor error in Haddock.Backends.LaTeX"
-- error "foreign declarations are currently not supported by --latex"

Expand Down Expand Up @@ -414,17 +414,23 @@ ppTySyn _ _ _ = error "declaration not supported by ppTySyn"
-------------------------------------------------------------------------------


ppFunSig :: DocForDecl DocName -> [DocName] -> LHsType DocNameI
-> Bool -> LaTeX
ppFunSig doc docnames (L _ typ) unicode =
ppFunSig
:: Maybe LaTeX -- ^ a prefix to put right before the signature
-> DocForDecl DocName -- ^ documentation
-> [DocName] -- ^ pattern names in the pattern signature
-> LHsType DocNameI -- ^ type of the pattern synonym
-> Bool -- ^ unicode
-> LaTeX
ppFunSig leader doc docnames (L _ typ) unicode =
ppTypeOrFunSig typ doc
( ppTypeSig names typ False
, hsep . punctuate comma $ map ppSymName names
( lead $ ppTypeSig names typ False
, lead $ hsep . punctuate comma $ map ppSymName names
, dcolon unicode
)
unicode
where
names = map getName docnames
lead = maybe id (<+>) leader

-- | Pretty-print a pattern synonym
ppLPatSig :: DocForDecl DocName -- ^ documentation
Expand All @@ -433,15 +439,7 @@ ppLPatSig :: DocForDecl DocName -- ^ documentation
-> Bool -- ^ unicode
-> LaTeX
ppLPatSig doc docnames ty unicode
= ppTypeOrFunSig typ doc
( keyword "pattern" <+> ppTypeSig names typ False
, keyword "pattern" <+> (hsep . punctuate comma $ map ppSymName names)
, dcolon unicode
)
unicode
where
typ = unLoc (hsSigType ty)
names = map getName docnames
= ppFunSig (Just (keyword "pattern")) doc docnames (hsSigType ty) unicode

-- | Pretty-print a type, adding documentation to the whole type and its
-- arguments as needed.
Expand Down Expand Up @@ -587,6 +585,7 @@ ppFds fds unicode =
hsep (map (ppDocName . unLoc) vars2)


-- TODO: associated types, associated type defaults, docs on default methods
ppClassDecl :: [DocInstance DocNameI]
-> Documentation DocName -> [(DocName, DocForDecl DocName)]
-> TyClDecl DocNameI -> Bool -> LaTeX
Expand All @@ -612,13 +611,21 @@ ppClassDecl instances doc subdocs

methodTable =
text "\\haddockpremethods{}" <> emph (text "Methods") $$
vcat [ ppFunSig doc names (hsSigWcType typ) unicode
| L _ (TypeSig _ lnames typ) <- lsigs
vcat [ ppFunSig leader doc names (hsSigType typ) unicode
| L _ (ClassOpSig _ is_def lnames typ) <- lsigs
, let doc = lookupAnySubdoc (head names) subdocs
names = map unLoc lnames ]
-- FIXME: is taking just the first name ok? Is it possible that
-- there are different subdocs for different names in a single
-- type signature?
names = map (cleanName . unLoc) lnames
leader = if is_def then Just (keyword "default") else Nothing
]
-- N.B. taking just the first name is ok. Signatures with multiple
-- names are expanded so that each name gets its own signature.

-- Get rid of the ugly '$dm' prefix on default method names
cleanName n
| isDefaultMethodOcc (occName n)
, '$':'d':'m':occStr <- getOccString n
= setName (tidyNameOcc (getName n) (mkOccName varName occStr)) n
| otherwise = n

instancesBit = ppDocInstances unicode instances

Expand Down Expand Up @@ -960,7 +967,7 @@ ppContext cxt unicode = ppContextNoLocs (map unLoc cxt) unicode

pp_hs_context :: [HsType DocNameI] -> Bool -> LaTeX
pp_hs_context [] _ = empty
pp_hs_context [p] unicode = ppType unicode p
pp_hs_context [p] unicode = ppCtxType unicode p
pp_hs_context cxt unicode = parenList (map (ppType unicode) cxt)


Expand Down Expand Up @@ -995,11 +1002,11 @@ ppLType unicode y = ppType unicode (unLoc y)
ppLParendType unicode y = ppParendType unicode (unLoc y)
ppLFunLhType unicode y = ppFunLhType unicode (unLoc y)


ppType, ppParendType, ppFunLhType :: Bool -> HsType DocNameI -> LaTeX
ppType, ppParendType, ppFunLhType, ppCtxType :: Bool -> HsType DocNameI -> LaTeX
ppType unicode ty = ppr_mono_ty (reparenTypePrec PREC_TOP ty) unicode
ppParendType unicode ty = ppr_mono_ty (reparenTypePrec PREC_TOP ty) unicode
ppFunLhType unicode ty = ppr_mono_ty (reparenTypePrec PREC_FUN ty) unicode
ppCtxType unicode ty = ppr_mono_ty (reparenTypePrec PREC_CTX ty) unicode

ppLHsTypeArg :: Bool -> LHsTypeArg DocNameI -> LaTeX
ppLHsTypeArg unicode (HsValArg ty) = ppLParendType unicode ty
Expand Down Expand Up @@ -1045,7 +1052,7 @@ ppr_mono_ty (HsTupleTy _ con tys) u = tupleParens con (map (ppLType u) tys)
ppr_mono_ty (HsSumTy _ tys) u = sumParens (map (ppLType u) tys)
ppr_mono_ty (HsKindSig _ ty kind) u = parens (ppr_mono_lty ty u <+> dcolon u <+> ppLKind u kind)
ppr_mono_ty (HsListTy _ ty) u = brackets (ppr_mono_lty ty u)
ppr_mono_ty (HsIParamTy _ (L _ n) ty) u = brackets (ppIPName n <+> dcolon u <+> ppr_mono_lty ty u)
ppr_mono_ty (HsIParamTy _ (L _ n) ty) u = ppIPName n <+> dcolon u <+> ppr_mono_lty ty u
ppr_mono_ty (HsSpliceTy {}) _ = error "ppr_mono_ty HsSpliceTy"
ppr_mono_ty (HsRecTy {}) _ = text "{..}"
ppr_mono_ty (XHsType (NHsCoreTy {})) _ = error "ppr_mono_ty HsCoreTy"
Expand Down Expand Up @@ -1110,7 +1117,7 @@ ppVerbOccName :: OccName -> LaTeX
ppVerbOccName = text . latexFilter . occNameString

ppIPName :: HsIPName -> LaTeX
ppIPName ip = text $ unpackFS $ hsIPNameFS ip
ppIPName = text . ('?':) . unpackFS . hsIPNameFS

ppOccName :: OccName -> LaTeX
ppOccName = text . occNameString
Expand Down Expand Up @@ -1177,32 +1184,35 @@ latexMonoMunge c s = latexMunge c s

parLatexMarkup :: (a -> LaTeX) -> DocMarkup a (StringContext -> LaTeX)
parLatexMarkup ppId = Markup {
markupParagraph = \p v -> p v <> text "\\par" $$ text "",
markupParagraph = \p v -> blockElem $ p v <> text "\\par",
markupEmpty = \_ -> empty,
markupString = \s v -> text (fixString v s),
markupAppend = \l r v -> l v <> r v,
markupIdentifier = markupId ppId,
markupIdentifierUnchecked = markupId (ppVerbOccName . snd),
markupModule = \m _ -> let (mdl,_ref) = break (=='#') m in tt (text mdl),
markupWarning = \p v -> emph (p v),
markupWarning = \p v -> p v,
markupEmphasis = \p v -> emph (p v),
markupBold = \p v -> bold (p v),
markupMonospaced = \p _ -> tt (p Mono),
markupUnorderedList = \p v -> itemizedList (map ($v) p) $$ text "",
markupUnorderedList = \p v -> blockElem $ itemizedList (map ($v) p),
markupPic = \p _ -> markupPic p,
markupMathInline = \p _ -> markupMathInline p,
markupMathDisplay = \p _ -> markupMathDisplay p,
markupOrderedList = \p v -> enumeratedList (map ($v) p) $$ text "",
markupDefList = \l v -> descriptionList (map (\(a,b) -> (a v, b v)) l),
markupCodeBlock = \p _ -> quote (verb (p Verb)) $$ text "",
markupMathDisplay = \p _ -> blockElem $ markupMathDisplay p,
markupOrderedList = \p v -> blockElem $ enumeratedList (map ($v) p),
markupDefList = \l v -> blockElem $ descriptionList (map (\(a,b) -> (a v, b v)) l),
markupCodeBlock = \p _ -> blockElem $ quote (verb (p Verb)),
markupHyperlink = \(Hyperlink u l) p -> markupLink u (fmap ($p) l),
markupAName = \_ _ -> empty,
markupProperty = \p _ -> quote $ verb $ text p,
markupExample = \e _ -> quote $ verb $ text $ unlines $ map exampleToString e,
markupProperty = \p _ -> blockElem $ quote $ verb $ text p,
markupExample = \e _ -> blockElem $ quote $ verb $ text $ unlines $ map exampleToString e,
markupHeader = \(Header l h) p -> header l (h p),
markupTable = \(Table h b) p -> table h b p
}
where
blockElem :: LaTeX -> LaTeX
blockElem = ($$ text "")

header 1 d = text "\\section*" <> braces d
header 2 d = text "\\subsection*" <> braces d
header l d
Expand Down
Loading