Skip to content

Commit 1d6ba8b

Browse files
committed
glass-democlient: support case-insensitive search
1 parent 5e271a4 commit 1d6ba8b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

glean/glass/tools/Glean/Glass/Test/DemoClient.hs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ data Command
4747
| Describe SymbolId
4848
| FindRefs SymbolId
4949
| FindLocation SymbolId
50-
| Search RepoName Text
50+
| Search RepoName Text Bool{- case-insensitve? -}
5151

5252
options :: ParserInfo Options
5353
options = info (helper <*> parser) (fullDesc <>
@@ -87,7 +87,7 @@ options = info (helper <*> parser) (fullDesc <>
8787
) <>
8888
command "search" (info searchCommand
8989
(progDesc $ unlines
90-
["Find entities matching (case-insensitive) string"
90+
["Find entities matching string"
9191
]
9292
)
9393
)
@@ -102,7 +102,13 @@ options = info (helper <*> parser) (fullDesc <>
102102
describeCommand = cmd (Describe <$> readSymbol) symbolHelp
103103
findRefsCommand = cmd (FindRefs <$> readSymbol) symbolHelp
104104
locationCommand = cmd (FindLocation <$> readSymbol) symbolHelp
105-
searchCommand = cmd readSearch searchHelp
105+
searchCommand = do
106+
~(repo,needle) <- argument readSearch searchHelp
107+
ignoreCase <- switch
108+
( long "case-insensitive"
109+
<> short 'i'
110+
)
111+
return $ Search repo needle ignoreCase
106112

107113
readService :: ReadM Service
108114
readService = do
@@ -113,12 +119,12 @@ readService = do
113119
Left _ -> fail ("Not a valid port: " <> show portStr)
114120
Right port -> return (HostPort host (fromIntegral port))
115121

116-
readSearch :: ReadM Command
122+
readSearch :: ReadM (RepoName, Text)
117123
readSearch = do
118124
repoStr <- Text.pack <$> readerAsk
119125
case Text.breakOn "/" repoStr of
120126
(_, "") -> fail "Not a valid repo/string"
121-
(repo, str) -> return (Search (RepoName repo) (Text.tail str))
127+
(repo, str) -> return (RepoName repo, Text.tail str)
122128

123129
readListRepoPath :: ReadM Command
124130
readListRepoPath = do
@@ -164,7 +170,7 @@ main = Glean.withOptions options $ \Options{..} ->
164170
Describe sym -> runDescribe sym
165171
FindRefs sym -> runFindRefs sym
166172
FindLocation sym -> runLocation sym
167-
Search repo str -> runSearch repo str
173+
Search repo str ignoreCase -> runSearch repo str ignoreCase
168174
mapM_ Text.putStrLn res
169175

170176
runListSymbols :: Protocol p => RepoName -> Path -> GlassM p [Text]
@@ -186,8 +192,8 @@ runDescribe sym = do
186192
annot = textShow <$> symbolDescription_annotations
187193
return $ [loc,name] <> catMaybes [kind,annot]
188194

189-
runSearch :: Protocol p => RepoName -> Text -> GlassM p [Text]
190-
runSearch repoName strName = do
195+
runSearch :: Protocol p => RepoName -> Text -> Bool -> GlassM p [Text]
196+
runSearch repoName strName ignoreCase = do
191197
SymbolSearchResult syms _ <- searchSymbol req def
192198
return (map textShow syms)
193199
where
@@ -196,7 +202,9 @@ runSearch repoName strName = do
196202
(Just repoName)
197203
def -- language
198204
def -- kinds
199-
def -- default search options
205+
def { -- search options
206+
symbolSearchOptions_ignoreCase = ignoreCase
207+
}
200208

201209
runLocation :: Protocol p => SymbolId -> GlassM p [Text]
202210
runLocation sym = do

0 commit comments

Comments
 (0)