@@ -9,8 +9,8 @@ import Idris.Docstrings (Docstring, containsText)
9import Data.List (nub)
9import Data.List (nub)
10import qualified Data.Text as T
10import qualified Data.Text as T
12−-- | Find definitions that are relevant to some string. Relevance is one or
12+-- | Find definitions that are relevant to all space-delimited components of
13−-- more of the following:
13+-- some string. Relevance is one or more of the following:
15-- * the string is a substring of the name
15-- * the string is a substring of the name
@@ -20,8 +20,12 @@ import qualified Data.Text as T
20apropos :: IState -> T.Text -> [Name]
20apropos :: IState -> T.Text -> [Name]
21apropos ist what = let defs = ctxtAlist (tt_ctxt ist)
21apropos ist what = let defs = ctxtAlist (tt_ctxt ist)
22 docs = toAlist (idris_docstrings ist)
22 docs = toAlist (idris_docstrings ist)
23− in nub (map fst (filter (isApropos what) defs) ++
23+ in nub (map fst (isAproposAll parts defs) ++
24− map fst (filter (isApropos what) docs))
24+ map fst (isAproposAll parts docs))
25+ where isAproposAll [] xs = xs
26+ isAproposAll (what:more) xs = filter (isApropos what)
27+ (isAproposAll more xs)
28+ parts = filter ((> 0) . T.length) . T.splitOn (T.pack " ") $ what
26textIn :: T.Text -> T.Text -> Bool
30textIn :: T.Text -> T.Text -> Bool
27textIn a b = T.isInfixOf (T.toLower a) (T.toLower b)
31textIn a b = T.isInfixOf (T.toLower a) (T.toLower b)
@@ -48,10 +52,10 @@ instance Apropos Def where
48 isApropos str (CaseOp _ ty ty' _ _ _) = isApropos str ty
52 isApropos str (CaseOp _ ty ty' _ _ _) = isApropos str ty
50instance Apropos (Binder (TT Name)) where
54instance Apropos (Binder (TT Name)) where
51− isApropos str (Lam ty) = isApropos str ty
55+ isApropos str (Lam ty) = str == T.pack "\\" || isApropos str ty
52− isApropos str (Pi ty) = isApropos str ty
56+ isApropos str (Pi ty) = str == T.pack "->" || isApropos str ty
53− isApropos str (Let ty val) = isApropos str ty || isApropos str val
57+ isApropos str (Let ty val) = str == T.pack "let" || isApropos str ty || isApropos str val
54− isApropos str (NLet ty val) = isApropos str ty || isApropos str val
58+ isApropos str (NLet ty val) = str == T.pack "let" || isApropos str ty || isApropos str val
55 isApropos str _ = False -- these shouldn't occur in defined libraries
59 isApropos str _ = False -- these shouldn't occur in defined libraries
57instance Apropos (TT Name) where
61instance Apropos (TT Name) where