leanprover / leanprover/lean4

TryThis.addSuggestion mis-indents tactic sequences

Open
#10,150 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.