on master help sign in
Make :apropos case-insensitive
fc65c25David Raymond Christiansen
src/Idris/Apropos.hs+7−4
@@ -23,18 +23,21 @@ apropos ist what = let defs = ctxtAlist (tt_ctxt ist)
23 in nub (map fst (filter (isApropos what) defs) ++
23 in nub (map fst (filter (isApropos what) defs) ++
24 map fst (filter (isApropos what) docs))
24 map fst (filter (isApropos what) docs))
25
25
26+textIn :: T.Text -> T.Text -> Bool
27+textIn a b = T.isInfixOf (T.toLower a) (T.toLower b)
28+
26class Apropos a where
29class Apropos a where
27 isApropos :: T.Text -> a -> Bool
30 isApropos :: T.Text -> a -> Bool
28
31
29instance Apropos Name where
32instance Apropos Name where
30− isApropos str (UN n) = T.isInfixOf str n
33+ isApropos str (UN n) = textIn str n
31− isApropos str (NS n' ns) = isApropos str n' || any (T.isInfixOf str) ns
34+ isApropos str (NS n' ns) = isApropos str n' || any (textIn str) ns
32 -- Handle special names from stdlib
35 -- Handle special names from stdlib
33 isApropos str n | (n == unitTy || n == unitCon) && str == T.pack "()" = True
36 isApropos str n | (n == unitTy || n == unitCon) && str == T.pack "()" = True
34 | n == falseTy && str == T.pack "_|_" = True
37 | n == falseTy && str == T.pack "_|_" = True
35 | (n == pairTy || n == pairCon) && str == T.pack "," = True
38 | (n == pairTy || n == pairCon) && str == T.pack "," = True
36 | n == eqTy && str == T.pack "=" = True
39 | n == eqTy && str == T.pack "=" = True
37− | n == eqCon && str == T.pack "refl" = True
40+ | n == eqCon && (T.toLower str) == T.pack "refl" = True
38 | (n == sigmaTy || n == existsCon) && str == T.pack "**" = True
41 | (n == sigmaTy || n == existsCon) && str == T.pack "**" = True
39 isApropos _ _ = False -- we don't care about case blocks, MNs, etc
42 isApropos _ _ = False -- we don't care about case blocks, MNs, etc
40
43
@@ -62,7 +65,7 @@ instance Apropos (TT Name) where
62 isApropos str _ = False
65 isApropos str _ = False
63
66
64instance Apropos Const where
67instance Apropos Const where
65− isApropos str c = T.isInfixOf str (T.pack (show c))
68+ isApropos str c = textIn str (T.pack (show c))
66
69
67instance Apropos Docstring where
70instance Apropos Docstring where
68 isApropos str d = containsText str d
71 isApropos str d = containsText str d
src/Idris/Docstrings.hs+6−5
@@ -93,25 +93,26 @@ noDocs = (emptyDocstring, [])
93
93
94-- | Does a string occur in the docstring?
94-- | Does a string occur in the docstring?
95containsText :: T.Text -> Docstring -> Bool
95containsText :: T.Text -> Docstring -> Bool
96−containsText str (CT.Doc _ blocks) = F.any (blockContains str) blocks
96+containsText str (CT.Doc _ blocks) = F.any (blockContains (T.toLower str)) blocks
97+ -- blockContains and inlineContains should always be called with a lower-case search string
97 where blockContains :: T.Text -> CT.Block -> Bool
98 where blockContains :: T.Text -> CT.Block -> Bool
98 blockContains str (CT.Para inlines) = F.any (inlineContains str) inlines
99 blockContains str (CT.Para inlines) = F.any (inlineContains str) inlines
99 blockContains str (CT.Header lvl inlines) = F.any (inlineContains str) inlines
100 blockContains str (CT.Header lvl inlines) = F.any (inlineContains str) inlines
100 blockContains str (CT.Blockquote blocks) = F.any (blockContains str) blocks
101 blockContains str (CT.Blockquote blocks) = F.any (blockContains str) blocks
101 blockContains str (CT.List b ty blockss) = F.any (F.any (blockContains str)) blockss
102 blockContains str (CT.List b ty blockss) = F.any (F.any (blockContains str)) blockss
102− blockContains str (CT.CodeBlock attr src) = T.isInfixOf str src
103+ blockContains str (CT.CodeBlock attr src) = T.isInfixOf str (T.toLower src)
103 blockContains str (CT.HtmlBlock txt) = False -- TODO
104 blockContains str (CT.HtmlBlock txt) = False -- TODO
104 blockContains str CT.HRule = False
105 blockContains str CT.HRule = False
105
106
106 inlineContains :: T.Text -> CT.Inline -> Bool
107 inlineContains :: T.Text -> CT.Inline -> Bool
107− inlineContains str (CT.Str s) = T.isInfixOf str s
108+ inlineContains str (CT.Str s) = T.isInfixOf str (T.toLower s)
108 inlineContains str CT.Space = False
109 inlineContains str CT.Space = False
109 inlineContains str CT.SoftBreak = False
110 inlineContains str CT.SoftBreak = False
110 inlineContains str CT.LineBreak = False
111 inlineContains str CT.LineBreak = False
111 inlineContains str (CT.Emph txt) = F.any (inlineContains str) txt
112 inlineContains str (CT.Emph txt) = F.any (inlineContains str) txt
112 inlineContains str (CT.Strong txt) = F.any (inlineContains str) txt
113 inlineContains str (CT.Strong txt) = F.any (inlineContains str) txt
113− inlineContains str (CT.Code txt) = T.isInfixOf str txt
114+ inlineContains str (CT.Code txt) = T.isInfixOf str (T.toLower txt)
114 inlineContains str (CT.Link body url title) = F.any (inlineContains str) body
115 inlineContains str (CT.Link body url title) = F.any (inlineContains str) body
115 inlineContains str (CT.Image body url title) = False
116 inlineContains str (CT.Image body url title) = False
116 inlineContains str (CT.Entity a) = False
117 inlineContains str (CT.Entity a) = False
117− inlineContains str (CT.RawHtml txt) = T.isInfixOf str txt
118+ inlineContains str (CT.RawHtml txt) = T.isInfixOf str (T.toLower txt)