lean4-htt/tests/lean/run/hintPreviewSpan.lean
jrr6 17a477393c
feat: allow custom preview spans in hint suggestions (#9555)
This PR allows hints in message data to specify custom preview spans
that extend beyond the edit region specified by the code action.
2025-07-26 00:04:28 +00:00

69 lines
1.4 KiB
Text

import Lean.Meta
/-!
# Preview spans for hints in messages
Tests rendering of hint suggestion preview spans in message data.
-/
open Lean Meta Hint
/-! ## Valid span appears -/
elab "suggest_id_insertion" _id:ident t:term : term <= tp => do
let p := t.raw.getPos?.get!
let hint ← MessageData.hint "Insert `id`" #[{
suggestion := "id "
span? := Syntax.ofRange ⟨p, p⟩
previewSpan? := t
}]
logInfo <| m!"Message" ++ hint
Lean.Elab.Term.elabTerm t tp
/--
info: Message
Hint: Insert `id`
i̲d̲ ̲true
-/
#guard_msgs in
example := suggest_id_insertion Foo true
elab "one" "two" tk:"three" "four" "five" : term => do
let hint ← MessageData.hint "Insert `id`" #[{
suggestion := "ee"
span? := tk
previewSpan? := (← getRef)
}]
logInfo m!"Message{hint}"
return .const ``Unit.unit []
/--
info: Message
Hint: Insert `id`
one two t̵h̵r̵ee four five
-/
#guard_msgs in
example := one two three four five
/-! ## Fallback appears in case of erroneous span -/
elab "bad_suggest_id_insertion" id:ident t:term : term <= tp => do
let p := t.raw.getPos?.get!
let hint ← MessageData.hint "Insert `id`" #[{
suggestion := "id "
span? := Syntax.ofRange ⟨p, p⟩
previewSpan? := id -- does not include edit range
}]
logInfo <| m!"Message" ++ hint
Lean.Elab.Term.elabTerm t tp
/--
info: Message
Hint: Insert `id`
i̲d̲ ̲
-/
#guard_msgs in
example := bad_suggest_id_insertion Foo true