1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889(************************************************************************)(* * 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)(* Separation of parsing and execution made upstream API hard to use for us
:/ *)letpmeasure(measure,print)fn=matchmeasurefn()with|Ok_asr->Feedback.msg_notice@@printr|Error(exn,_)asr->Feedback.msg_notice@@printr;Exninfo.iraiseexnletwith_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.ControlTime->pmeasureSystem.(measure_duration,fmt_transaction_result)fn|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.Interp.invalidate_cache();Vernacstate.unfreeze_full_statest|Vernacexpr.ControlSucceed->fn();Vernacstate.Interp.invalidate_cache();Vernacstate.unfreeze_full_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()