on master help sign in
Merge pull request #1140 from PhilipRasmussen/idrisdoc
f9827acDavid Christiansen
idris.cabal+5
@@ -339,12 +339,17 @@ Extra-source-files:
339 test/idrisdoc005/*.ipkg
339 test/idrisdoc005/*.ipkg
340 test/idrisdoc006/run
340 test/idrisdoc006/run
341 test/idrisdoc006/expected
341 test/idrisdoc006/expected
342+ test/idrisdoc006/A/fully/Qualified/NAME.idr
342 test/idrisdoc006/*.idr
343 test/idrisdoc006/*.idr
343 test/idrisdoc006/*.ipkg
344 test/idrisdoc006/*.ipkg
344 test/idrisdoc007/run
345 test/idrisdoc007/run
345 test/idrisdoc007/expected
346 test/idrisdoc007/expected
346 test/idrisdoc007/*.idr
347 test/idrisdoc007/*.idr
347 test/idrisdoc007/*.ipkg
348 test/idrisdoc007/*.ipkg
349+ test/idrisdoc008/run
350+ test/idrisdoc008/expected
351+ test/idrisdoc008/*.idr
352+ test/idrisdoc008/*.ipkg
348
353
349 test/interactive001/run
354 test/interactive001/run
350 test/interactive001/input
355 test/interactive001/input
src/Idris/IdrisDoc.hs+26−10
@@ -77,10 +77,19 @@ generateDocs ist nss' out =
77
77
78-- ----------------------------------------------------------------- [ Types ]
78-- ----------------------------------------------------------------- [ Types ]
79
79
80+-- | Either an error message or a result
80type Failable = Either String
81type Failable = Either String
82+
83+-- | Internal representation of a fully qualified namespace name
81type NsName = [T.Text]
84type NsName = [T.Text]
85+
86+-- | All information to be documented about a single namespace member
82type NsItem = (Name, Maybe Docs, Accessibility)
87type NsItem = (Name, Maybe Docs, Accessibility)
88+
89+-- | All information to be documented about a namespace
83type NsInfo = [NsItem]
90type NsInfo = [NsItem]
91+
92+-- | A map from namespace names to information about them
84type NsDict = M.Map NsName NsInfo
93type NsDict = M.Map NsName NsInfo
85
94
86-- --------------------------------------------------------------- [ Utility ]
95-- --------------------------------------------------------------- [ Utility ]
@@ -133,10 +142,11 @@ fetchInfo :: IState -- ^ IState to fetch info from
133fetchInfo ist nss =
142fetchInfo ist nss =
134 do let originNss = S.fromList nss
143 do let originNss = S.fromList nss
135 info <- nsDict ist
144 info <- nsDict ist
136− let info' = M.map (filter (filterName . (\(n, _, _) -> n))) info
145+ let info' = M.map (filter filterInclude) info
137 info'' = M.map removeOrphans info'
146 info'' = M.map removeOrphans info'
147+ info''' = M.filter (not . null) info''
138− reachedNss = traceNss info'' originNss S.empty
148+ reachedNss = traceNss info''' originNss S.empty
139− return $ M.filterWithKey (\k _ -> S.member k reachedNss) info''
149+ return $ M.filterWithKey (\k _ -> S.member k reachedNss) info'''
140
150
141
151
142-- | Removes loose class methods and data constructors,
152-- | Removes loose class methods and data constructors,
@@ -160,6 +170,16 @@ filterName (NS n _) = filterName n
160filterName _ = False
170filterName _ = False
161
171
162
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+
163-- | Finds all namespaces indirectly referred by a set of namespaces.
183-- | Finds all namespaces indirectly referred by a set of namespaces.
164-- The NsItems of the namespaces are searched for references.
184-- The NsItems of the namespaces are searched for references.
165traceNss :: NsDict -- ^ Mappings of namespaces and their contents
185traceNss :: NsDict -- ^ Mappings of namespaces and their contents
@@ -215,7 +235,7 @@ getAccess ist n =
215 let res = lookupDefAcc n False (tt_ctxt ist)
235 let res = lookupDefAcc n False (tt_ctxt ist)
216 in case res of
236 in case res of
217 [(_, acc)] -> acc
237 [(_, acc)] -> acc
218− _ -> Public
238+ _ -> Hidden
219
239
220-- | Simple predicate for whether an NsItem has Docs
240-- | Simple predicate for whether an NsItem has Docs
221hasDoc :: NsItem -- ^ The NsItem to test
241hasDoc :: NsItem -- ^ The NsItem to test
@@ -403,19 +423,15 @@ createNsDoc ist ns content out =
403 do let tpath = out </> "docs" </> (genRelNsPath ns "html")
423 do let tpath = out </> "docs" </> (genRelNsPath ns "html")
404 dir = takeDirectory tpath
424 dir = takeDirectory tpath
405 file = takeFileName tpath
425 file = takeFileName tpath
406− visible (_, _, Hidden) = False
407− visible _ = True
408 haveDocs (_, Just d, _) = [d]
426 haveDocs (_, Just d, _) = [d]
409 haveDocs _ = []
427 haveDocs _ = []
410− -- Do not document private members
411− content' = filter visible content
412 -- We cannot do anything without a Doc
428 -- We cannot do anything without a Doc
413− content'' = concatMap haveDocs content'
429+ content' = concatMap haveDocs content
414 createDirectoryIfMissing True dir
430 createDirectoryIfMissing True dir
415 (path, h) <- openTempFile dir file
431 (path, h) <- openTempFile dir file
416 BS2.hPut h $ renderHtml $ wrapper (Just ns) $ do
432 BS2.hPut h $ renderHtml $ wrapper (Just ns) $ do
417 H.h1 $ toHtml (nsName2Str ns)
433 H.h1 $ toHtml (nsName2Str ns)
418− H.dl ! class_ "decls" $ forM_ content'' (createOtherDoc ist)
434+ H.dl ! class_ "decls" $ forM_ content' (createOtherDoc ist)
419 hClose h
435 hClose h
420 renameFile path tpath
436 renameFile path tpath
421
437
src/Idris/REPL.hs+4−2
@@ -1565,8 +1565,10 @@ getPkgCheck :: Opt -> Maybe String
1565getPkgCheck (PkgCheck str) = Just str
1565getPkgCheck (PkgCheck str) = Just str
1566getPkgCheck _ = Nothing
1566getPkgCheck _ = Nothing
1567
1567
1568−-- IdrisDoc
1568+-- | Returns None if given an Opt which is not PkgMkDoc
1569+-- Otherwise returns Just x, where x is the contents of PkgMkDoc
1569−getPkgMkDoc :: Opt -> Maybe String
1570+getPkgMkDoc :: Opt -- ^ Opt to extract
1571+ -> Maybe String -- ^ Result
1570getPkgMkDoc (PkgMkDoc str) = Just str
1572getPkgMkDoc (PkgMkDoc str) = Just str
1571getPkgMkDoc _ = Nothing
1573getPkgMkDoc _ = Nothing
1572
1574
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
test/idrisdoc006/A.idr → test/idrisdoc006/A/fully/Qualified/NAME.idrrenamed+1−1
@@ -1,4 +1,4 @@
1−module A
1+module A.fully.Qualified.NAME
2
2
3||| This is another test
3||| This is another test
4data Test : Type where
4data Test : Type where
test/idrisdoc006/expected+6−5
@@ -1,6 +1,7 @@
1−Type checking ./A.idr
1+Type checking ./A/fully/Qualified/NAME.idr
2+IdrisDoc file written
2Type checking ./B.idr
3Type checking ./B.idr
3−A: Check
4+A.fully.Qualified.NAME.html
4−B: Check
5+B.html
5−A
6+A.fully.Qualified.NAME is in the index
6−B
7+B is in the index
test/idrisdoc006/package_a.ipkg+1−1
@@ -1,4 +1,4 @@
1package test_merge
1package test_merge
2
2
3−modules = A
3+modules = A.fully.Qualified.NAME
4
4
test/idrisdoc006/run+9−9
@@ -1,17 +1,17 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−# Tests that documentation properly is merged with existing
2+# Tests that documentation properly is merged with existent.
3idris --mkdoc package_a.ipkg
3idris --mkdoc package_a.ipkg
4+[ -f test_merge_doc/IdrisDoc ] && echo "IdrisDoc file written"
4idris --mkdoc package_b.ipkg
5idris --mkdoc package_b.ipkg
5−[ -f test_merge_doc/docs/A.html ] && echo "A: Check"
6−[ -f test_merge_doc/docs/B.html ] && echo "B: Check"
6+ls -1p test_merge_doc/docs
7−if grep -q "href\\=\"docs/A\\.html\"" test_merge_doc/index.html; then
7+if grep -q "href\\=\"docs/A.fully.Qualified.NAME\\.html\"" test_merge_doc/index.html; then
8− echo A
8+ echo A.fully.Qualified.NAME is in the index
9else
9else
10− echo A is not in the index
10+ echo A.fully.Qualified.NAME is NOT in the index
11fi
11fi
12if grep -q "href\\=\"docs/B\\.html\"" test_merge_doc/index.html; then
12if grep -q "href\\=\"docs/B\\.html\"" test_merge_doc/index.html; then
13− echo B
13+ echo B is in the index
14else
14else
15− echo B is not in the index
15+ echo B is NOT in the index
16fi
16fi
17−rm -rf *.ibc *_doc
17+rm -rf *.ibc *_doc A/fully/Qualified/NAME.ibc
test/idrisdoc008/Abstract.idrnew file+5
@@ -0,0 +1,5 @@
1+module Abstract
2+
3+abstract
4+frozen : ()
5+frozen = ()
test/idrisdoc008/Visible.idrnew file+5
@@ -0,0 +1,5 @@
1+module Visible
2+
3+public
4+visible : ()
5+visible = ()
test/idrisdoc008/expectednew file+4
@@ -0,0 +1,4 @@
1+Type checking ./Abstract.idr
2+Type checking ./Visible.idr
3+Abstract members are documented
4+Public members are documented
test/idrisdoc008/runnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/env bash
2+# Tests that documentation is generated for both public and abstract members.
3+idris --mkdoc visibility.ipkg
4+[ -f visibility_doc/docs/Abstract.html ] && echo "Abstract members are documented"
5+[ -f visibility_doc/docs/Visible.html ] && echo "Public members are documented"
6+rm -rf *.ibc *_doc
test/idrisdoc008/visibility.ipkgnew file+4
@@ -0,0 +1,4 @@
1+package visibility
2+
3+modules = Abstract, Visible
4+