Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file base.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131(************************************************************************)(* * 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+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* Status: Experimental *)(************************************************************************)(* This file contains some coq-specific commands, we should instead
functorialize it so we can share with other OCaml-specific tools *)(* Whether to send extended lsp messages *)letstd_protocol=reftruelet_mk_extral=if!std_protocolthen[]elsel(* Ad-hoc parsing for file:///foo... *)let_parse_uristr=letl=String.lengthstr-7inString.(substr7l)moduleJ=Yojson.SafemoduleU=Yojson.Safe.Utilletstring_fieldnamedict=U.to_stringList.(assocnamedict)letdict_fieldnamedict=U.to_assoc(List.assocnamedict)moduleMessage=structtypet=|Notificationof{method_:string;params:(string*Yojson.Safe.t)list}|Requestof{id:int;method_:string;params:(string*Yojson.Safe.t)list}(** Reify an incoming message *)letfrom_yojsonmsg=tryletdict=U.to_assocmsginletmethod_=string_field"method"dictinletparams=dict_field"params"dictin(matchList.assoc_opt"id"dictwith|None->Notification{method_;params}|Someid->letid=U.to_intidinRequest{id;method_;params})|>Result.okwith|Not_found->Error("missing parameter: "^J.to_stringmsg)|U.Type_error(msg,obj)->Error(Format.asprintf"msg: %s; obj: %s"msg(J.to_stringobj))letmethod_=function|Notification{method_;_}|Request{method_;_}->method_letparams=function|Notification{params;_}|Request{params;_}->paramsendletmk_reply~id~result=`Assoc[("jsonrpc",`String"2.0");("id",`Intid);("result",result)]letmk_request_error~id~code~message=`Assoc[("jsonrpc",`String"2.0");("id",`Intid);("error",`Assoc[("code",`Intcode);("message",`Stringmessage)])]letmk_notification~method_~params=`Assoc[("jsonrpc",`String"2.0");("method",`Stringmethod_);("params",`Assocparams)](* let json_of_goal g = let pr_hyp (s,(_,t)) = `Assoc ["hname", `String s;
"htype", `String (Format.asprintf "%a" Print.pp_term (Bindlib.unbox t))] in
let open Proofs in let j_env = List.map pr_hyp g.g_hyps in `Assoc [ "gid",
`Int g.g_meta.meta_key ; "hyps", `List j_env ; "type", `String
(Format.asprintf "%a" Print.pp_term g.g_type)]
let json_of_thm thm = let open Proofs in match thm with | None -> `Null |
Some thm -> `Assoc [ "goals", `List List.(map json_of_goal thm.t_goals) ] *)letmk_range{Fleche.Types.Range.start;end_}:J.t=`Assoc[("start",`Assoc[("line",`Intstart.line);("character",`Intstart.character)]);("end",`Assoc[("line",`Intend_.line);("character",`Intend_.character)])](* let mk_diagnostic ((p : Pos.pos), (lvl : int), (msg : string), (thm :
Proofs.theorem option)) : J.json = *)letmk_diagnostic((r:Fleche.Types.Range.t),(lvl:int),(msg:string),(_thm:unitoption)):J.t=(* let goal = json_of_thm thm in *)letrange=mk_rangerin`Assoc[(* mk_extra ["goal_info", goal] @ *)("range",range);("severity",`Intlvl);("message",`Stringmsg)]letmk_diagnostics~uri~versionld:J.t=mk_notification~method_:"textDocument/publishDiagnostics"~params:[("uri",`Stringuri);("version",`Intversion);("diagnostics",`ListList.(mapmk_diagnosticld))]