feat: remove +premises from grind? output (#11028)

This PR ensures that `grind? +premises` removes `+premises` from the
"Try this" suggestion.
This commit is contained in:
Kim Morrison 2025-10-31 14:00:33 +11:00 committed by GitHub
parent 40e1e097c1
commit 00d41d64e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -201,6 +201,21 @@ def setGrindParams (stx : TSyntax `tactic) (params : Array Syntax) : TSyntax `ta
def getGrindParams (stx : TSyntax `tactic) : Array Syntax :=
stx.raw[grindParamsPos][1].getSepArgs
/-- Filter out `+premises` from the config syntax -/
def filterPremisesFromConfig (config : TSyntax ``Lean.Parser.Tactic.optConfig) : TSyntax ``Lean.Parser.Tactic.optConfig :=
let configItems := config.raw.getArgs
let filteredItems := configItems.filter fun item =>
-- Keep all items except +premises
-- Structure: null node -> configItem -> posConfigItem -> ["+", ident]
match item[0]? with
| some configItem => match configItem[0]? with
| some posConfigItem => match posConfigItem[1]? with
| some ident => !(posConfigItem.getKind == ``Lean.Parser.Tactic.posConfigItem && ident.getId == `premises)
| none => true
| none => true
| none => true
⟨config.raw.setArgs filteredItems⟩
def mkGrindOnly
(config : TSyntax ``Lean.Parser.Tactic.optConfig)
(trace : Grind.Trace)
@ -217,7 +232,8 @@ def mkGrindOnly
else
let param ← Grind.globalDeclToGrindParamSyntax declName kind minIndexable
params := params.push param
let result ← `(tactic| grind $config:optConfig only)
let filteredConfig := filterPremisesFromConfig config
let result ← `(tactic| grind $filteredConfig:optConfig only)
return setGrindParams result params
private def elabGrindConfig' (config : TSyntax ``Lean.Parser.Tactic.optConfig) (interactive : Bool) : TacticM Grind.Config := do

View file

@ -0,0 +1,12 @@
import Lean
set_premise_selector Lean.PremiseSelection.sineQuaNonSelector
-- Test that grind? +premises does NOT include +premises in its output
/--
info: Try this:
[apply] grind only
-/
#guard_msgs in
example {x y : Nat} (h : x = y) : y = x := by
grind? +premises