123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124moduleLsp=Fleche_lspopenPetanque_json(* Client wrap *)moduletypeChans=sigvalic:in_channelvaloc:Format.formattervaltrace:?verbose:string->string->unitvalmessage:lvl:int->message:string->unitend(* Display incoming requests *)letdisplay_requests=falseletmaybe_display_requestmethod_=ifdisplay_requeststhenFormat.eprintf"received request: %s@\n%!"method_letdo_trace~traceparams=matchLsp.Base.TraceParams.of_yojson(`Assocparams)with|Ok{message;verbose}->trace?verbosemessage|Error_->()letdo_message~messageparams=matchLsp.Base.MessageParams.of_yojson(`Assocparams)with|Ok{type_;message=msg}->message~lvl:type_~message:msg|Error_->()(* Read until we find a response *)letrecread_response~trace~messageic=matchLsp.Io.read_messageicwith|Some(Ok(Lsp.Base.Message.Responser))->Okr|Some(Ok(Notification{method_;params}))whenString.equalmethod_Lsp.Base.TraceParams.method_->do_trace~traceparams;read_response~trace~messageic|Some(Ok(Notification{method_;params}))whenString.equalmethod_Lsp.Base.MessageParams.method_->do_message~messageparams;read_response~trace~messageic|Some(Ok(Request{method_;_}))|Some(Ok(Notification{method_;_}))->maybe_display_requestmethod_;read_response~trace~messageic|Some(Errorerr)->Errorerr|None->assertfalse(* not in our testing setup *)letid_counter=ref0letget_id()=incrid_counter;!id_countermoduleWrap(R:Protocol.Request.S)(C:Chans):sigvalcall:R.Params.t->(R.Response.t,string)Result.tend=structlettrace=C.traceletmessage=C.messageletcallparams=letid=get_id()inletmethod_=R.method_inletparams=Yojson.Safe.Util.to_assoc(R.Params.to_yojsonparams)inletrequest=Lsp.Base.Request.make~id~method_~params()inlet()=Lsp.Io.send_messageC.oc(Lsp.Base.Message.Requestrequest)inread_response~trace~messageC.ic|>funr->Result.bindr(function|Ok{id=_;result}->R.Response.of_yojsonresult|Error{id=_;code=_;message;data=_}->Errormessage)endmoduleS(C:Chans)=structopenProtocolopenProtocol_shell(* Shell calls (they do have an equivalent version in LSP) *)letset_workspace=letmoduleM=Wrap(SetWorkspace)(C)inM.calllettoc=letmoduleM=Wrap(TableOfContents)(C)inM.call(* Standard calls *)letget_root_state=letmoduleM=Wrap(GetRootState)(C)inM.callletget_state_at_pos=letmoduleM=Wrap(GetStateAtPos)(C)inM.callletstart=letmoduleM=Wrap(Start)(C)inM.callletrun=letmoduleM=Wrap(RunTac)(C)inM.callletgoals=letmoduleM=Wrap(Goals)(C)inM.callletpremises=letmoduleM=Wrap(Premises)(C)inM.callletstate_equal=letmoduleM=Wrap(StateEqual)(C)inM.callletstate_hash=letmoduleM=Wrap(StateHash)(C)inM.callletstate_proof_equal=letmoduleM=Wrap(StateProofEqual)(C)inM.callletstate_proof_hash=letmoduleM=Wrap(StateProofHash)(C)inM.callend