lean4-htt/tests/lean/run/grind_try_extend.lean
Marc Huisinga 9d427fdfcf
feat: "try this" messages with support for interactivity (#10524)
This PR adds support for interactivity to the combined "try this"
messages that were introduced in #9966. In doing so, it moves the link
to apply a suggestion to a separate `[apply]` button in front of the
suggestion. Hints with diffs remain unchanged, as they did not
previously support interacting with terms in the diff, either.

<img width="379" height="256" alt="Suggestion with interactive message"
src="https://github.com/user-attachments/assets/7838ebf6-0613-46e7-bc88-468a05acbf51"
/>
2025-10-13 13:39:03 +00:00

36 lines
990 B
Text

module
public import Lean
public meta import Lean.Elab.Tactic
open Lean Meta Elab Tactic Try
-- Install a `TryTactic` handler for `assumption`
@[local try_tactic assumption]
meta def evalTryApply : TryTactic := fun tac => do
-- We just use the default implementation, but return a different tactic.
evalAssumption tac
`(tactic| (trace "worked"; assumption))
/--
info: Try this:
[apply] · trace "worked"; assumption
-/
#guard_msgs (info) in
example (h : False) : False := by
try? (max := 1) -- at most one solution
-- `try?` uses `evalAndSuggest` the attribute `[try_tactic]` is used to extend `evalAndSuggest`.
-- Let's define our own `try?` that uses `evalAndSuggest`
elab stx:"my_try?" : tactic => do
-- Things to try
let toTry ← `(tactic| attempt_all | assumption | apply True | rfl)
evalAndSuggest stx toTry
/--
info: Try these:
[apply] · trace "worked"; assumption
[apply] rfl
-/
#guard_msgs (info) in
example (a : Nat) (h : a = a) : a = a := by
my_try?