diff --git a/Makefile b/Makefile index 8764344b..bc746532 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ clean: doc: @dune build @doc +fmt: + @dune build @fmt --auto-promote + VERSION=$(shell awk '/^version:/ {print $$2}' linol.opam) update_next_tag: diff --git a/src/blocking_IO.ml b/src/blocking_IO.ml index af17c500..5791d2bf 100644 --- a/src/blocking_IO.ml +++ b/src/blocking_IO.ml @@ -10,11 +10,9 @@ let ( let* ) x f = f x let ( and+ ) a b = a, b let return x = x let failwith = failwith - let fail = Printexc.raise_with_backtrace - -let stdin = fun () -> stdin -let stdout = fun () -> stdout +let stdin () = stdin +let stdout () = stdout let default_spawn f = let run () = diff --git a/src/eio/linol_eio.ml b/src/eio/linol_eio.ml index a3cb606c..42b35d07 100644 --- a/src/eio/linol_eio.ml +++ b/src/eio/linol_eio.ml @@ -15,11 +15,15 @@ module IO_eio : let failwith = failwith let fail = raise - let catch f handler = try f () with exn -> - let bt = Printexc.get_raw_backtrace () in - handler exn bt + let catch f handler = + try f () + with exn -> + let bt = Printexc.get_raw_backtrace () in + handler exn bt + + let stdin env = + Eio.Buf_read.of_flow ~max_size:1_000_000 (Eio.Stdenv.stdin env) - let stdin env = Eio.Buf_read.of_flow ~max_size:1_000_000 (Eio.Stdenv.stdin env) let stdout = Eio.Stdenv.stdout type env = Eio_unix.Stdenv.base @@ -27,29 +31,28 @@ module IO_eio : type out_channel = Eio_unix.sink_ty Eio.Std.r let write_string out_ch str = Eio.Flow.copy_string str out_ch + let write out_ch bytes off len = Eio.Buf_write.with_flow out_ch @@ fun w -> Eio.Buf_write.bytes w ~off ~len bytes + let read in_ch bytes off len = let str = Eio.Buf_read.take len in_ch in Bytes.blit_string str off bytes 0 len - let read_line in_ch = - Eio.Buf_read.line in_ch + + let read_line in_ch = Eio.Buf_read.line in_ch end (** Spawn function. *) let spawn f = let promise, resolver = Eio.Promise.create () in - begin - try - f (); - Eio.Promise.resolve_ok resolver () - with - exn -> - (Printf.eprintf "uncaught exception in `spawn`:\n%s\n%!" - (Printexc.to_string exn)); - Eio.Promise.resolve_error resolver exn - end; + (try + f (); + Eio.Promise.resolve_ok resolver () + with exn -> + Printf.eprintf "uncaught exception in `spawn`:\n%s\n%!" + (Printexc.to_string exn); + Eio.Promise.resolve_error resolver exn); Eio.Promise.await_exn promise diff --git a/src/jsonrpc2.ml b/src/jsonrpc2.ml index 48c292c0..9aecefd3 100644 --- a/src/jsonrpc2.ml +++ b/src/jsonrpc2.ml @@ -22,7 +22,11 @@ module type S = sig t val create_stdio : - ?on_received:(json -> unit) -> ?on_sent:(json -> unit) -> env:IO.env -> server -> t + ?on_received:(json -> unit) -> + ?on_sent:(json -> unit) -> + env:IO.env -> + server -> + t val send_server_notification : t -> Lsp.Server_notification.t -> unit IO.t diff --git a/src/jsonrpc2.mli b/src/jsonrpc2.mli index 2ed46b04..96c2acf6 100644 --- a/src/jsonrpc2.mli +++ b/src/jsonrpc2.mli @@ -24,7 +24,11 @@ module type S = sig (** Create a connection from the pair of channels *) val create_stdio : - ?on_received:(json -> unit) -> ?on_sent:(json -> unit) -> env:IO.env -> server -> t + ?on_received:(json -> unit) -> + ?on_sent:(json -> unit) -> + env:IO.env -> + server -> + t (** Create a connection using stdin/stdout *) val send_server_notification : t -> Lsp.Server_notification.t -> unit IO.t diff --git a/src/lwt/linol_lwt.ml b/src/lwt/linol_lwt.ml index 432527bf..5b8b2889 100644 --- a/src/lwt/linol_lwt.ml +++ b/src/lwt/linol_lwt.ml @@ -18,8 +18,8 @@ module IO_lwt : let return = Lwt.return let failwith = Lwt.fail_with - let stdin = fun () -> Lwt_io.stdin - let stdout = fun () -> Lwt_io.stdout + let stdin () = Lwt_io.stdin + let stdout () = Lwt_io.stdout type env = unit type in_channel = Lwt_io.input Lwt_io.channel