Skip to content

Commit 99f6367

Browse files
term case too
1 parent 0105add commit 99f6367

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

LeanSearchClient/LoogleSyntax.lean

+40-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,47 @@ syntax (name := loogle_cmd) "#loogle" str "go" : command
156156
| none => pure ()
157157
| _ => throwUnsupportedSyntax
158158

159-
#loogle "List ?a → ?b" go
159+
-- #loogle "List ?a → ?b" go
160160

161-
#loogle "nonsense" go
161+
-- #loogle "nonsense" go
162162

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
164201

165202
end LeanSearchClient

0 commit comments

Comments
 (0)