123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114(************************************************************************)(* * 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 -- Requests *)(* Copyright 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Copyright 2019-2023 Inria -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)moduleError=structtype'at={code:int;payload:'a;feedback:Lang.Range.tCoq.Message.tlist}letmake?(feedback=[])codepayload={code;payload;feedback}letmap~f{code;payload;feedback}=letpayload=fpayloadin{code;payload;feedback}endmoduleR=structtype('r,'e)t=('r,'eError.t)Result.tletmap_error~f=Result.map_error(Error.map~f)letcode=-32803letprint_err~namee=matchewith|Coq.Protect.Error.Anomaly{msg;_}|User{msg;_}->Format.asprintf"Error in %s request: %a"namePp.pp_withmsgletof_execution~lines~name~fx:('r,string)t=letCoq.Protect.E.{r;feedback}=fxinletf=Coq.Utils.to_range~linesinletfeedback=List.map(Coq.Message.map~f)feedbackinmatchrwith|Interrupted->letpayload=name^" request interrupted"inError{code;payload;feedback}|Completed(Errore)->letpayload=print_err~nameeinError{code;payload;feedback}|Completed(Okr)->(* Fleche.Io.Log.feedback feedback; *)rendtype('r,'e)document=token:Coq.Limits.Token.t->doc:Fleche.Doc.t->('r,'e)R.ttype('r,'e)position=token:Coq.Limits.Token.t->doc:Fleche.Doc.t->point:int*int->('r,'e)R.t(** Requests that require data access *)moduleData=structtype('r,'e)t=|Immediateof{uri:Lang.LUri.File.t;handler:('r,'e)document}|DocRequestof{uri:Lang.LUri.File.t;postpone:bool;handler:('r,'e)document}|PosRequestof{uri:Lang.LUri.File.t;point:int*int;version:intoption;postpone:bool;handler:('r,'e)position}(* Debug printing *)letdatafmt=function|Immediate{uri=_;handler=_}->Format.fprintffmt"{k:imm }"|DocRequest{uri=_;postpone;handler=_}->Format.fprintffmt"{k:doc | p: %B}"postpone|PosRequest{uri=_;point;version;postpone;handler=_}->Format.fprintffmt"{k:pos | l: %d, c: %d v: %a p: %B}"(fstpoint)(sndpoint)Format.(pp_print_optionpp_print_int)versionpostponeletdm_requestpr=matchprwith|Immediate{uri;handler=_}->(uri,false,Fleche.Theory.Request.Immediate)|DocRequest{uri;postpone;handler=_}->(uri,postpone,Fleche.Theory.Request.FullDoc)|PosRequest{uri;point;version;postpone;handler=_}->(uri,postpone,Fleche.Theory.Request.(PosInDoc{point;version}))letserve~token~docpr=matchprwith|Immediate{uri=_;handler}->handler~token~doc|DocRequest{uri=_;postpone=_;handler}->handler~token~doc|PosRequest{uri=_;point;version=_;postpone=_;handler}->handler~token~point~docend