123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105(************************************************************************)(* * 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 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Copyright 2019-2022 Inria -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)moduleSetup=structtypet={vo_load_path:Loadpath.vo_pathlist;ml_include_path:stringlist;options:(Goptions.option_name*Coqargs.option_command)list(** This includes warnings *)}letappendbase{vo_load_path;ml_include_path;options}={vo_load_path=base.vo_load_path@vo_load_path;ml_include_path=base.ml_include_path@ml_include_path;options=base.options@options}endtypet=Setup.t*string(* | CoqProject of Setup.t *)(* | Dune *)letapply({Setup.vo_load_path;ml_include_path;options},_)=List.iterMltop.add_ml_dirml_include_path;List.iterLoadpath.add_vo_pathvo_load_path;List.iterCoqargs.set_optionoptions;()(* TODO, parse _CoqProject extra_args in Coq format *)letparse_coq_args_=[]letloadpath_from_coqproject():Setup.t=(* Io.Log.error "init" "Parsing _CoqProject"; *)letopenCoqProject_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;ml_includes;extra_args;_}=read_project_file~warning_fn:(fun_->())"_CoqProject"inletml_include_path=List.map(funf->f.thing.path)ml_includesinletvo_path=List.map(funf->to_vo_loadpathf.thingfalse)q_includesinletvo_load_path=List.appendvo_path(List.map(funf->to_vo_loadpathf.thingtrue)r_includes)inletoptions=parse_coq_argsextra_argsin{vo_load_path;ml_include_path;options}letcoq_loadpath_default~implicitcoq_path=letmk_pathprefix=coq_path^"/"^prefixinletmk_lp~ml~root~dir~implicit={Loadpath.unix_path=mk_pathdir;coq_path=root;has_ml=ml;implicit;recursive=true}inletcoq_root=Names.DirPath.make[Libnames.coq_root]inletdefault_root=Libnames.default_root_prefixin{Setup.vo_load_path=[mk_lp~ml:false~root:coq_root~implicit~dir:"theories";mk_lp~ml:true~root:default_root~implicit:false~dir:"user-contrib"];ml_include_path=(letunix_path=Filename.concatcoq_path"../coq-core/plugins"inSystem.all_subdirs~unix_path|>List.mapfst);options=[]}(* We append the default loadpath, TODO, support -noinit *)letguess~coqlib~cmdline=letvo_workspace,origin=ifSys.file_exists"_CoqProject"then(loadpath_from_coqproject(),Filename.concat(Sys.getcwd())"_CoqProject")else(cmdline,"Command-line arguments")in(* Import stdlib without `From Coq` requirement *)letimplicit=truein(Setup.append(coq_loadpath_default~implicitcoqlib)vo_workspace,origin)