summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorAaron Allen <aaron@flipstone.com>2020-12-03 20:57:43 -0600
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-11 12:58:14 -0500
commit4548d1f8a2356458ded83f26a728c31159b46a56 (patch)
treec2e718951cb1673df84973824e0a75d61d8f907e /ghc
parent381eb66012c2b1b9ef50008df57293fe443c2972 (diff)
downloadhaskell-4548d1f8a2356458ded83f26a728c31159b46a56.tar.gz
Elide extraneous messages for :doc command (#15784)
Do not print `<has no documentation>` alongside a valid doc. Additionally, if two matching symbols lack documentation then the message will only be printed once. Hence, `<has no documentation>` will be printed at most once and only if all matching symbols are lacking docs.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs20
1 files changed, 15 insertions, 5 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index d44eb79bd1..81b0a84fca 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -1791,22 +1791,32 @@ docCmd "" =
docCmd s = do
-- TODO: Maybe also get module headers for module names
names <- GHC.parseName s
- e_docss <- mapM GHC.getDocs names
- sdocs <- mapM (either handleGetDocsFailure (pure . pprDocs)) e_docss
+ e_docss <- sequence <$> mapM GHC.getDocs names
+ sdocs <- either handleGetDocsFailure (pure . pprDocs) e_docss
let sdocs' = vcat (intersperse (text "") sdocs)
unqual <- GHC.getPrintUnqual
dflags <- getDynFlags
(liftIO . putStrLn . showSDocForUser dflags unqual) sdocs'
+pprDocs :: [(Maybe HsDocString, Map Int HsDocString)] -> [SDoc]
+pprDocs docs
+ | null nonEmptyDocs = pprDoc <$> take 1 docs
+ -- elide <has no documentation> if there's at least one non-empty doc (#15784)
+ | otherwise = pprDoc <$> nonEmptyDocs
+ where
+ empty (mb_decl_docs, arg_docs)
+ = isNothing mb_decl_docs && null arg_docs
+ nonEmptyDocs = filter (not . empty) docs
+
-- TODO: also print arg docs.
-pprDocs :: (Maybe HsDocString, Map Int HsDocString) -> SDoc
-pprDocs (mb_decl_docs, _arg_docs) =
+pprDoc :: (Maybe HsDocString, Map Int HsDocString) -> SDoc
+pprDoc (mb_decl_docs, _arg_docs) =
maybe
(text "<has no documentation>")
(text . unpackHDS)
mb_decl_docs
-handleGetDocsFailure :: GHC.GhcMonad m => GetDocsFailure -> m SDoc
+handleGetDocsFailure :: GHC.GhcMonad m => GetDocsFailure -> m [SDoc]
handleGetDocsFailure no_docs = do
dflags <- getDynFlags
let msg = showPpr dflags no_docs