package coq-lsp
Language Server Protocol native server for Coq
Install
Dune Dependency
Authors
Maintainers
Sources
coq-lsp-0.1.8.8.17.tbz
sha256=d825cca28cff503fb23906245ebeb0a41fc6497b21e4538df7a3450e705129e6
sha512=f2351f6cc81ebaef77e46b1f72bcbb4397f5433eabe3b64ca9ee72423bc251d016ae51ac4b7b35d66bdceee6295f2feb799ea82290fd467933ff25d78844c972
doc/src/coq-lsp.lsp/io.ml.html
Source file io.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
(************************************************************************) (* * 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 *) (************************************************************************) module F = Format module J = Yojson.Safe let fn = ref (fun _ -> ()) let set_log_fn f = fn := f let read_raw_request ic = let cl = input_line ic in let sin = Scanf.Scanning.from_string cl in let raw_obj = Scanf.bscanf sin "Content-Length: %d\r" (fun size -> let buf = Bytes.create size in (* Consume the second \r\n or header *) let ohdr = input_line ic in (* If the second line is a return, then no more headers *) let () = if ohdr.[0] = '\r' then () else (* Fixme (or use ocaml-lsp) Skip the Content-type header *) ignore (input_line ic) in really_input ic buf 0 size; Bytes.to_string buf) in J.from_string raw_obj exception ReadError of string let read_raw_request ic = try Some (read_raw_request ic) with (* if the end of input is encountered while some more characters are needed to read the current conversion specification, or the lsp server closes *) | End_of_file -> None (* if the input does not match the format. *) | Scanf.Scan_failure msg (* if a conversion to a number is not possible. *) | Failure msg (* if the format string is invalid. *) | Invalid_argument msg -> raise (ReadError msg) let mut = Mutex.create () let log = ref (fun _ _ -> ()) let send_json fmt obj = Mutex.lock mut; if Fleche.Debug.send then !log "send" obj; let msg = if !Fleche.Config.v.pp_json then F.asprintf "%a" J.(pretty_print ~std:true) obj else J.to_string obj ^ "\n" in let size = String.length msg in F.fprintf fmt "Content-Length: %d\r\n\r\n%s%!" size msg; Mutex.unlock mut (** Logging *) module TraceValue = struct type t = | Off | Messages | Verbose let of_string = function | "messages" -> Ok Messages | "verbose" -> Ok Verbose | "off" -> Ok Off | v -> Error ("TraceValue.parse: " ^ v) let to_string = function | Off -> "off" | Messages -> "messages" | Verbose -> "verbose" end let trace_value = ref TraceValue.Off let set_trace_value value = trace_value := value let logMessage ~lvl ~message = let method_ = "window/logMessage" in let params = `Assoc [ ("type", `Int lvl); ("message", `String message) ] in let msg = Base.mk_notification ~method_ ~params in !fn msg let logTrace ~message ~extra = let method_ = "$/logTrace" in let params = match (!trace_value, extra) with | Verbose, Some extra -> `Assoc [ ("message", `String message); ("verbose", `String extra) ] | _, _ -> `Assoc [ ("message", `String message) ] in Base.mk_notification ~method_ ~params |> !fn let trace hdr ?extra msg = let message = Format.asprintf "[%s]: @[%s@]" hdr msg in logTrace ~message ~extra let trace_object hdr obj = let message = Format.asprintf "[%s]: @[%a@]" hdr Yojson.Safe.(pretty_print ~std:false) obj in (* Fixme, use the extra parameter *) trace hdr message let () = log := trace_object (** Misc helpers *) let rec read_request ic = match read_raw_request ic with | None -> None (* EOF *) | Some com -> ( if Fleche.Debug.read then trace_object "read" com; match Base.Message.from_yojson com with | Ok msg -> Some msg | Error msg -> trace "read_request" ("error: " ^ msg); read_request ic)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>