123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081(************************************************************************)(* * 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 2022-2023 Inria -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* We convert in case of failure to some default values *)letutf16_offset_of_utf8_offset~lines~line~byte=ifline<Array.lengthlinesthenletline=Array.getlineslineinLang.Utf.utf16_offset_of_utf8_offset~line~offset:byteelse0letto_range~lines(p:Loc.t):Lang.Range.t=letLoc.{line_nb;line_nb_last;bol_pos;bol_pos_last;bp;ep;_}=pinletstart_line=line_nb-1inletend_line=line_nb_last-1in(* cols *)letstart_col=bp-bol_posinletend_col=ep-bol_pos_lastinletstart_col=utf16_offset_of_utf8_offset~lines~line:start_line~byte:start_colinletend_col=utf16_offset_of_utf8_offset~lines~line:end_line~byte:end_colinLang.Range.{start={line=start_line;character=start_col;offset=bp};end_={line=end_line;character=end_col;offset=ep}}letto_orange~lines=Option.map(to_range~lines)letwith_failfn=tryfn();CErrors.user_err(Pp.str"The command has not failed!")withexnwhenCErrors.noncriticalexn->letexn=Exninfo.captureexninletmsg=CErrors.iprintexninFeedback.msg_notice?loc:NonePp.(str"The command has indeed failed with message:"++fnl()++msg)letwith_ctrlctrl~st~fn=letst=State.to_coqstinmatchctrlwith|Vernacexpr.ControlTimebatch->letheader=Pp.mt()inSystem.with_time~batch~headerfn()|Vernacexpr.ControlTimeoutn->(matchControl.timeout(float_of_intn)fn()with|None->Exninfo.iraise(Exninfo.captureCErrors.Timeout)|Somex->x)(* fail and succeed *)|Vernacexpr.ControlFail->with_failfn;Vernacstate.invalidate_cache();Vernacstate.unfreeze_interp_statest|Vernacexpr.ControlSucceed->fn();Vernacstate.invalidate_cache();Vernacstate.unfreeze_interp_statest(* Unsupported by coq-lsp, maybe deprecate upstream *)|Vernacexpr.ControlRedirect_->fn()letwith_control~fn~control~st=List.fold_right(functrlfn()->with_ctrlctrl~st~fn)controlfn()