@@ -37,7 +37,7 @@ namespace LeanSearchClient
37
37
38
38
open Lean Meta Elab Tactic Parser Term
39
39
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
41
41
let apiUrl := "https://leansearch.net/api/search"
42
42
let s' := s.replace " " "%20"
43
43
let q := apiUrl ++ s! "?query={ s'} &num_results={ num_results} "
@@ -71,14 +71,14 @@ structure SearchResult where
71
71
kind? : Option String
72
72
deriving Repr
73
73
74
- def queryNum : CoreM Nat := do
74
+ def leansearchQueryNum : CoreM Nat := do
75
75
return leansearch.queries.get (← getOptions)
76
76
77
77
def moogleQueryNum : CoreM Nat := do
78
78
return moogle.queries.get (← getOptions)
79
79
namespace SearchResult
80
80
81
- def ofJson ? (js : Json) : Option SearchResult :=
81
+ def ofLeanSearchJson ? (js : Json) : Option SearchResult :=
82
82
match js.getObjValAs? String "formal_name" with
83
83
| Except.ok name =>
84
84
let type? := js.getObjValAs? String "formal_type" |>.toOption
@@ -106,10 +106,10 @@ def ofMoogleJson? (js : Json) : MetaM <| Option SearchResult :=
106
106
return some {name := name, type? := type?, docString? := doc?, doc_url? := docurl?, kind? := kind?}
107
107
| _ => return none
108
108
109
- def query (s : String) (num_results : Nat) :
109
+ def queryLeanSearch (s : String) (num_results : Nat) :
110
110
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 ?
113
113
114
114
def queryMoogle (s : String) (num_results : Nat) :
115
115
MetaM <| Array SearchResult := do
@@ -140,19 +140,19 @@ def toTacticSuggestions (sr : SearchResult) : Array TryThis.Suggestion :=
140
140
141
141
end SearchResult
142
142
143
- def getQueryCommandSuggestions (s : String) (num_results : Nat) :
143
+ def getLeanSearchQueryCommandSuggestions (s : String) (num_results : Nat) :
144
144
IO <| Array TryThis.Suggestion := do
145
- let searchResults ← SearchResult.query s num_results
145
+ let searchResults ← SearchResult.queryLeanSearch s num_results
146
146
return searchResults.map SearchResult.toCommandSuggestion
147
147
148
- def getQueryTermSuggestions (s : String) (num_results : Nat) :
148
+ def getLeanSearchQueryTermSuggestions (s : String) (num_results : Nat) :
149
149
IO <| Array TryThis.Suggestion := do
150
- let searchResults ← SearchResult.query s num_results
150
+ let searchResults ← SearchResult.queryLeanSearch s num_results
151
151
return searchResults.map SearchResult.toTermSuggestion
152
152
153
- def getQueryTacticSuggestionGroups (s : String) (num_results : Nat) :
153
+ def getLeanSearchQueryTacticSuggestionGroups (s : String) (num_results : Nat) :
154
154
IO <| Array (String × Array TryThis.Suggestion) := do
155
- let searchResults ← SearchResult.query s num_results
155
+ let searchResults ← SearchResult.queryLeanSearch s num_results
156
156
return searchResults.map fun sr =>
157
157
let fullName := match sr.type? with
158
158
| some type => s! "{ sr.name} (type: { type} )"
@@ -200,7 +200,7 @@ def checkTactic (target : Expr) (tac : Syntax) :
200
200
catch _ =>
201
201
return none
202
202
203
- def incompleteQuery : String :=
203
+ def incompleteLeanSearchQuery : String :=
204
204
"#leansearch query should end with a `.` or `?`.\n \
205
205
Note this command sends your query to an external service at https://leansearch.net/."
206
206
@@ -218,10 +218,10 @@ syntax (name := leansearch_cmd) "#leansearch" str : command
218
218
| `(command| #leansearch $s) =>
219
219
let s := s.getString
220
220
if s.endsWith "." || s.endsWith "?" then
221
- let suggestions ← getQueryCommandSuggestions s (← queryNum )
221
+ let suggestions ← getLeanSearchQueryCommandSuggestions s (← leansearchQueryNum )
222
222
TryThis.addSuggestions stx suggestions (header := "Lean Search Results" )
223
223
else
224
- logWarning incompleteQuery
224
+ logWarning incompleteLeanSearchQuery
225
225
| _ => throwUnsupportedSyntax
226
226
227
227
syntax (name := leansearch_term) "#leansearch" str : term
@@ -232,10 +232,10 @@ syntax (name := leansearch_term) "#leansearch" str : term
232
232
| `(#leansearch $s) =>
233
233
let s := s.getString
234
234
if s.endsWith "." || s.endsWith "?" then
235
- let suggestions ← getQueryTermSuggestions s (← queryNum )
235
+ let suggestions ← getLeanSearchQueryTermSuggestions s (← leansearchQueryNum )
236
236
TryThis.addSuggestions stx suggestions (header := "Lean Search Results" )
237
237
else
238
- logWarning incompleteQuery
238
+ logWarning incompleteLeanSearchQuery
239
239
defaultTerm expectedType?
240
240
| _ => throwUnsupportedSyntax
241
241
@@ -249,7 +249,7 @@ syntax (name := leansearch_tactic) "#leansearch" str : tactic
249
249
if s.endsWith "." || s.endsWith "?" then
250
250
let target ← getMainTarget
251
251
let suggestionGroups ←
252
- getQueryTacticSuggestionGroups s (← queryNum )
252
+ getLeanSearchQueryTacticSuggestionGroups s (← leansearchQueryNum )
253
253
for (name, sg) in suggestionGroups do
254
254
let sg ← sg.filterM fun s =>
255
255
let sugTxt := s.suggestion
@@ -266,12 +266,12 @@ syntax (name := leansearch_tactic) "#leansearch" str : tactic
266
266
unless sg.isEmpty do
267
267
TryThis.addSuggestions stx sg (header := s! "From: { name} " )
268
268
else
269
- logWarning incompleteQuery
269
+ logWarning incompleteLeanSearchQuery
270
270
| _ => throwUnsupportedSyntax
271
271
272
272
syntax (name := moogle_cmd) "#moogle" str : command
273
273
274
- @[command_elab moogle_cmd] def moogleSearchCommandImpl : CommandElab :=
274
+ @[command_elab moogle_cmd] def moogleCommandImpl : CommandElab :=
275
275
fun stx => Command.liftTermElabM do
276
276
match stx with
277
277
| `(command| #moogle $s) =>
@@ -285,7 +285,7 @@ syntax (name := moogle_cmd) "#moogle" str : command
285
285
286
286
syntax (name := moogle_term) "#moogle" str : term
287
287
288
- @[term_elab moogle_term] def moogleSearchTermImpl : TermElab :=
288
+ @[term_elab moogle_term] def moogleTermImpl : TermElab :=
289
289
fun stx expectedType? => do
290
290
match stx with
291
291
| `(#moogle $s) =>
@@ -300,7 +300,7 @@ syntax (name := moogle_term) "#moogle" str : term
300
300
301
301
syntax (name := moogle_tactic) "#moogle" str : tactic
302
302
303
- @[tactic moogle_tactic] def moogleSearchTacticImpl : Tactic :=
303
+ @[tactic moogle_tactic] def moogleTacticImpl : Tactic :=
304
304
fun stx => withMainContext do
305
305
match stx with
306
306
| `(tactic|#moogle $s) =>
0 commit comments