on master help sign in
Make :apropos case-insensitive
commitfc65c25d5863d715a509e384f311366cc0662dd6 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateTue 18 Mar 2014, 13:55 (13 years ago) parentbb3a7b7
2 files changed+13−9
src/Idris/Apropos.hs+7−4 src/Idris/Docstrings.hs+6−5
src/Idris/Apropos.hs+7−4
@@ -23,18 +23,21 @@ apropos ist what = let defs = ctxtAlist (tt_ctxt ist)
2323 in nub (map fst (filter (isApropos what) defs) ++
2424 map fst (filter (isApropos what) docs))
2525
26+textIn :: T.Text -> T.Text -> Bool
27+textIn a b = T.isInfixOf (T.toLower a) (T.toLower b)
28+
2629class Apropos a where
2730 isApropos :: T.Text -> a -> Bool
2831
2932instance Apropos Name where
30− isApropos str (UN n) = T.isInfixOf str n
31− isApropos str (NS n' ns) = isApropos str n' || any (T.isInfixOf str) ns
33+ isApropos str (UN n) = textIn str n
34+ isApropos str (NS n' ns) = isApropos str n' || any (textIn str) ns
3235 -- Handle special names from stdlib
3336 isApropos str n | (n == unitTy || n == unitCon) && str == T.pack "()" = True
3437 | n == falseTy && str == T.pack "_|_" = True
3538 | (n == pairTy || n == pairCon) && str == T.pack "," = True
3639 | n == eqTy && str == T.pack "=" = True
37− | n == eqCon && str == T.pack "refl" = True
40+ | n == eqCon && (T.toLower str) == T.pack "refl" = True
3841 | (n == sigmaTy || n == existsCon) && str == T.pack "**" = True
3942 isApropos _ _ = False -- we don't care about case blocks, MNs, etc
4043
@@ -62,7 +65,7 @@ instance Apropos (TT Name) where
6265 isApropos str _ = False
6366
6467instance Apropos Const where
65− isApropos str c = T.isInfixOf str (T.pack (show c))
68+ isApropos str c = textIn str (T.pack (show c))
6669
6770instance Apropos Docstring where
6871 isApropos str d = containsText str d
src/Idris/Docstrings.hs+6−5
@@ -93,25 +93,26 @@ noDocs = (emptyDocstring, [])
9393
9494-- | Does a string occur in the docstring?
9595containsText :: 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
9798 where blockContains :: T.Text -> CT.Block -> Bool
9899 blockContains str (CT.Para inlines) = F.any (inlineContains str) inlines
99100 blockContains str (CT.Header lvl inlines) = F.any (inlineContains str) inlines
100101 blockContains str (CT.Blockquote blocks) = F.any (blockContains str) blocks
101102 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)
103104 blockContains str (CT.HtmlBlock txt) = False -- TODO
104105 blockContains str CT.HRule = False
105106
106107 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)
108109 inlineContains str CT.Space = False
109110 inlineContains str CT.SoftBreak = False
110111 inlineContains str CT.LineBreak = False
111112 inlineContains str (CT.Emph txt) = F.any (inlineContains str) txt
112113 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)
114115 inlineContains str (CT.Link body url title) = F.any (inlineContains str) body
115116 inlineContains str (CT.Image body url title) = False
116117 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)