From b91798be48d9fa02610b419ccea15a7dfd663823 Mon Sep 17 00:00:00 2001 From: Zubin Duggal Date: Sat, 12 Mar 2022 00:07:56 +0000 Subject: hi haddock: Lex and store haddock docs in interface files Names appearing in Haddock docstrings are lexed and renamed like any other names appearing in the AST. We currently rename names irrespective of the namespace, so both type and constructor names corresponding to an identifier will appear in the docstring. Haddock will select a given name as the link destination based on its own heuristics. This patch also restricts the limitation of `-haddock` being incompatible with `Opt_KeepRawTokenStream`. The export and documenation structure is now computed in GHC and serialised in .hi files. This can be used by haddock to directly generate doc pages without reparsing or renaming the source. At the moment the operation of haddock is not modified, that's left to a future patch. Updates the haddock submodule with the minimum changes needed. --- ghc/GHCi/UI.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ghc') diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 4043f3e247..76d714c3e6 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -1902,9 +1902,9 @@ docCmd s = do data DocComponents = DocComponents - { docs :: Maybe HsDocString -- ^ subject's haddocks + { docs :: Maybe [HsDoc GhcRn] -- ^ subject's haddocks , sigAndLoc :: Maybe SDoc -- ^ type signature + category + location - , argDocs :: IntMap HsDocString -- ^ haddocks for arguments + , argDocs :: IntMap (HsDoc GhcRn) -- ^ haddocks for arguments } buildDocComponents :: GHC.GhcMonad m => String -> Name -> m DocComponents @@ -1945,7 +1945,7 @@ pprDocs docs | otherwise = pprDoc <$> nonEmptyDocs where empty DocComponents{docs = mb_decl_docs, argDocs = arg_docs} - = isNothing mb_decl_docs && null arg_docs + = maybe True null mb_decl_docs && null arg_docs nonEmptyDocs = filter (not . empty) docs -- TODO: also print arg docs. @@ -1958,7 +1958,7 @@ pprDoc DocComponents{sigAndLoc = mb_sig_loc, docs = mb_decl_docs} = where formatDoc doc = vcat [ fromMaybe empty mb_sig_loc -- print contextual info (#19055) - , text $ unpackHDS doc + , pprHsDocStrings $ map hsDocString doc ] handleGetDocsFailure :: GHC.GhcMonad m => GetDocsFailure -> m a -- cgit v1.2.1