on master help sign in
Make :apropos search for documented modules as well
commit79e77c62b4ac7853fc776ffe34740bd74c2ebcfb authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateSat 3 Jan 2015, 23:30 (12 years ago) parent25c117a
2 files changed+26−7
src/Idris/Apropos.hs+18−4 src/Idris/REPL.hs+8−3
src/Idris/Apropos.hs+18−4
@@ -1,12 +1,12 @@
1−module Idris.Apropos where
1+module Idris.Apropos (apropos, aproposModules) where
22
33import Idris.AbsSyntax
44import Idris.Core.Evaluate (ctxtAlist, Def(..))
55import Idris.Core.TT (Name(..), Type, TT(..), NameType(..), Binder(..), Const(..),
66 lookupCtxtExact, toAlist)
7−import Idris.Docstrings (Docstring, containsText)
7+import Idris.Docstrings (Docstring, DocTerm, containsText)
88
9−import Data.List (nub)
9+import Data.List (nub, nubBy, intersperse)
1010import qualified Data.Text as T
1111
1212-- | Find definitions that are relevant to all space-delimited components of
@@ -22,11 +22,25 @@ apropos ist what = let defs = ctxtAlist (tt_ctxt ist)
2222 docs = toAlist (idris_docstrings ist)
2323 in nub (map fst (isAproposAll parts defs) ++
2424 map fst (isAproposAll parts docs))
25− where isAproposAll [] xs = xs
25+ where isAproposAll [] xs = xs
2626 isAproposAll (what:more) xs = filter (isApropos what)
2727 (isAproposAll more xs)
2828 parts = filter ((> 0) . T.length) . T.splitOn (T.pack " ") $ what
2929
30+-- | Find modules whose names or docstrings contain all the
31+-- space-delimited components of some string.
32+aproposModules :: IState -> T.Text -> [(String, Docstring DocTerm)]
33+aproposModules ist what = let mods = toAlist (idris_moduledocs ist)
34+ found = nubBy (\x y -> fst x == fst y)
35+ (isAproposAll parts mods)
36+ in map unModName found
37+ where isAproposAll [] xs = xs
38+ isAproposAll (what:more) xs = filter (\(n,d) -> isApropos what n || isApropos what d)
39+ (isAproposAll more xs)
40+ parts = filter ((> 0) . T.length) . T.splitOn (T.pack " ") $ what
41+ unModName (NS _ ns, d) = ((concat . intersperse "." . map T.unpack . reverse) ns, d)
42+ unModName (n, d) = ("<<MODULE>>", d)
43+
3044textIn :: T.Text -> T.Text -> Bool
3145textIn a b = T.isInfixOf (T.toLower a) (T.toLower b)
3246
src/Idris/REPL.hs+8−3
@@ -5,7 +5,7 @@ module Idris.REPL where
55
66import Idris.AbsSyntax
77import Idris.ASTUtils
8−import Idris.Apropos (apropos)
8+import Idris.Apropos (apropos, aproposModules)
99import Idris.REPLParser
1010import Idris.ElabDecls
1111import Idris.ElabTerm
@@ -13,7 +13,7 @@ import Idris.Erasure
1313import Idris.Error
1414import Idris.ErrReverse
1515import Idris.Delaborate
16−import Idris.Docstrings (Docstring, overview, renderDocstring)
16+import Idris.Docstrings (Docstring, overview, renderDocstring, renderDocTerm)
1717import Idris.Help
1818import Idris.IdrisDoc
1919import Idris.Prover
@@ -1179,16 +1179,21 @@ process fn (Apropos pkgs a) =
11791179 iputStrLn $ "Searching packages: " ++ showSep ", " pkgs
11801180 mapM_ loadPkgIndex pkgs
11811181 ist <- getIState
1182+ let mods = aproposModules ist (T.pack a)
11821183 let names = apropos ist (T.pack a)
11831184 let aproposInfo = [ (n,
11841185 delabTy ist n,
11851186 fmap (overview . fst) (lookupCtxtExact n (idris_docstrings ist)))
11861187 | n <- sort names, isUN n ]
1187− iRenderResult $ vsep (map (prettyDocumentedIst ist) aproposInfo)
1188+ iRenderResult $ vsep (map (\(m, d) -> text "Module" <+> text m <$>
1189+ ppD ist d <> line) mods) <$>
1190+ vsep (map (prettyDocumentedIst ist) aproposInfo)
11881191 putIState orig
11891192 where isUN (UN _) = True
11901193 isUN (NS n _) = isUN n
11911194 isUN _ = False
1195+ ppD ist = renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) []))
1196+
11921197
11931198process fn (WhoCalls n) =
11941199 do calls <- whoCalls n