format code

This commit is contained in:
Simon Cruanes 2025-04-03 08:16:22 -04:00
parent fa8ec8ee77
commit 50cc7a9527
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
6 changed files with 36 additions and 24 deletions

View file

@ -13,6 +13,9 @@ clean:
doc: doc:
@dune build @doc @dune build @doc
fmt:
@dune build @fmt --auto-promote
VERSION=$(shell awk '/^version:/ {print $$2}' linol.opam) VERSION=$(shell awk '/^version:/ {print $$2}' linol.opam)
update_next_tag: update_next_tag:

View file

@ -10,11 +10,9 @@ let ( let* ) x f = f x
let ( and+ ) a b = a, b let ( and+ ) a b = a, b
let return x = x let return x = x
let failwith = failwith let failwith = failwith
let fail = Printexc.raise_with_backtrace let fail = Printexc.raise_with_backtrace
let stdin () = stdin
let stdin = fun () -> stdin let stdout () = stdout
let stdout = fun () -> stdout
let default_spawn f = let default_spawn f =
let run () = let run () =

View file

@ -15,11 +15,15 @@ module IO_eio :
let failwith = failwith let failwith = failwith
let fail = raise let fail = raise
let catch f handler = try f () with exn -> let catch f handler =
try f ()
with exn ->
let bt = Printexc.get_raw_backtrace () in let bt = Printexc.get_raw_backtrace () in
handler exn bt 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 let stdout = Eio.Stdenv.stdout
type env = Eio_unix.Stdenv.base type env = Eio_unix.Stdenv.base
@ -27,29 +31,28 @@ module IO_eio :
type out_channel = Eio_unix.sink_ty Eio.Std.r 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_string out_ch str = Eio.Flow.copy_string str out_ch
let write out_ch bytes off len = let write out_ch bytes off len =
Eio.Buf_write.with_flow out_ch @@ fun w -> Eio.Buf_write.with_flow out_ch @@ fun w ->
Eio.Buf_write.bytes w ~off ~len bytes Eio.Buf_write.bytes w ~off ~len bytes
let read in_ch bytes off len = let read in_ch bytes off len =
let str = Eio.Buf_read.take len in_ch in let str = Eio.Buf_read.take len in_ch in
Bytes.blit_string str off bytes 0 len 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 end
(** Spawn function. *) (** Spawn function. *)
let spawn f = let spawn f =
let promise, resolver = Eio.Promise.create () in let promise, resolver = Eio.Promise.create () in
begin (try
try
f (); f ();
Eio.Promise.resolve_ok resolver () Eio.Promise.resolve_ok resolver ()
with with exn ->
exn -> Printf.eprintf "uncaught exception in `spawn`:\n%s\n%!"
(Printf.eprintf "uncaught exception in `spawn`:\n%s\n%!" (Printexc.to_string exn);
(Printexc.to_string exn)); Eio.Promise.resolve_error resolver exn);
Eio.Promise.resolve_error resolver exn
end;
Eio.Promise.await_exn promise Eio.Promise.await_exn promise

View file

@ -22,7 +22,11 @@ module type S = sig
t t
val create_stdio : 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 val send_server_notification : t -> Lsp.Server_notification.t -> unit IO.t

View file

@ -24,7 +24,11 @@ module type S = sig
(** Create a connection from the pair of channels *) (** Create a connection from the pair of channels *)
val create_stdio : 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 *) (** Create a connection using stdin/stdout *)
val send_server_notification : t -> Lsp.Server_notification.t -> unit IO.t val send_server_notification : t -> Lsp.Server_notification.t -> unit IO.t

View file

@ -18,8 +18,8 @@ module IO_lwt :
let return = Lwt.return let return = Lwt.return
let failwith = Lwt.fail_with let failwith = Lwt.fail_with
let stdin = fun () -> Lwt_io.stdin let stdin () = Lwt_io.stdin
let stdout = fun () -> Lwt_io.stdout let stdout () = Lwt_io.stdout
type env = unit type env = unit
type in_channel = Lwt_io.input Lwt_io.channel type in_channel = Lwt_io.input Lwt_io.channel