Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
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
(************************************************************************) (* * 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 *) (************************************************************************) module F = Format module J = Yojson.Safe let mut = Mutex.create () let debug_fmt = ref F.err_formatter let log_error hdr msg = Mutex.lock mut; F.fprintf !debug_fmt "[%s]: @[%s@]@\n%!" hdr msg; Mutex.unlock mut let log_object hdr obj = F.fprintf !debug_fmt "[%s]: @[%a@]@\n%!" hdr J.(pretty_print ~std:false) obj let flush_log () = F.pp_print_flush !debug_fmt () exception ReadError of string let read_request_raw 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 let read_request ic = try read_request_raw 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 -> raise (ReadError "EOF") (* 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 send_json fmt obj = Mutex.lock mut; if Fleche.Debug.send then log_object "send" obj; let msg = F.asprintf "%a" J.(pretty_print ~std:true) obj in let size = String.length msg in F.fprintf fmt "Content-Length: %d\r\n\r\n%s%!" size msg; Mutex.unlock mut