package coq-lsp
Language Server Protocol native server for Coq
Install
Dune Dependency
Authors
Maintainers
Sources
coq-lsp-0.1.5.8.16.tbz
sha256=5a0819d6ceb18cf031ece2c466eefd27f018d85c1c7472038bbb7c2663714b6e
sha512=be97b25db922014681dce75a68566b887f692c60208b698f03ce8b2fc0c1a2eab5c0c563d698eeb1d21dea5405468e958e67cce9a6c94a3106529f1b4ebfce13
doc/src/coq-lsp.coq/ast.ml.html
Source file ast.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
(* module Vernacexpr = Serlib.Ser_vernacexpr *) type t = Vernacexpr.vernac_control let hash x = Serlib.Ser_vernacexpr.hash_vernac_control x let compare x y = Serlib.Ser_vernacexpr.compare_vernac_control x y let to_coq x = x let of_coq x = x let loc { CAst.loc; _ } = loc (* Printer is very fiddly w.r.t. state, especially when used for debug, so we just let it fail for now. *) let print x = try Ppvernac.pr_vernac x with _ -> Pp.str "XXX Coq printer crashed" module Id = struct type t = Names.Id.t let of_string = Names.Id.of_string let of_coq x = x let to_coq x = x module Set = Names.Id.Set module Map = Names.Id.Map end module Kinds = struct (* LSP kinds *) let _file = 1 let _module_ = 2 let _namespace = 3 let _package = 4 let class_ = 5 let method_ = 6 let _property = 7 let field = 8 let _constructor = 9 let enum = 10 let _interface = 11 let function_ = 12 let variable = 13 let _constant = 14 let _string = 15 let _number = 16 let _boolean = 17 let _array = 18 let _object = 19 let _key = 20 let _null = 21 let enumMember = 22 let struct_ = 23 let _event = 24 let _operator = 25 let _typeParameter = 26 end module Info = struct type 'l t = { range : 'l ; name : Names.Name.t CAst.t ; kind : int ; detail : string option (* usually the type *) ; children : 'l t list option } let make ~range ~name ~kind ?detail ?children () = { range; name; kind; detail; children } end let marshal_in ic : t = Marshal.from_channel ic let marshal_out oc v = Marshal.to_channel oc v [] let pp_loc ?(print_file = false) fmt loc = let open Loc in let file = if print_file then match loc.fname with | ToplevelInput -> "Toplevel input" | InFile { file; _ } -> "File \"" ^ file ^ "\"" else "loc" in Format.fprintf fmt "%s: line: %d, col: %d -- line: %d, col: %d / {%d-%d}" file (loc.line_nb - 1) (loc.bp - loc.bol_pos) (loc.line_nb_last - 1) (loc.ep - loc.bol_pos_last) loc.bp loc.ep let loc_to_string ?print_file loc = Format.asprintf "%a" (pp_loc ?print_file) loc open CAst open Vernacexpr let inductive_detail = function | Inductive_kw -> (Kinds.enum, "Inductive") | CoInductive -> (Kinds.enum, "CoInductive") | Variant -> (Kinds.struct_, "Variant") | Record -> (Kinds.struct_, "Record") | Structure -> (Kinds.struct_, "Structure") | Class _ -> (Kinds.class_, "Class") let assumption_detail = function | Decls.Definitional -> "Variable" | Logical -> "Axiom" | Conjectural -> "Parameter" | Context -> "Context" let definition_detail = function | Decls.Definition -> "Definition" | Coercion -> "Coercion" | SubClass -> "SubClass" | CanonicalStructure -> "CanonicalStructure" | Example -> "Example" | Fixpoint -> "Fixpoint" | CoFixpoint -> "CoFixpoint" | Scheme -> "Scheme" | StructureComponent -> "StructureComponent" | IdentityCoercion -> "IdentityCoercion" | Instance -> "Instance" | Method -> "Method" | Let -> "Let" let theorem_detail = function | Decls.Theorem -> "Theorem" | Lemma -> "Lemma" | Fact -> "Fact" | Remark -> "Remark" | Property -> "Property" | Proposition -> "Proposition" | Corollary -> "Corollary" let mk_name = CAst.map (fun id -> Names.Name id) let constructor_info ~lines ((_, (id, _typ)) : constructor_expr) = let range = Option.get id.loc in let range = Utils.to_range ~lines range in let name = mk_name id in let detail = "Constructor" in let kind = Kinds.enumMember in Info.make ~range ~name ~detail ~kind () let local_decl_expr_info ~lines ~kind ~detail (l : local_decl_expr) = let name = match l with | AssumExpr (ln, _, _) -> ln | DefExpr (ln, _, _, _) -> ln in let range = Option.get name.loc in let range = Utils.to_range ~lines range in Info.make ~range ~name ~kind ~detail () let projection_info ~lines ((ld, _) : local_decl_expr * record_field_attr) = let kind = Kinds.field in let detail = "Field" in local_decl_expr_info ~lines ~detail ~kind ld let inductive_info ~lines ~range ikind (expr, _) = let (_, (id, _)), _, _, cons = expr in let name = mk_name id in match cons with | Constructors ci -> let children = List.map (constructor_info ~lines) ci in let kind, detail = inductive_detail ikind in Info.make ~range ~name ~kind ~detail ~children () | RecordDecl (_, pi, _) -> let children = List.map (projection_info ~lines) pi in let kind, detail = inductive_detail ikind in Info.make ~range ~name ~kind ~detail ~children () let inductives_info ~lines ~range ikind idecls = match idecls with | [] -> None | inds -> Some (List.map (inductive_info ~lines ~range ikind) inds) let ident_decl_info ~lines ~kind ~detail (lident, _) = let range = Option.get lident.loc in let range = Utils.to_range ~lines range in let name = mk_name lident in Info.make ~range ~name ~detail ~kind () let assumption_info ~lines kind (_, (ids, _)) = let detail = assumption_detail kind in let kind = Kinds.variable in List.map (ident_decl_info ~lines ~kind ~detail) ids let fixpoint_info ~range { fname; _ } = let name = mk_name fname in let detail = "Fixpoint" in Info.make ~range ~name ~detail ~kind:Kinds.function_ () let make_info ~st:_ ~lines CAst.{ loc; v } : _ Info.t list option = let open Vernacexpr in match loc with | None -> None | Some range -> ( let range = Utils.to_range ~lines range in (* TODO: sections *) match v.expr with | VernacDefinition ((_, kind), (name, _), _) -> let detail = definition_detail kind in let kind = Kinds.function_ in Some [ Info.make ~range ~name ~detail ~kind () ] | VernacStartTheoremProof (kind, ndecls) -> ( let detail = theorem_detail kind in let kind = Kinds.function_ in match ndecls with | ((id, _), _) :: _ -> let name = mk_name id in Some [ Info.make ~range ~name ~detail ~kind () ] | [] -> None) | VernacInductive (ikind, idecls) -> inductives_info ~lines ~range ikind idecls | VernacAssumption ((_, kind), _, ids) -> Some (List.concat_map (assumption_info ~lines kind) ids) | VernacFixpoint (_, f_expr) -> Some (List.map (fixpoint_info ~range) f_expr) | VernacInstance ((name, _), _, _, _, _) -> let kind = Kinds.method_ in let detail = "Instance" in Some [ Info.make ~range ~name ~kind ~detail () ] | _ -> None)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>