123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687openFleche(* Put these in an utility function for plugins *)letof_execution~io~what(v:(_,_)Coq.Protect.E.t)=matchvwith|{r;feedback=_}->(matchrwith|Coq.Protect.R.Completed(Okgoals)->goals|Coq.Protect.R.Completed(Error(Anomalyerr))|Coq.Protect.R.Completed(Error(Usererr))->letmessage=Format.asprintf"error when retrieving %s: %a"whatPp.pp_with(snderr)inIo.Report.message~io~lvl:Io.Level.error~message;None|Coq.Protect.R.Interrupted->None)(* We output a record for each sentence in the document, linear order. Note that
for unparseable nodes, we don't have an AST. *)moduleAstGoals=struct(* Just to bring the serializers in scope *)moduleLang=Lsp.JLangmoduleCoq=Lsp.JCoqtype'at={raw:string;range:Lang.Range.t;ast:Coq.Ast.toption;goals:'aCoq.Goals.reified_ppoption}[@@derivingto_yojson]letof_node~io~token~(contents:Contents.t)(node:Doc.Node.t)=letrange=node.rangeinletraw=Fleche.Contents.extract_raw~contents~rangeinletast=Option.map(funn->n.Doc.Node.Ast.v)node.astinletst=node.stateinletgoals=of_execution~io~what:"goals"(Info.Goals.goals~token~st)in{raw;range;ast;goals}endletpp_jsonppfmt(astgoal:_AstGoals.t)=letg_json=AstGoals.to_yojsonppastgoalinYojson.Safe.pretty_printfmtg_json(* For now we have not added sexp serialization, but we can easily do so *)(* let pp_sexp fmt (astgoal : AstGoals.t) = *)(* let g_sexp = AstGoals.sexp_of astgoal in *)(* Sexplib.Sexp.pp_hum fmt sast *)letpwppfmtv=Format.fprintffmt"@[%a@]@\n"ppvletpp_ast_goals~io~token~contentsppfmtnode=letres=AstGoals.of_node~io~token~contentsnodeinpwppfmtresletdump_goals~io~token~out_file~(doc:Doc.t)pp=letout=Stdlib.open_outout_fileinletfmt=Format.formatter_of_out_channeloutinletcontents=doc.contentsinList.iter(pp_ast_goals~io~token~contentsppfmt)doc.nodes;Format.pp_print_flushfmt();Stdlib.close_outoutletdump_ast~io~token~(doc:Doc.t)=leturi=doc.uriinleturi_str=Lang.LUri.File.to_string_uriuriinletmessage=Format.asprintf"[goaldump plugin] dumping goals for %s ..."uri_strinletlvl=Io.Level.infoinIo.Report.message~io~lvl~message;letout_file_j=Lang.LUri.File.to_string_fileuri^".json.goaldump"inletppd=`String(Pp.string_of_ppcmdsd)in(* Uncomment to output Pp-formatted goals *)(* let pp d = Lsp.JCoq.Pp.to_yojson d in *)let()=dump_goals~io~token~out_file:out_file_j~doc(pp_jsonpp)in(* let out_file_s = Lang.LUri.File.to_string_file uri ^ ".sexp.goaldump" in *)(* let () = dump_goals ~out_file:out_file_s ~doc pp_sexp in *)letmessage=Format.asprintf"[ast plugin] dumping ast for %s was completed!"uri_strinIo.Report.message~io~lvl~message;()letmain()=Theory.Register.Completed.adddump_astlet()=main()