TryThis.addSuggestion mis-indents tactic sequences
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
The TryThis suggestions API mis-indents tactic sequences. This means that (a) the info message is formatted incorrectly and (b) when clicking the code action, the tactic sequence is inserted in the wrong place, creating a syntax error. MWE:
import Lean
open Lean Lean.Meta.Tactic
elab "suggest_tac_seq" : tactic => do
let tacSeq ← `(tacticSeq|
skip
skip)
TryThis.addSuggestion (← getRef) {
suggestion := .tsyntax tacSeq
}
example : True := by
suggest_tac_seq
trivial
/-
(a) Info message:
Try this:
skip
skip
(b) Result of applying the code action:
example : True := by
skip
skip
trivial
-/
There are also more challenging examples, but I wouldn't expect these to be formatted correctly (though this one actually remains syntactically correct).
import Lean
open Lean Lean.Meta.Tactic
elab "suggest_tac_seq" : tactic => do
let tacSeq ← `(tacticSeq|
skip
skip)
TryThis.addSuggestion (← getRef) {
suggestion := .tsyntax tacSeq
}
example : True := by
first | suggest_tac_seq | fail
trivial
/-
example : True := by
first |
skip
skip | fail
trivial
-/
Context
aesop? uses this functionality pervasively. I previously worked around the indentation issues, but nightly breaks the workaround (Zulip).
Versions
Lean 4.24.0-nightly-2025-08-26
Target: x86_64-unknown-linux-gnu
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimal examples against the cited Lean nightly, then inspect the TryThis.addSuggestion entry point and its tactic-sequence formatting and code-action insertion paths. Done means the info message uses correct indentation and applying the suggestion inserts the sequence in the correct location without introducing a syntax error.
Written by the indexing model from the issue text.
Assessment
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100