123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687(************************************************************************)(* * 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)letdict_fieldnamedict=U.to_assoc(List.assocnamedict)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=dict_field"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)]moduleVersionedTextDocument=structtypet={uri:string;version:int}[@@derivingyojson]end