mirror of
https://github.com/c-cube/linol.git
synced 2025-12-05 19:00:34 -05:00
Compare commits
3 commits
fb49472f34
...
c6e84391e7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6e84391e7 | ||
|
|
705cc47ddf | ||
|
|
40843b81db |
2 changed files with 9 additions and 11 deletions
|
|
@ -37,7 +37,7 @@ let diagnostics (_state : state_after_processing) : Lsp.Types.Diagnostic.t list
|
|||
so that users only need to override methods that they want the server to
|
||||
actually meaningfully interpret and respond to.
|
||||
*)
|
||||
class lsp_server =
|
||||
class lsp_server ~(sw: Eio.Switch.t) =
|
||||
object (self)
|
||||
inherit Linol_eio.Jsonrpc2.server
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class lsp_server =
|
|||
val buffers : (Lsp.Types.DocumentUri.t, state_after_processing) Hashtbl.t =
|
||||
Hashtbl.create 32
|
||||
|
||||
method spawn_query_handler f = Linol_eio.spawn f
|
||||
method spawn_query_handler f = Linol_eio.spawn ~sw f
|
||||
|
||||
(* We define here a helper method that will:
|
||||
- process a document
|
||||
|
|
@ -82,7 +82,8 @@ class lsp_server =
|
|||
and runs it as a task. *)
|
||||
let run () =
|
||||
Eio_main.run @@ fun env ->
|
||||
let s = new lsp_server in
|
||||
Eio.Switch.run @@ fun sw ->
|
||||
let s = new lsp_server ~sw in
|
||||
let server = Linol_eio.Jsonrpc2.create_stdio ~env s in
|
||||
let task () =
|
||||
let shutdown () = s#get_status = `ReceivedExit in
|
||||
|
|
|
|||
|
|
@ -52,17 +52,14 @@ module IO_eio :
|
|||
end
|
||||
|
||||
(** Spawn function. *)
|
||||
let spawn f =
|
||||
let promise, resolver = Eio.Promise.create () in
|
||||
(try
|
||||
f ();
|
||||
Eio.Promise.resolve_ok resolver ()
|
||||
let spawn ~sw f =
|
||||
Eio.Fiber.fork ~sw (fun () ->
|
||||
try
|
||||
f ()
|
||||
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
|
||||
raise exn)
|
||||
|
||||
include Lsp.Types
|
||||
include IO_eio
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue