Skip to content

Commit 49fa2fe

Browse files
More symmetric names
1 parent 2dddae1 commit 49fa2fe

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

LeanSearchClient/Syntax.lean

+22-22
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace LeanSearchClient
3737

3838
open Lean Meta Elab Tactic Parser Term
3939

40-
def getQueryJson (s : String) (num_results : Nat := 6) : IO <| Array Json := do
40+
def getLeanSearchQueryJson (s : String) (num_results : Nat := 6) : IO <| Array Json := do
4141
let apiUrl := "https://leansearch.net/api/search"
4242
let s' := s.replace " " "%20"
4343
let q := apiUrl ++ s!"?query={s'}&num_results={num_results}"
@@ -71,14 +71,14 @@ structure SearchResult where
7171
kind? : Option String
7272
deriving Repr
7373

74-
def queryNum : CoreM Nat := do
74+
def leansearchQueryNum : CoreM Nat := do
7575
return leansearch.queries.get (← getOptions)
7676

7777
def moogleQueryNum : CoreM Nat := do
7878
return moogle.queries.get (← getOptions)
7979
namespace SearchResult
8080

81-
def ofJson? (js : Json) : Option SearchResult :=
81+
def ofLeanSearchJson? (js : Json) : Option SearchResult :=
8282
match js.getObjValAs? String "formal_name" with
8383
| Except.ok name =>
8484
let type? := js.getObjValAs? String "formal_type" |>.toOption
@@ -106,10 +106,10 @@ def ofMoogleJson? (js : Json) : MetaM <| Option SearchResult :=
106106
return some {name := name, type? := type?, docString? := doc?, doc_url? := docurl?, kind? := kind?}
107107
| _ => return none
108108

109-
def query (s : String) (num_results : Nat) :
109+
def queryLeanSearch (s : String) (num_results : Nat) :
110110
IO <| Array SearchResult := do
111-
let jsArr ← getQueryJson s num_results
112-
return jsArr.filterMap ofJson?
111+
let jsArr ← getLeanSearchQueryJson s num_results
112+
return jsArr.filterMap ofLeanSearchJson?
113113

114114
def queryMoogle (s : String) (num_results : Nat) :
115115
MetaM <| Array SearchResult := do
@@ -140,19 +140,19 @@ def toTacticSuggestions (sr : SearchResult) : Array TryThis.Suggestion :=
140140

141141
end SearchResult
142142

143-
def getQueryCommandSuggestions (s : String) (num_results : Nat) :
143+
def getLeanSearchQueryCommandSuggestions (s : String) (num_results : Nat) :
144144
IO <| Array TryThis.Suggestion := do
145-
let searchResults ← SearchResult.query s num_results
145+
let searchResults ← SearchResult.queryLeanSearch s num_results
146146
return searchResults.map SearchResult.toCommandSuggestion
147147

148-
def getQueryTermSuggestions (s : String) (num_results : Nat) :
148+
def getLeanSearchQueryTermSuggestions (s : String) (num_results : Nat) :
149149
IO <| Array TryThis.Suggestion := do
150-
let searchResults ← SearchResult.query s num_results
150+
let searchResults ← SearchResult.queryLeanSearch s num_results
151151
return searchResults.map SearchResult.toTermSuggestion
152152

153-
def getQueryTacticSuggestionGroups (s : String) (num_results : Nat) :
153+
def getLeanSearchQueryTacticSuggestionGroups (s : String) (num_results : Nat) :
154154
IO <| Array (String × Array TryThis.Suggestion) := do
155-
let searchResults ← SearchResult.query s num_results
155+
let searchResults ← SearchResult.queryLeanSearch s num_results
156156
return searchResults.map fun sr =>
157157
let fullName := match sr.type? with
158158
| some type => s!"{sr.name} (type: {type})"
@@ -200,7 +200,7 @@ def checkTactic (target : Expr) (tac : Syntax) :
200200
catch _ =>
201201
return none
202202

203-
def incompleteQuery : String :=
203+
def incompleteLeanSearchQuery : String :=
204204
"#leansearch query should end with a `.` or `?`.\n\
205205
Note this command sends your query to an external service at https://leansearch.net/."
206206

@@ -218,10 +218,10 @@ syntax (name := leansearch_cmd) "#leansearch" str : command
218218
| `(command| #leansearch $s) =>
219219
let s := s.getString
220220
if s.endsWith "." || s.endsWith "?" then
221-
let suggestions ← getQueryCommandSuggestions s (← queryNum)
221+
let suggestions ← getLeanSearchQueryCommandSuggestions s (← leansearchQueryNum)
222222
TryThis.addSuggestions stx suggestions (header := "Lean Search Results")
223223
else
224-
logWarning incompleteQuery
224+
logWarning incompleteLeanSearchQuery
225225
| _ => throwUnsupportedSyntax
226226

227227
syntax (name := leansearch_term) "#leansearch" str : term
@@ -232,10 +232,10 @@ syntax (name := leansearch_term) "#leansearch" str : term
232232
| `(#leansearch $s) =>
233233
let s := s.getString
234234
if s.endsWith "." || s.endsWith "?" then
235-
let suggestions ← getQueryTermSuggestions s (← queryNum)
235+
let suggestions ← getLeanSearchQueryTermSuggestions s (← leansearchQueryNum)
236236
TryThis.addSuggestions stx suggestions (header := "Lean Search Results")
237237
else
238-
logWarning incompleteQuery
238+
logWarning incompleteLeanSearchQuery
239239
defaultTerm expectedType?
240240
| _ => throwUnsupportedSyntax
241241

@@ -249,7 +249,7 @@ syntax (name := leansearch_tactic) "#leansearch" str : tactic
249249
if s.endsWith "." || s.endsWith "?" then
250250
let target ← getMainTarget
251251
let suggestionGroups ←
252-
getQueryTacticSuggestionGroups s (← queryNum)
252+
getLeanSearchQueryTacticSuggestionGroups s (← leansearchQueryNum)
253253
for (name, sg) in suggestionGroups do
254254
let sg ← sg.filterM fun s =>
255255
let sugTxt := s.suggestion
@@ -266,12 +266,12 @@ syntax (name := leansearch_tactic) "#leansearch" str : tactic
266266
unless sg.isEmpty do
267267
TryThis.addSuggestions stx sg (header := s!"From: {name}")
268268
else
269-
logWarning incompleteQuery
269+
logWarning incompleteLeanSearchQuery
270270
| _ => throwUnsupportedSyntax
271271

272272
syntax (name := moogle_cmd) "#moogle" str : command
273273

274-
@[command_elab moogle_cmd] def moogleSearchCommandImpl : CommandElab :=
274+
@[command_elab moogle_cmd] def moogleCommandImpl : CommandElab :=
275275
fun stx => Command.liftTermElabM do
276276
match stx with
277277
| `(command| #moogle $s) =>
@@ -285,7 +285,7 @@ syntax (name := moogle_cmd) "#moogle" str : command
285285

286286
syntax (name := moogle_term) "#moogle" str : term
287287

288-
@[term_elab moogle_term] def moogleSearchTermImpl : TermElab :=
288+
@[term_elab moogle_term] def moogleTermImpl : TermElab :=
289289
fun stx expectedType? => do
290290
match stx with
291291
| `(#moogle $s) =>
@@ -300,7 +300,7 @@ syntax (name := moogle_term) "#moogle" str : term
300300

301301
syntax (name := moogle_tactic) "#moogle" str : tactic
302302

303-
@[tactic moogle_tactic] def moogleSearchTacticImpl : Tactic :=
303+
@[tactic moogle_tactic] def moogleTacticImpl : Tactic :=
304304
fun stx => withMainContext do
305305
match stx with
306306
| `(tactic|#moogle $s) =>

0 commit comments

Comments
 (0)