@@ -156,10 +156,47 @@ syntax (name := loogle_cmd) "#loogle" str "go" : command
156
156
| none => pure ()
157
157
| _ => throwUnsupportedSyntax
158
158
159
- #loogle "List ?a → ?b" go
159
+ -- #loogle "List ?a → ?b" go
160
160
161
- #loogle "nonsense" go
161
+ -- #loogle "nonsense" go
162
162
163
- #loogle "?a → ?b" go
163
+ -- #loogle "?a → ?b" go
164
+
165
+ -- #loogle "sin" go
166
+
167
+
168
+ syntax (name := loogle_term) "#loogle" str "go" : term
169
+ @[term_elab loogle_term] def loogleTermImpl : TermElab :=
170
+ fun stx expectedType? => do
171
+ match stx with
172
+ | `(#loogle $s go) =>
173
+ let s := s.getString
174
+ let result ← getLoogleQueryJson s
175
+ match result with
176
+ | LoogleResult.success xs =>
177
+ let suggestions := xs.map SearchResult.toTermSuggestion
178
+ if suggestions.isEmpty then
179
+ logWarning "Loogle search returned no results"
180
+ logInfo loogleUsage
181
+ else
182
+ TryThis.addSuggestions stx suggestions (header := s! "Loogle Search Results" )
183
+
184
+ | LoogleResult.failure error suggestions? =>
185
+ logWarning s! "Loogle search failed with error: { error} "
186
+ logInfo loogleUsage
187
+ match suggestions? with
188
+ | some suggestions =>
189
+ let suggestions : List TryThis.Suggestion :=
190
+ suggestions.map fun s =>
191
+ let s := s.replace "\" " "\\\" "
192
+ {suggestion := .string s! "#loogle \" { s} \" go" }
193
+ unless suggestions.isEmpty do
194
+ TryThis.addSuggestions stx suggestions.toArray (header := s! "Did you maybe mean" )
195
+ | none => pure ()
196
+ defaultTerm expectedType?
197
+ | _ => throwUnsupportedSyntax
198
+
199
+
200
+ -- example := #loogle "List ?a → ?b" go
164
201
165
202
end LeanSearchClient
0 commit comments