1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980moduleLsp=Fleche_lspopenFleche(* 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(Anomaly{msg;_}))|Coq.Protect.R.Completed(Error(User{msg;_}))->letlvl=Io.Level.ErrorinIo.Report.msg~io~lvl"error when retrieving %s: %a"whatPp.pp_withmsg;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)=AstGoals.to_yojsonppastgoal|>Yojson.Safe.pretty_printfmt(* For now we have not added sexp serialization, but we can easily do so *)(* let pp_sexp fmt (astgoal : AstGoals.t) = *)(* AstGoals.sexp_of astgoal *)(* |> Sexplib.Sexp.pp_hum fmt *)letpwppfmtv=Format.fprintffmt"@[%a@]@\n"ppvletpp_ast_goals~io~token~contentsppfmtnode=AstGoals.of_node~io~token~contentsnode|>pwppfmtletdump_goals~io~token~out_file~(doc:Doc.t)pp=letcontents=doc.contentsinletffmtnodes=List.iter(pp_ast_goals~io~token~contentsppfmt)nodesinCoq.Compat.format_to_file~file:out_file~fdoc.nodesletppd=(* Set to true to output Pp-formatted goals *)letoutput_pp=falseinifoutput_ppthenLsp.JCoq.Pp.to_yojsondelse`String(Pp.string_of_ppcmdsd)letdump_ast~io~token~(doc:Doc.t)=leturi=doc.uriinleturi_str=Lang.LUri.File.to_string_uriuriinletlvl=Io.Level.InfoinIo.Report.msg~io~lvl"[goaldump plugin] dumping goals for %s ..."uri_str;letout_file_j=Lang.LUri.File.to_string_fileuri^".json.goaldump"inlet()=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 *)Io.Report.msg~io~lvl"[goaldump plugin] dumping ast for %s was completed!"uri_str;()letmain()=Theory.Register.Completed.adddump_astlet()=main()