123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(************************************************************************)(* Coq Language Server Protocol *)(* Copyright 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* Status: Experimental *)(************************************************************************)(* This file contains some coq-specific commands, we should instead
functorialize it so we can share with other OCaml-specific tools *)moduleJ=Yojson.SafemoduleU=Yojson.Safe.Utilletint_fieldnamedict=U.to_intList.(assocnamedict)letstring_fieldnamedict=U.to_stringList.(assocnamedict)moduleParams=structtypet=(string*Yojson.Safe.t)listletto_yojsondict=`AssocdictendmoduleNotification=structtypet={method_:string;params:Params.t}letmake~method_~params()={method_;params}letto_yojson{method_;params}=letparams=[("params",Params.to_yojsonparams)]in`Assoc([("jsonrpc",`String"2.0");("method",`Stringmethod_)]@params)endmoduleRequest=structtypet={id:int;method_:string;params:Params.t}letmake~method_~id~params()={id;method_;params}letto_yojson{method_;id;params}=letparams=[("params",Params.to_yojsonparams)]in`Assoc([("jsonrpc",`String"2.0");("id",`Intid);("method",`Stringmethod_)]@params)endmoduleResponse=structtypet=|Okof{id:int;result:Yojson.Safe.t}|Errorof{id:int;code:int;message:string;data:Yojson.Safe.toption}letmk_ok~id~result=Ok{id;result}letmk_error~id~code~message=Error{id;code;message;data=None}letid=function|Ok{id;_}|Error{id;_}->idletto_yojson=function|Ok{id;result}->`Assoc[("jsonrpc",`String"2.0");("id",`Intid);("result",result)]|Error{id;code;message;data=_}->`Assoc[("jsonrpc",`String"2.0");("id",`Intid);("error",`Assoc[("code",`Intcode);("message",`Stringmessage)])]endmoduleMessage=structtypet=|NotificationofNotification.t|RequestofRequest.t|ResponseofResponse.tletresponse_of_yojsondict=letid=int_field"id"dictinmatchList.assoc_opt"error"dictwith|None->letresult=List.assoc"result"dictinResponse.Ok{id;result}|Someerror->leterror=U.to_assocerrorinletcode=int_field"code"errorinletmessage=string_field"message"errorinletdata=NoneinError{id;code;message;data}letrequest_of_yojsonmethod_dict=letparams=List.assoc_opt"params"dict|>Option.mapU.to_assoc|>Option.default[]inmatchList.assoc_opt"id"dictwith|None->Notification{Notification.method_;params}|Someid->letid=U.to_intidinRequest{Request.id;method_;params}letof_yojsonmsg=letdict=U.to_assocmsginmatchList.assoc_opt"method"dictwith|None->Response(response_of_yojsondict)|Somemethod_->request_of_yojson(U.to_stringmethod_)dictletof_yojsonmsg=tryof_yojsonmsg|>Result.okwith|Not_found->Error("missing parameter: "^J.to_stringmsg)|U.Type_error(msg,obj)->Error(Format.asprintf"msg: %s; obj: %s"msg(J.to_stringobj))letto_yojson=function|Notificationn->Notification.to_yojsonn|Requestr->Request.to_yojsonr|Responser->Response.to_yojsonrletnotificationn=Notificationnletresponser=ResponserendmoduleProgressToken:sigtypet=|Stringofstring|Intofint[@@derivingyojson]end=structtypet=|Stringofstring|Intofintletof_yojsonx=matchxwith|`Strings->Result.ok(Strings)|`Inti->Result.ok(Inti)|_->Result.error"failure to parse ProgressToken.t"letto_yojson=function|Strings->`Strings|Inti->`IntiendmoduleProgressParams=structtype'at={token:ProgressToken.t;value:'a}[@@derivingyojson]endletmk_progress~token~valuef=letparams=ProgressParams.(to_yojsonf{token;value})inletparams=U.to_assocparamsinNotification.(to_yojson{method_="$/progress";params})moduleWorkDoneProgressBegin=structtypet={kind:string;title:string;cancellable:booloption[@None];message:stringoption[@None];percentage:intoption[@None]}[@@derivingto_yojson]endmoduleWorkDoneProgressReport=structtypet={kind:string;cancellable:booloption[@None];message:stringoption[@None];percentage:intoption[@None]}[@@derivingto_yojson]endmoduleWorkDoneProgressEnd=structtypet={kind:string}[@@derivingto_yojson]end