123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960(* Example plugin to print errors with goals *)(* c.f. https://github.com/coq/coq/issues/19601 *)openFlecheletmsg_info~io=Io.(Report.msg~io~lvl:Info)letpp_goals~token~st=matchCoq.State.lemmas~stwith|None->Pp.str"no goals"|Someproof->(matchCoq.Print.pr_goals~token~proofwith|{Coq.Protect.E.r=Completed(Okgoals);_}->goals|{Coq.Protect.E.r=Completed(Error(User{msg;_}|Anomaly{msg;_}));_}->Pp.(str"error when printing goals: "++msg)|{Coq.Protect.E.r=Interrupted;_}->Pp.str"goal printing was interrupted")moduleError_info=structtypet={error:Pp.t;command:string;goals:Pp.t}letprint~io{error;command;goals}=msg_info~io"[explain errors plugin]@\n\
Error:@\n\
\ @[%a@]@\n\
@\n\
when trying to apply@\n\
@\n\
\ @[%s@]@\n\
for goals:@\n\
\ @[%a@]"Pp.pp_witherrorcommandPp.pp_withgoalsendletextract_errors~token~root~contents(node:Doc.Node.t)=leterrors=List.filterLang.Diagnostic.is_errornode.diagsinletst=Option.cataDoc.Node.staterootnode.previnletcommand=Contents.extract_raw~contents~range:node.rangeinletgoals=pp_goals~token~stinList.map(fun{Lang.Diagnostic.message;_}->{Error_info.error=message;command;goals})errorsletexplain_error~io~token~(doc:Doc.t)=letroot=doc.rootinletcontents=doc.contentsinleterrors=List.(map(extract_errors~token~root~contents)doc.nodes|>concat)inmsg_info~io"[explain errors plugin] we got %d errors"(List.lengtherrors);List.iter(Error_info.print~io)errorsletmain()=Theory.Register.Completed.addexplain_errorlet()=main()