123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139(************************************************************************)(* * 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.Utilletstring_fieldnamedict=U.to_stringList.(assocnamedict)letodict_field~defaultnamedict=Option.cataU.to_assocdefault(List.assoc_optnamedict)moduleMessage=structtypet=|Notificationof{method_:string[@key"method"];params:(string*Yojson.Safe.t)list}|Requestof{id:int;method_:string[@key"method"];params:(string*Yojson.Safe.t)list}(** Reify an incoming message *)letfrom_yojsonmsg=tryletdict=U.to_assocmsginletmethod_=string_field"method"dictinletparams=odict_field~default:[]"params"dictin(matchList.assoc_opt"id"dictwith|None->Notification{method_;params}|Someid->letid=U.to_intidinRequest{id;method_;params})|>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))letmethod_=function|Notification{method_;_}|Request{method_;_}->method_letparams=function|Notification{params;_}|Request{params;_}->paramsendletmk_reply~id~result=`Assoc[("jsonrpc",`String"2.0");("id",`Intid);("result",result)]letmk_request_error~id~code~message=`Assoc[("jsonrpc",`String"2.0");("id",`Intid);("error",`Assoc[("code",`Intcode);("message",`Stringmessage)])]letmk_notification~method_~params=`Assoc[("jsonrpc",`String"2.0");("method",`Stringmethod_);("params",params)]moduleProgressToken: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})inmk_notification~method_:"$/progress"~paramsmoduleWorkDoneProgressBegin=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