on master help sign in
Namespaces only containing private members is now correctly considered empty
cd92ae8Philip Rasmussen
src/Idris/IdrisDoc.hs+17−10
@@ -142,10 +142,11 @@ fetchInfo :: IState -- ^ IState to fetch info from
142fetchInfo ist nss =
142fetchInfo ist nss =
143 do let originNss = S.fromList nss
143 do let originNss = S.fromList nss
144 info <- nsDict ist
144 info <- nsDict ist
145− let info' = M.map (filter (filterName . (\(n, _, _) -> n))) info
145+ let info' = M.map (filter filterInclude) info
146 info'' = M.map removeOrphans info'
146 info'' = M.map removeOrphans info'
147+ info''' = M.filter (not . null) info''
147− reachedNss = traceNss info'' originNss S.empty
148+ reachedNss = traceNss info''' originNss S.empty
148− return $ M.filterWithKey (\k _ -> S.member k reachedNss) info''
149+ return $ M.filterWithKey (\k _ -> S.member k reachedNss) info'''
149
150
150
151
151-- | Removes loose class methods and data constructors,
152-- | Removes loose class methods and data constructors,
@@ -169,6 +170,16 @@ filterName (NS n _) = filterName n
169filterName _ = False
170filterName _ = False
170
171
171
172
173+-- | Whether a NsItem should be included in the documentation.
174+-- It must not be Hidden and filterName must return True for the name.
175+-- Also it must have Docs -- without Docs, nothing can be done.
176+filterInclude :: NsItem -- ^ Accessibility to check
177+ -> Bool -- ^ Predicate result
178+filterInclude (name, Just _, Public) | filterName name = True
179+filterInclude (name, Just _, Frozen) | filterName name = True
180+filterInclude _ = False
181+
182+
172-- | Finds all namespaces indirectly referred by a set of namespaces.
183-- | Finds all namespaces indirectly referred by a set of namespaces.
173-- The NsItems of the namespaces are searched for references.
184-- The NsItems of the namespaces are searched for references.
174traceNss :: NsDict -- ^ Mappings of namespaces and their contents
185traceNss :: NsDict -- ^ Mappings of namespaces and their contents
@@ -224,7 +235,7 @@ getAccess ist n =
224 let res = lookupDefAcc n False (tt_ctxt ist)
235 let res = lookupDefAcc n False (tt_ctxt ist)
225 in case res of
236 in case res of
226 [(_, acc)] -> acc
237 [(_, acc)] -> acc
227− _ -> Public
238+ _ -> Hidden
228
239
229-- | Simple predicate for whether an NsItem has Docs
240-- | Simple predicate for whether an NsItem has Docs
230hasDoc :: NsItem -- ^ The NsItem to test
241hasDoc :: NsItem -- ^ The NsItem to test
@@ -412,19 +423,15 @@ createNsDoc ist ns content out =
412 do let tpath = out </> "docs" </> (genRelNsPath ns "html")
423 do let tpath = out </> "docs" </> (genRelNsPath ns "html")
413 dir = takeDirectory tpath
424 dir = takeDirectory tpath
414 file = takeFileName tpath
425 file = takeFileName tpath
415− visible (_, _, Hidden) = False
416− visible _ = True
417 haveDocs (_, Just d, _) = [d]
426 haveDocs (_, Just d, _) = [d]
418 haveDocs _ = []
427 haveDocs _ = []
419− -- Do not document private members
420− content' = filter visible content
421 -- We cannot do anything without a Doc
428 -- We cannot do anything without a Doc
422− content'' = concatMap haveDocs content'
429+ content' = concatMap haveDocs content
423 createDirectoryIfMissing True dir
430 createDirectoryIfMissing True dir
424 (path, h) <- openTempFile dir file
431 (path, h) <- openTempFile dir file
425 BS2.hPut h $ renderHtml $ wrapper (Just ns) $ do
432 BS2.hPut h $ renderHtml $ wrapper (Just ns) $ do
426 H.h1 $ toHtml (nsName2Str ns)
433 H.h1 $ toHtml (nsName2Str ns)
427− H.dl ! class_ "decls" $ forM_ content'' (createOtherDoc ist)
434+ H.dl ! class_ "decls" $ forM_ content' (createOtherDoc ist)
428 hClose h
435 hClose h
429 renameFile path tpath
436 renameFile path tpath
430
437
test/idrisdoc001/TestPrivate.idrnew file+5
@@ -0,0 +1,5 @@
1+module TestPrivate
2+
3+private
4+iAmPrivate : ()
5+iAmPrivate = ()
test/idrisdoc001/expected+2
@@ -1,3 +1,5 @@
1Type checking ./TestEmpty.idr
1Type checking ./TestEmpty.idr
2+Type checking ./TestPrivate.idr
2Warning: Ignoring empty or non-existing namespace 'TestEmpty'
3Warning: Ignoring empty or non-existing namespace 'TestEmpty'
4+Warning: Ignoring empty or non-existing namespace 'TestPrivate'
3No namespaces to generate documentation for
5No namespaces to generate documentation for
test/idrisdoc001/run+1−1
@@ -1,4 +1,4 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−# Tests that no documentation is built for empty namespaces
2+# Tests that no documentation is built for empty and/or private-only namespaces
3idris --mkdoc test_empty.ipkg
3idris --mkdoc test_empty.ipkg
4rm -rf *.ibc *_doc
4rm -rf *.ibc *_doc
test/idrisdoc001/test_empty.ipkg+1−1
@@ -1,4 +1,4 @@
1package test_empty
1package test_empty
2
2
3−modules = TestEmpty
3+modules = TestEmpty, TestPrivate
4
4