lean4-htt/tests/lean/run/grind_eval_suggest.lean
Marc Huisinga f180eee7bf
feat: use widget message for "try this" (#9966)
This PR adjusts the "try this" widget to be rendered as a widget message
under 'Messages', not a separate widget under a 'Suggestions' section.
The main benefit of this is that the message of the widget is not
duplicated between 'Messages' and 'Suggestions'.

Since widget message suggestions were already implemented by @jrr6 for
the new hint infrastructure, this PR replaces the old "try this"
implementation with the new hint infrastructure. In doing so, the
`style?` field of suggestions is deprecated, since the hint
infrastructure highlights hints using diff colors, and `style?` also
never saw much use downstream. Additionally, since the message and the
suggestion are now the same component, the `messageData?` field of
suggestions is deprecated as well. Notably, the "Try this:" message
string now also contains a newline and indentation to separate the
suggestion from the rest of the message more clearly and the `postInfo?`
field of the suggestion is now part of the message.

Finally, this PR changes the diff colors used by the hint infrastructure
to be more color-blindness-friendly (insertions are now blue, not green,
and text that remains unchanged is now using the editor foreground color
instead of blue).

### Breaking changes
Tests that use `#guard_msgs` to test the "Try this:" message may need to
be adjusted for the new formatting of the message.
2025-08-26 12:15:32 +00:00

99 lines
2.3 KiB
Text

module
public meta import Lean.Elab.Tactic
public import Lean.Elab.Tactic.Try
public import Std.Tactic.BVDecide
open Lean Elab Tactic Try
elab tk:"eval_suggest" tac:tactic : tactic => do
evalAndSuggest tk tac
set_option hygiene false in
macro "try_simple?" : tactic => `(tactic| eval_suggest (intros; attempt_all | rfl | (first | simp?; done | simp? +arith; done | simp_all) | grind?))
opaque f : Nat → Nat
@[simp, grind =] theorem fthm : f x = x := sorry
/--
info: Try these:
• simp +arith
• simp +arith only [Nat.reduceAdd, fthm]
• grind
• grind only [= fthm]
-/
#guard_msgs (info) in
example (x : Nat) : 1 + 1 + f x = x + 2 := by
try_simple?
/--
info: Try these:
• rfl
• simp
• simp only [Nat.succ_eq_add_one, Nat.add_left_cancel_iff]
• grind
• grind only
-/
#guard_msgs (info) in
example (x : Nat) : x + 1 = Nat.succ x := by
try_simple?
/--
info: Try these:
• · intros; rfl
• · intros; simp
• · intros; simp only [Nat.succ_eq_add_one, Nat.add_left_cancel_iff]
• · intros; grind
• · intros; grind only
-/
#guard_msgs (info) in
example (x : Nat) : True → x + 1 = Nat.succ x := by
try_simple?
/--
info: Try these:
• simp_all
• grind
• grind only
-/
#guard_msgs (info) in
example (h : 0 + x = y) : f x = f y := by
try_simple?
macro "bad_tac" : tactic => `(tactic| eval_suggest (intros; (attempt_all | rfl | grind?); simp))
/--
error: Tactic `try?` failed: consider using `grind` manually, or `try? +missing` for partial proofs containing `sorry`
⊢ True
-/
#guard_msgs (error) in
example : True := by
bad_tac
macro "simple_tac" : tactic => `(tactic| eval_suggest (intros; skip; first | skip | simp))
/--
info: Try this:
simp
-/
#guard_msgs (info) in
example : True ∧ True := by
simple_tac -- terminal `skip` should not succeed
example : False := by
fail_if_success simple_tac -- should not succeed
sorry
set_option hygiene false in
macro "simple_tac2" : tactic => `(tactic| eval_suggest (intros; (simp only [Nat.zero_add]; simp only [Nat.one_mul]); simp [*]))
/--
info: Try this:
· intros; simp only [Nat.zero_add]; simp only [Nat.one_mul]; simp [*]
-/
#guard_msgs (info) in
example : x = 0 → 0 + 1*x = 0 := by
simple_tac2
example : x = 0 → 0 + 1*x = 0 := by
· intros; (simp only [Nat.zero_add]; simp only [Nat.one_mul]); simp [*]