@@ -223,20 +223,47 @@ where
223223 | .cases _ | .intro | .inj | .ext | .symbol _ =>
224224 throwError "invalid modifier"
225225
226+ def logAnchor (numDigits : Nat) (anchorPrefix : UInt64) (e : Expr) : TermElabM Unit := do
227+ let stx ← getRef
228+ if e.isFVar || e.isConst then
229+ /-
230+ **Note** : When `e` is a constant or free variable, the hover displays `e`
231+ -/
232+ Term.addTermInfo' stx e
233+ else if (← isType e) then
234+ /-
235+ **Note** : If `e` is a type, we create a fake `sorry` to force `e` to be displayed
236+ when we hover over the anchor.
237+ We wrap the `sorry` with `id` to ensure the hover will not display `sorry : e`
238+ -/
239+ let e ← mkSorry e (synthetic := false )
240+ let e ← mkId e
241+ Term.addTermInfo' stx e
242+ else
243+ /-
244+ **Note** : only the `e`s type is displayed when hovering over the anchor.
245+ We add a silent info with the anchor declaration.
246+ -/
247+ Term.addTermInfo' stx e
248+ logAt (severity := .information) (isSilent := true ) stx
249+ m!"#{anchorToString numDigits anchorPrefix} := {e}"
250+
226251@[builtin_grind_tactic cases] def evalCases : GrindTactic := fun stx => do
227252 match stx with
228253 | `(grind| cases #$anchor:hexnum) =>
229254 let (numDigits, val) ← elabAnchor anchor
230255 let goal ← getMainGoal
231256 let candidates := goal.split.candidates
232- let (goals, genNew) ← liftSearchM do
257+ let (e, goals, genNew) ← liftSearchM do
233258 for c in candidates do
259+ let e := c.getExpr
234260 let anchor ← getAnchor c.getExpr
235261 if isAnchorPrefix numDigits val anchor then
236262 let some result ← split? c
237263 | throwError "`cases` tactic failed, case-split is not ready{indentExpr c.getExpr}"
238- return result
264+ return (e, result)
239265 throwError "`cases` tactic failed, invalid anchor"
266+ goal.withContext <| withRef anchor <| logAnchor numDigits val e
240267 let goals ← goals.filterMapM fun goal => do
241268 let (goal, _) ← liftGrindM <| SearchM.run goal do
242269 intros genNew
0 commit comments