123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122(************************************************************************)(* * 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 / SerAPI *)(* Copyright 2016-2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(**************************************************************************)(* Low-level, internal Coq initialization *)(**************************************************************************)typecoq_opts={fb_handler:Feedback.feedback->unit(** callback to handle async feedback *);load_module:string->unit(** callback to load cma/cmo files *);load_plugin:Mltop.PluginSpec.t->unit(** callback to load findlib packages *);debug:bool(** Enable Coq Debug mode *)}letcoq_initopts=(* Core Coq initialization *)Lib.init();Global.set_impredicative_setfalse;Flags.set_native_compilerfalse;Global.set_native_compilerfalse;ifopts.debugthenCDebug.set_flags"backtrace";(**************************************************************************)(* Feedback setup *)(**************************************************************************)(* Initialize logging. *)ignore(Feedback.add_feederopts.fb_handler);(* SerAPI plugins *)letload_plugin=opts.load_plugininletload_module=opts.load_modulein(* Custom toplevel is used for bytecode-to-js dynlink *)letser_mltop:Mltop.toplevel=letopenMltopin{load_plugin;load_module;add_dir=(fun_->());ml_loop=(fun_->())}inMltop.set_topser_mltop;(**************************************************************************)(* Add root state!! *)(**************************************************************************)Vernacstate.freeze_interp_state~marshallable:false|>State.of_coq(* End of initialization *)letloadpath_from_coqproject():Loadpath.vo_pathlist=ifnot(Sys.file_exists"_CoqProject")then[]elselet(* Io.Log.error "init" "Parsing _CoqProject"; *)openCoqProject_fileinletto_vo_loadpathfimplicit=letopenLoadpathinletunix_path,coq_path=fin(* Lsp.Io.log_error "init"
* (Printf.sprintf "Path from _CoqProject: %s %s" unix_path.path coq_path); *){implicit;recursive=true;has_ml=false;unix_path=unix_path.path;coq_path=Libnames.dirpath_of_stringcoq_path}inlet{r_includes;q_includes;_}=read_project_file~warning_fn:(fun_->())"_CoqProject"inletvo_path=List.map(funf->to_vo_loadpathf.thingfalse)q_includesinList.appendvo_path(List.map(funf->to_vo_loadpathf.thingtrue)r_includes)(* Inits the context for a document *)letdoc_init~root_state~vo_load_path~ml_include_path~libname~require_libs=(* Lsp.Io.log_error "init" "starting"; *)Vernacstate.unfreeze_interp_state(State.to_coqroot_state);(* This should go away in Coq itself *)Safe_typing.allow_delayed_constants:=true;letload_objslibs=letrq_file(dir,from,exp)=letmp=Libnames.qualid_of_stringdirinletmfrom=Option.mapLibnames.qualid_of_stringfrominFlags.silently(Vernacentries.vernac_requiremfromexp)[(mp,Vernacexpr.ImportAll)]inList.(iterrq_file(revlibs))in(* Set load path; important, this has to happen before we declare the library
below as [Declaremods/Library] will infer the module name by looking at the
load path! *)List.iterMltop.add_ml_dirml_include_path;List.iterLoadpath.add_vo_pathvo_load_path;List.iterLoadpath.add_vo_path(loadpath_from_coqproject());Declaremods.start_librarylibname;(* Import initial libraries. *)load_objsrequire_libs;(* We return the state at this point! *)Vernacstate.freeze_interp_state~marshallable:false|>State.of_coq