mirror of
https://github.com/c-cube/linol.git
synced 2025-12-06 11:15:46 -05:00
api break: put spawn in the server itself, not IO
This commit is contained in:
parent
8c2e204cdf
commit
c6969ab87c
7 changed files with 21 additions and 19 deletions
|
|
@ -43,6 +43,8 @@ class lsp_server =
|
||||||
val buffers : (Lsp.Types.DocumentUri.t, state_after_processing) Hashtbl.t =
|
val buffers : (Lsp.Types.DocumentUri.t, state_after_processing) Hashtbl.t =
|
||||||
Hashtbl.create 32
|
Hashtbl.create 32
|
||||||
|
|
||||||
|
method spawn_query_handler f = Linol_lwt.spawn f
|
||||||
|
|
||||||
(* We define here a helper method that will:
|
(* We define here a helper method that will:
|
||||||
- process a document
|
- process a document
|
||||||
- store the state resulting from the processing
|
- store the state resulting from the processing
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ let fail = raise
|
||||||
let stdin = stdin
|
let stdin = stdin
|
||||||
let stdout = stdout
|
let stdout = stdout
|
||||||
|
|
||||||
let default_spawn_ f =
|
let default_spawn f =
|
||||||
let run () =
|
let run () =
|
||||||
try f ()
|
try f ()
|
||||||
with e ->
|
with e ->
|
||||||
|
|
@ -21,9 +21,6 @@ let default_spawn_ f =
|
||||||
in
|
in
|
||||||
ignore (Thread.create run ())
|
ignore (Thread.create run ())
|
||||||
|
|
||||||
let spawn_ref_ = ref default_spawn_
|
|
||||||
let set_spawn_function f = spawn_ref_ := f
|
|
||||||
let spawn f = !spawn_ref_ f
|
|
||||||
let catch f g = try f () with e -> g e
|
let catch f g = try f () with e -> g e
|
||||||
|
|
||||||
let rec read ic buf i len =
|
let rec read ic buf i len =
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@ include
|
||||||
and type in_channel = in_channel
|
and type in_channel = in_channel
|
||||||
and type out_channel = out_channel
|
and type out_channel = out_channel
|
||||||
|
|
||||||
val set_spawn_function : ((unit -> unit) -> unit) -> unit
|
val default_spawn : (unit -> unit) -> unit
|
||||||
(** Change the way the LSP server spawns new threads to handle
|
(** Start a new thread.
|
||||||
client queries. For example, one might use a thread pool. *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,7 @@ module Make (IO : IO) : S with module IO = IO = struct
|
||||||
let* r = read_msg self in
|
let* r = read_msg self in
|
||||||
match r with
|
match r with
|
||||||
| Ok r ->
|
| Ok r ->
|
||||||
IO.spawn (fun () -> process_msg r);
|
self.s#spawn_query_handler (fun () -> process_msg r);
|
||||||
loop ()
|
loop ()
|
||||||
| Error e -> IO.fail e
|
| Error e -> IO.fail e
|
||||||
in
|
in
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,16 @@ module IO_lwt :
|
||||||
let read_line = Lwt_io.read_line
|
let read_line = Lwt_io.read_line
|
||||||
let catch = Lwt.catch
|
let catch = Lwt.catch
|
||||||
let fail = Lwt.fail
|
let fail = Lwt.fail
|
||||||
|
end
|
||||||
|
|
||||||
|
(** Spawn function.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
let spawn f =
|
let spawn f =
|
||||||
Lwt.async (fun () ->
|
Lwt.async (fun () ->
|
||||||
Lwt.catch f (fun exn ->
|
Lwt.catch f (fun 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);
|
||||||
Lwt.return ()))
|
Lwt.return ()))
|
||||||
end
|
|
||||||
|
|
||||||
include Lsp.Types
|
include Lsp.Types
|
||||||
include IO_lwt
|
include IO_lwt
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,11 @@ module Make (IO : IO) = struct
|
||||||
|
|
||||||
method must_quit = false
|
method must_quit = false
|
||||||
(** Set to true if the client requested to exit *)
|
(** Set to true if the client requested to exit *)
|
||||||
|
|
||||||
|
method virtual spawn_query_handler : (unit -> unit IO.t) -> unit
|
||||||
|
(** How to start a new future/task/thread concurrently. This is used
|
||||||
|
to process incoming user queries.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
end
|
end
|
||||||
|
|
||||||
(** A wrapper to more easily reply to notifications *)
|
(** A wrapper to more easily reply to notifications *)
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,6 @@ module type IO = sig
|
||||||
val read_line : in_channel -> string t
|
val read_line : in_channel -> string t
|
||||||
val write : out_channel -> bytes -> int -> int -> unit t
|
val write : out_channel -> bytes -> int -> int -> unit t
|
||||||
val write_string : out_channel -> string -> unit t
|
val write_string : out_channel -> string -> unit t
|
||||||
|
|
||||||
val spawn : (unit -> unit t) -> unit
|
|
||||||
(** Spawn a new task that executes concurrently. *)
|
|
||||||
|
|
||||||
val fail : exn -> unit t
|
val fail : exn -> unit t
|
||||||
val catch : (unit -> 'a t) -> (exn -> 'a t) -> 'a t
|
val catch : (unit -> 'a t) -> (exn -> 'a t) -> 'a t
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue