This PR adds a new definition `Message.kind` which returns the top-level tag of a message. This is serialized as the new field `kind` in `SerialMessaege` so that i can be used by external consumers (e.g., Lake) to identify messages via `lean --json`. The tag of trace messages has also been changed from `_traceMsg` to the more friendly `trace`.
26 lines
820 B
Text
26 lines
820 B
Text
import Lean.Elab.Command
|
|
|
|
open Lean Elab Command
|
|
|
|
elab tk:"#guard_msg_kind " kind:ident " in " cmd:command : command => do
|
|
let initMsgs ← modifyGet fun st => (st.messages, {st with messages := {}})
|
|
elabCommandTopLevel cmd
|
|
let msgs ← modifyGet fun st => (st.messages, {st with messages := initMsgs})
|
|
let kind := kind.getId
|
|
for msg in msgs.toList do
|
|
if msg.kind != kind then
|
|
logErrorAt tk s!"expected {kind}, got {msg.kind}"
|
|
|
|
/- Test inferring kind from a tag. -/
|
|
#guard_msg_kind custom in
|
|
run_cmd do logInfo <| .tagged `custom ""
|
|
|
|
/- Test trace message kind. -/
|
|
#guard_msg_kind trace in
|
|
set_option trace.Elab.step true in
|
|
def trace := ()
|
|
|
|
/- Test linter kind. -/
|
|
#guard_msg_kind linter.unusedVariables in
|
|
#guard_msgs (info) in -- hack to avoid re-triggering the linter
|
|
def unused (x : Unit) := ()
|