Skip to content

Commit 14acf8e

Browse files
committed
fix: log tactic analysis messages on correct range (leanprover-community#28919)
The tactic analysis framework attempts to log messages on a synthetic concatenation of tactics (`` `(tactic|$tacticSeq;*)``). However, this inserts position info from the current ref in the tactic sequence nodes, and so messages are logged on the current ref (in this case, the whole command). This PR works around this by setting the ref to the input array of tactics via `mkNullNode`. (Note that VS code cannot log on disjoint ranges, so Lean's `log*` family of functions only logs on the first line of multiline ranges. Hence, logging on the full tactic sequence range results in a squiggly line under only the first line of the tactic. This is unrelated to the current fix.)
1 parent 93fccc9 commit 14acf8e

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

Mathlib/Tactic/TacticAnalysis.lean

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,21 @@ from the start of the sequence. -/
282282
def testTacticSeq (config : ComplexConfig) (tacticSeq : Array (TSyntax `tactic))
283283
(ctxI : ContextInfo) (i : TacticInfo) (ctx : config.ctx) :
284284
CommandElabM Unit := do
285-
let stx ← `(tactic| $(tacticSeq);*)
286-
-- TODO: support more than 1 goal. Probably by requiring all tests to succeed in a row
287-
if let [goal] := i.goalsBefore then
288-
let (oldGoals, oldHeartbeats) ← withHeartbeats <|
289-
try
290-
ctxI.runTacticCode i goal stx
291-
catch e =>
292-
logWarningAt stx m!"original tactic '{stx}' failed: {e.toMessageData}"
293-
return [goal]
294-
let (new, newHeartbeats) ← withHeartbeats <| ctxI.runTactic i goal <| config.test ctx
295-
if let some msg := config.tell stx oldGoals oldHeartbeats new newHeartbeats then
296-
logWarningAt stx msg
285+
/- Syntax quotations use the current ref's position info even for nodes which do not usually
286+
carry position info. We set the ref here to ensure we log messages on the correct range. -/
287+
withRef (mkNullNode tacticSeq) do
288+
let stx ← `(tactic| $tacticSeq;*)
289+
-- TODO: support more than 1 goal. Probably by requiring all tests to succeed in a row
290+
if let [goal] := i.goalsBefore then
291+
let (oldGoals, oldHeartbeats) ← withHeartbeats <|
292+
try
293+
ctxI.runTacticCode i goal stx
294+
catch e =>
295+
logWarning m!"original tactic '{stx}' failed: {e.toMessageData}"
296+
return [goal]
297+
let (new, newHeartbeats) ← withHeartbeats <| ctxI.runTactic i goal <| config.test ctx
298+
if let some msg := config.tell stx oldGoals oldHeartbeats new newHeartbeats then
299+
logWarning msg
297300

298301
/-- Run the `config` against a sequence of tactics, using the `trigger` to determine which
299302
subsequences should be `test`ed. -/

0 commit comments

Comments
 (0)